get($model, 'arcadia_id', $dbValue, []); // THEN expect($result)->toBeInstanceOf(ArcadiaId::class) ->and($result->value)->toBe('123'); }); it('transforms numeric string from database to ArcadiaId instance on get', function () use ($cast, $model): void { // GIVEN $dbValue = '456'; // WHEN $result = $cast->get($model, 'arcadia_id', $dbValue, []); // THEN expect($result)->toBeInstanceOf(ArcadiaId::class) ->and($result->value)->toBe('456'); }); it('throws InvalidArgumentException on get when value is null', function () use ($cast, $model): void { // GIVEN & WHEN expect(fn () => $cast->get($model, 'arcadia_id', null, [])) // THEN ->toThrow(\InvalidArgumentException::class, 'ArcadiaId value cannot be null'); }); it('throws InvalidArgumentException on get when value is invalid type', function () use ($cast, $model): void { // GIVEN & WHEN expect(fn () => $cast->get($model, 'arcadia_id', 'abc', [])) // THEN ->toThrow(\InvalidArgumentException::class, 'Value must be an integer or numeric string'); }); it('transforms ArcadiaId instance to integer on set', function () use ($cast, $model): void { // GIVEN $arcadiaId = new ArcadiaId('789'); // WHEN $result = $cast->set($model, 'arcadia_id', $arcadiaId, []); // THEN expect($result)->toBe(789); }); it('transforms raw integer to integer on set', function () use ($cast, $model): void { // GIVEN $value = 42; // WHEN $result = $cast->set($model, 'arcadia_id', $value, []); // THEN expect($result)->toBe(42); }); it('transforms numeric string to integer on set', function () use ($cast, $model): void { // GIVEN $value = '99'; // WHEN $result = $cast->set($model, 'arcadia_id', $value, []); // THEN expect($result)->toBe(99); }); it('throws InvalidArgumentException on set when value is null', function () use ($cast, $model): void { // GIVEN & WHEN expect(fn () => $cast->set($model, 'arcadia_id', null, [])) // THEN ->toThrow(\InvalidArgumentException::class, 'ArcadiaId value cannot be null'); }); it('throws InvalidArgumentException on set when value is invalid type', function () use ($cast, $model): void { // GIVEN $invalid = ['array-not-supported']; // WHEN expect(fn () => $cast->set($model, 'arcadia_id', $invalid, [])) // THEN ->toThrow(\InvalidArgumentException::class, 'Value must be an integer, numeric string, or instance of ArcadiaId'); }); });