adrema/tests/Lib/MergesAttributes.php

27 lines
520 B
PHP
Raw Permalink Normal View History

2022-08-12 22:07:59 +02:00
<?php
namespace Tests\Lib;
trait MergesAttributes
{
2023-09-19 20:14:52 +02:00
/**
* @return array<string, mixed>
*/
abstract public function defaults(): array;
2022-08-12 22:07:59 +02:00
2023-09-19 20:14:52 +02:00
/**
* @param array<string, mixed> $overwrites
* @return array<string, mixed>
*/
2022-08-12 22:07:59 +02:00
public function attributes(?array $overwrites = []): array
{
$defaults = collect($this->defaults());
foreach ($overwrites as $key => $value) {
$defaults->put($key, $value);
}
return $defaults->toArray();
}
}