workbench, tests

This commit is contained in:
icefox 2026-02-23 21:09:02 -03:00
parent d83a324eb0
commit 367858c97c
No known key found for this signature in database
27 changed files with 568 additions and 410 deletions

View file

@ -17,8 +17,8 @@ describe('caster priority', function () {
});
it('uses CastWith attribute over global config caster', function () {
$globalCaster = function (mixed $value): SimpleValue {
return new SimpleValue($value['value'] * 3);
$globalCaster = function (mixed $data): SimpleValue {
return new SimpleValue($data * 3);
};
config(['dto.cast.' . SimpleValue::class => $globalCaster]);
@ -30,16 +30,16 @@ describe('caster priority', function () {
});
it('falls back to global config caster when no CastWith attribute', function () {
$globalCaster = function (mixed $value): SimpleValue {
return new SimpleValue($value['value'] * 3);
$globalCaster = function (mixed $data): SimpleValue {
return new SimpleValue($data['value'] * 3);
};
config(['dto.cast.' . SimpleValue::class => $globalCaster]);
$object = WithGlobalCaster::fromArray([
'value' => ['value' => 5],
'simple' => ['value' => 5],
]);
expect($object->value->value)->toBe(15); // 5 * 3
expect($object->simple->value)->toBe(15); // 5 * 3
});
it('falls back to default construction when no caster exists', function () {

View file

@ -6,9 +6,9 @@ namespace Tests\Casters;
class SimpleValueCaster
{
public function cast(mixed $value): SimpleValue
public function cast(mixed $data): SimpleValue
{
return new SimpleValue($value['value'] * 2);
return new SimpleValue($data['value'] * 2);
}
public static function rules(): array

View file

@ -11,6 +11,6 @@ readonly class WithGlobalCaster
use DataObject;
public function __construct(
public SimpleValue $value,
public SimpleValue $simple,
) {}
}