Fix annotations, remove groups
This commit is contained in:
parent
d3e12785bb
commit
aa7b062b29
3 changed files with 13 additions and 42 deletions
|
|
@ -102,8 +102,8 @@ trait DataObject
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array<int,mixed> $data
|
* @param array<string,mixed> $data
|
||||||
* @param array<int,string|Rule> $rules
|
* @param array<string,array<int, string|Rule>> $rules
|
||||||
*/
|
*/
|
||||||
public static function withValidator(array $data, array $rules): Validator
|
public static function withValidator(array $data, array $rules): Validator
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -15,19 +15,6 @@ class DataObjectServiceProvider extends ServiceProvider
|
||||||
public function register(): void
|
public function register(): void
|
||||||
{
|
{
|
||||||
$this->mergeConfigFrom(__DIR__ . '/config/dto.php', 'dto');
|
$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
|
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' => [],
|
|
||||||
]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -38,7 +38,7 @@ describe('primitive data test', function () {
|
||||||
expect($object->float)->toEqualWithDelta(3.14, 0.0001);
|
expect($object->float)->toEqualWithDelta(3.14, 0.0001);
|
||||||
expect($object->bool)->toBeTrue();
|
expect($object->bool)->toBeTrue();
|
||||||
});
|
});
|
||||||
})->group('primitives');
|
});
|
||||||
|
|
||||||
describe('optional data', function () {
|
describe('optional data', function () {
|
||||||
it('creates optional rules', function () {
|
it('creates optional rules', function () {
|
||||||
|
|
@ -59,7 +59,7 @@ describe('optional data', function () {
|
||||||
expect($object->float)->toEqualWithDelta(0.777, 0.0001);
|
expect($object->float)->toEqualWithDelta(0.777, 0.0001);
|
||||||
expect($object->bool)->toBeFalse();
|
expect($object->bool)->toBeFalse();
|
||||||
});
|
});
|
||||||
})->group('optional');
|
});
|
||||||
|
|
||||||
describe('nullable data', function () {
|
describe('nullable data', function () {
|
||||||
it('creates nullable rules', function () {
|
it('creates nullable rules', function () {
|
||||||
|
|
@ -88,7 +88,7 @@ describe('nullable data', function () {
|
||||||
expect($object->string)->toBe('dfg');
|
expect($object->string)->toBe('dfg');
|
||||||
expect($object->int)->toBeNull();
|
expect($object->int)->toBeNull();
|
||||||
});
|
});
|
||||||
})->group('nullable');
|
});
|
||||||
|
|
||||||
describe('reference other DataObject', function () {
|
describe('reference other DataObject', function () {
|
||||||
|
|
||||||
|
|
@ -105,7 +105,7 @@ describe('reference other DataObject', function () {
|
||||||
'extra.bool' => ['required', 'boolean'],
|
'extra.bool' => ['required', 'boolean'],
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
})->group('reference');
|
});
|
||||||
|
|
||||||
describe('primitive array', function () {
|
describe('primitive array', function () {
|
||||||
it('creates array rules', function () {
|
it('creates array rules', function () {
|
||||||
|
|
@ -115,7 +115,7 @@ describe('primitive array', function () {
|
||||||
'values.*' => ['required', 'numeric'],
|
'values.*' => ['required', 'numeric'],
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
})->group('primitive-array');
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('object array', function () {
|
describe('object array', function () {
|
||||||
|
|
@ -133,7 +133,7 @@ describe('object array', function () {
|
||||||
'values.*.bool' => ['sometimes', 'boolean'],
|
'values.*.bool' => ['sometimes', 'boolean'],
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
})->group('object-array');
|
});
|
||||||
|
|
||||||
describe('can map input names', function () {
|
describe('can map input names', function () {
|
||||||
|
|
||||||
|
|
@ -164,7 +164,7 @@ describe('can map input names', function () {
|
||||||
expect($object->text)->toBe('xyz');
|
expect($object->text)->toBe('xyz');
|
||||||
expect($object->standard)->toBe(1);
|
expect($object->standard)->toBe(1);
|
||||||
});
|
});
|
||||||
})->group('input-map');
|
});
|
||||||
|
|
||||||
describe('with mapper object', function () {
|
describe('with mapper object', function () {
|
||||||
it('uses mapper', function () {
|
it('uses mapper', function () {
|
||||||
|
|
@ -187,7 +187,7 @@ describe('with mapper object', function () {
|
||||||
'standard' => 1,
|
'standard' => 1,
|
||||||
]);
|
]);
|
||||||
})->throws(ValidationException::class);
|
})->throws(ValidationException::class);
|
||||||
})->group('mapper-object');
|
});
|
||||||
|
|
||||||
test('failed validation throws ValidationException', function () {
|
test('failed validation throws ValidationException', function () {
|
||||||
$object = PrimitiveData::fromArray([
|
$object = PrimitiveData::fromArray([
|
||||||
|
|
@ -195,8 +195,7 @@ test('failed validation throws ValidationException', function () {
|
||||||
'float' => 3.14,
|
'float' => 3.14,
|
||||||
'bool' => true,
|
'bool' => true,
|
||||||
]);
|
]);
|
||||||
})->throws(ValidationException::class)
|
})->throws(ValidationException::class);
|
||||||
->group('error');
|
|
||||||
|
|
||||||
|
|
||||||
test('tries to resolve without mapper', function () {
|
test('tries to resolve without mapper', function () {
|
||||||
|
|
@ -221,4 +220,4 @@ test('creates collection', function () {
|
||||||
expect($object->values->count())->toBe(2);
|
expect($object->values->count())->toBe(2);
|
||||||
expect($object->values[0]->string)->toBe('x');
|
expect($object->values[0]->string)->toBe('x');
|
||||||
expect($object->values[1]->int)->toBeNull();
|
expect($object->values[1]->int)->toBeNull();
|
||||||
})->group('collection');
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue