Fix annotations, remove groups

This commit is contained in:
icefox 2026-02-18 19:24:17 -03:00
parent d3e12785bb
commit aa7b062b29
No known key found for this signature in database
3 changed files with 13 additions and 42 deletions

View file

@ -102,8 +102,8 @@ trait DataObject
}
/**
* @param array<int,mixed> $data
* @param array<int,string|Rule> $rules
* @param array<string,mixed> $data
* @param array<string,array<int, string|Rule>> $rules
*/
public static function withValidator(array $data, array $rules): Validator
{

View file

@ -15,19 +15,6 @@ class DataObjectServiceProvider extends ServiceProvider
public function register(): void
{
$this->mergeConfigFrom(__DIR__ . '/config/dto.php', 'dto');
$registrar = new DataObjectRegistrar($this->app);
// Register from configured namespaces or manual class list
$config = $this->getConfig();
if (!empty($config['classes'])) {
// Manual registration (zero overhead)
$registrar->registerMany($config['classes']);
} elseif (!empty($config['namespaces'])) {
// Automatic namespace scanning
$registrar->registerFromNamespaces($config['namespaces']);
}
}
/**
@ -35,21 +22,6 @@ class DataObjectServiceProvider extends ServiceProvider
*/
public function boot(): void
{
// Commands will be registered here
}
/**
* Get DataObject configuration.
*
* @return array{namespaces: string[], classes: class-string[]}
*/
protected function getConfig(): array
{
return config('dataobject', [
'namespaces' => [
'App\DataObjects',
],
'classes' => [],
]);
//
}
}

View file

@ -38,7 +38,7 @@ describe('primitive data test', function () {
expect($object->float)->toEqualWithDelta(3.14, 0.0001);
expect($object->bool)->toBeTrue();
});
})->group('primitives');
});
describe('optional data', function () {
it('creates optional rules', function () {
@ -59,7 +59,7 @@ describe('optional data', function () {
expect($object->float)->toEqualWithDelta(0.777, 0.0001);
expect($object->bool)->toBeFalse();
});
})->group('optional');
});
describe('nullable data', function () {
it('creates nullable rules', function () {
@ -88,7 +88,7 @@ describe('nullable data', function () {
expect($object->string)->toBe('dfg');
expect($object->int)->toBeNull();
});
})->group('nullable');
});
describe('reference other DataObject', function () {
@ -105,7 +105,7 @@ describe('reference other DataObject', function () {
'extra.bool' => ['required', 'boolean'],
]);
});
})->group('reference');
});
describe('primitive array', function () {
it('creates array rules', function () {
@ -115,7 +115,7 @@ describe('primitive array', function () {
'values.*' => ['required', 'numeric'],
]);
});
})->group('primitive-array');
});
describe('object array', function () {
@ -133,7 +133,7 @@ describe('object array', function () {
'values.*.bool' => ['sometimes', 'boolean'],
]);
});
})->group('object-array');
});
describe('can map input names', function () {
@ -164,7 +164,7 @@ describe('can map input names', function () {
expect($object->text)->toBe('xyz');
expect($object->standard)->toBe(1);
});
})->group('input-map');
});
describe('with mapper object', function () {
it('uses mapper', function () {
@ -187,7 +187,7 @@ describe('with mapper object', function () {
'standard' => 1,
]);
})->throws(ValidationException::class);
})->group('mapper-object');
});
test('failed validation throws ValidationException', function () {
$object = PrimitiveData::fromArray([
@ -195,8 +195,7 @@ test('failed validation throws ValidationException', function () {
'float' => 3.14,
'bool' => true,
]);
})->throws(ValidationException::class)
->group('error');
})->throws(ValidationException::class);
test('tries to resolve without mapper', function () {
@ -221,4 +220,4 @@ test('creates collection', function () {
expect($object->values->count())->toBe(2);
expect($object->values[0]->string)->toBe('x');
expect($object->values[1]->int)->toBeNull();
})->group('collection');
});