From 06fcfe6b737e3380cfad202f7320c468e567fe6d Mon Sep 17 00:00:00 2001 From: Ruben Van Assche Date: Tue, 16 Jan 2024 13:46:52 +0100 Subject: [PATCH] Partial tests --- composer.json | 5 +- src/Concerns/BaseData.php | 6 +- .../DataCollectableAnnotationReader.php | 4 +- src/Support/Creation/CreationContext.php | 10 +- .../Creation/CreationContextFactory.php | 17 +- src/Support/Partials/ResolvedPartial.php | 8 + .../Partials/ResolvedPartialsCollection.php | 22 + .../Transformation/TransformationContext.php | 14 + tests/Fakes/CollectionAnnotationsData.php | 33 +- .../VisibleDataFieldsResolverTest.php | 511 ++++++++++++++++-- .../DataCollectableAnnotationReaderTest.php | 17 +- tests/TransformationTest.php | 4 +- 12 files changed, 564 insertions(+), 87 deletions(-) diff --git a/composer.json b/composer.json index c5a865f6..d4130cdf 100644 --- a/composer.json +++ b/composer.json @@ -43,13 +43,12 @@ }, "autoload" : { "psr-4" : { - "Spatie\\LaravelData\\" : "src", - "Spatie\\LaravelData\\Database\\Factories\\" : "database/factories" + "Spatie\\LaravelData\\" : "src/" } }, "autoload-dev" : { "psr-4" : { - "Spatie\\LaravelData\\Tests\\" : "tests" + "Spatie\\LaravelData\\Tests\\" : "tests/" } }, "scripts" : { diff --git a/src/Concerns/BaseData.php b/src/Concerns/BaseData.php index bc0b85b9..93250213 100644 --- a/src/Concerns/BaseData.php +++ b/src/Concerns/BaseData.php @@ -95,10 +95,12 @@ public function getMorphClass(): string public function __sleep(): array { - return app(DataConfig::class)->getDataClass(static::class) + $dataClass = app(DataConfig::class)->getDataClass(static::class); + + return $dataClass ->properties ->map(fn (DataProperty $property) => $property->name) - ->push('_additional') + ->when($dataClass->appendable, fn(Collection $properties) => $properties->push('_additional')) ->toArray(); } } diff --git a/src/Support/Annotations/DataCollectableAnnotationReader.php b/src/Support/Annotations/DataCollectableAnnotationReader.php index bcc5312f..86e4a472 100644 --- a/src/Support/Annotations/DataCollectableAnnotationReader.php +++ b/src/Support/Annotations/DataCollectableAnnotationReader.php @@ -15,6 +15,9 @@ use Spatie\LaravelData\Contracts\BaseData; use Spatie\LaravelData\Contracts\BaseDataCollectable; +/** + * @note To myself, always use the fully qualified class names in pest tests when using anonymous classes + */ class DataCollectableAnnotationReader { /** @var array */ @@ -220,7 +223,6 @@ protected function resolveFcqn( return ltrim((string) $type, '\\'); } - protected function getContext(ReflectionProperty|ReflectionClass|ReflectionMethod $reflection): Context { $reflectionClass = $reflection instanceof ReflectionProperty || $reflection instanceof ReflectionMethod diff --git a/src/Support/Creation/CreationContext.php b/src/Support/Creation/CreationContext.php index 397e9c96..255fe41a 100644 --- a/src/Support/Creation/CreationContext.php +++ b/src/Support/Creation/CreationContext.php @@ -29,11 +29,11 @@ class CreationContext */ public function __construct( public string $dataClass, - public ValidationType $validationType, - public bool $mapPropertyNames, - public bool $withoutMagicalCreation, - public ?array $ignoredMagicalMethods, - public ?GlobalCastsCollection $casts, + public readonly ValidationType $validationType, + public readonly bool $mapPropertyNames, + public readonly bool $withoutMagicalCreation, + public readonly ?array $ignoredMagicalMethods, + public readonly ?GlobalCastsCollection $casts, ) { } diff --git a/src/Support/Creation/CreationContextFactory.php b/src/Support/Creation/CreationContextFactory.php index 12be1c65..411cb8e8 100644 --- a/src/Support/Creation/CreationContextFactory.php +++ b/src/Support/Creation/CreationContextFactory.php @@ -55,6 +55,19 @@ public static function createFromConfig( ); } + public static function createFromContext( + CreationContext $context + ) { + return new self( + dataClass: $context->dataClass, + validationType: $context->validationType, + mapPropertyNames: $context->mapPropertyNames, + withoutMagicalCreation: $context->withoutMagicalCreation, + ignoredMagicalMethods: $context->ignoredMagicalMethods, + casts: $context->casts, + ); + } + public function validationType(ValidationType $validationType): self { $this->validationType = $validationType; @@ -112,7 +125,7 @@ public function ignoreMagicalMethod(string ...$methods): self */ public function withCast( string $castable, - Cast|string $cast, + Cast | string $cast, ): self { $cast = is_string($cast) ? app($cast) : $cast; @@ -174,7 +187,7 @@ public function from(mixed ...$payloads): BaseData public function collect( mixed $items, ?string $into = null - ): array|DataCollection|PaginatedDataCollection|CursorPaginatedDataCollection|Enumerable|AbstractPaginator|PaginatorContract|AbstractCursorPaginator|CursorPaginatorContract|LazyCollection|Collection { + ): array | DataCollection | PaginatedDataCollection | CursorPaginatedDataCollection | Enumerable | AbstractPaginator | PaginatorContract | AbstractCursorPaginator | CursorPaginatorContract | LazyCollection | Collection { return DataContainer::get()->dataCollectableFromSomethingResolver()->execute( $this->dataClass, $this->get(), diff --git a/src/Support/Partials/ResolvedPartial.php b/src/Support/Partials/ResolvedPartial.php index bd0d0f32..f898c94d 100644 --- a/src/Support/Partials/ResolvedPartial.php +++ b/src/Support/Partials/ResolvedPartial.php @@ -108,6 +108,14 @@ public function toLaravel(): array return [implode('.', $segments)]; } + public function toArray(): array + { + return [ + 'segments' => $this->segments, + 'pointer' => $this->pointer, + ]; + } + public function next(): self { $this->pointer++; diff --git a/src/Support/Partials/ResolvedPartialsCollection.php b/src/Support/Partials/ResolvedPartialsCollection.php index 1e8807e5..b1c10ac7 100644 --- a/src/Support/Partials/ResolvedPartialsCollection.php +++ b/src/Support/Partials/ResolvedPartialsCollection.php @@ -10,6 +10,28 @@ */ class ResolvedPartialsCollection extends SplObjectStorage implements Stringable { + public static function create(ResolvedPartial ...$resolvedPartials): self + { + $collection = new self(); + + foreach ($resolvedPartials as $resolvedPartial) { + $collection->attach($resolvedPartial); + } + + return $collection; + } + + public function toArray(): array + { + $output = []; + + foreach ($this as $resolvedPartial) { + $output[] = $resolvedPartial->toArray(); + } + + return $output; + } + public function __toString(): string { $output = "- excludedPartials:".PHP_EOL; diff --git a/src/Support/Transformation/TransformationContext.php b/src/Support/Transformation/TransformationContext.php index f906f5b6..fa285015 100644 --- a/src/Support/Transformation/TransformationContext.php +++ b/src/Support/Transformation/TransformationContext.php @@ -176,6 +176,20 @@ public function mergePartialsFromDataContext( return $this; } + public function toArray(): array + { + return [ + 'transformValues' => $this->transformValues, + 'mapPropertyNames' => $this->mapPropertyNames, + 'wrapExecutionType' => $this->wrapExecutionType, + 'transformers' => $this->transformers !== null ? iterator_to_array($this->transformers) : null, + 'includedPartials' => $this->includedPartials?->toArray(), + 'excludedPartials' => $this->excludedPartials?->toArray(), + 'onlyPartials' => $this->onlyPartials?->toArray(), + 'exceptPartials' => $this->exceptPartials?->toArray(), + ]; + } + public function __clone(): void { if ($this->includedPartials !== null) { diff --git a/tests/Fakes/CollectionAnnotationsData.php b/tests/Fakes/CollectionAnnotationsData.php index 20180ad7..19330e49 100644 --- a/tests/Fakes/CollectionAnnotationsData.php +++ b/tests/Fakes/CollectionAnnotationsData.php @@ -71,22 +71,27 @@ class CollectionAnnotationsData public array $propertyT; /** - * @param \Spatie\LaravelData\Tests\Fakes\SimpleData[]|null $propertyA - * @param null|\Spatie\LaravelData\Tests\Fakes\SimpleData[] $propertyB - * @param ?\Spatie\LaravelData\Tests\Fakes\SimpleData[] $propertyC - * @param ?\Spatie\LaravelData\Tests\Fakes\SimpleData[] $propertyD - * @param \Spatie\LaravelData\DataCollection<\Spatie\LaravelData\Tests\Fakes\SimpleData> $propertyE - * @param ?\Spatie\LaravelData\DataCollection<\Spatie\LaravelData\Tests\Fakes\SimpleData> $propertyF - * @param SimpleData[] $propertyG + * @param \Spatie\LaravelData\Tests\Fakes\SimpleData[]|null $paramA + * @param null|\Spatie\LaravelData\Tests\Fakes\SimpleData[] $paramB + * @param ?\Spatie\LaravelData\Tests\Fakes\SimpleData[] $paramC + * @param ?\Spatie\LaravelData\Tests\Fakes\SimpleData[] $paramD + * @param \Spatie\LaravelData\DataCollection<\Spatie\LaravelData\Tests\Fakes\SimpleData> $paramE + * @param ?\Spatie\LaravelData\DataCollection<\Spatie\LaravelData\Tests\Fakes\SimpleData> $paramF + * @param SimpleData[] $paramG + * @param array $paramH + * @param array $paramJ + * @param array $paramI */ public function method( - array $propertyA, - ?array $propertyB, - ?array $propertyC, - array $propertyD, - DataCollection $propertyE, - ?DataCollection $propertyF, - array $propertyG, + array $paramA, + ?array $paramB, + ?array $paramC, + array $paramD, + DataCollection $paramE, + ?DataCollection $paramF, + array $paramG, + array $paramJ, + array $paramI, ) { } diff --git a/tests/Resolvers/VisibleDataFieldsResolverTest.php b/tests/Resolvers/VisibleDataFieldsResolverTest.php index 373a81d3..1f5e2063 100644 --- a/tests/Resolvers/VisibleDataFieldsResolverTest.php +++ b/tests/Resolvers/VisibleDataFieldsResolverTest.php @@ -1,14 +1,18 @@ $collection - */ - public function __construct( - public string $string = 'string', - public SimpleData $simple = new SimpleData('simple'), - public NestedData $nested = new NestedData(new SimpleData('simple')), - public array $collection = [ - new SimpleData('simple'), - new SimpleData('simple'), - ], - ) { - } - }; + $data = VisibleFieldsData::instance(); + + $visibleFields = findVisibleFields($data, $factory); + + $visibleFields = array_map(fn ($field) => $field instanceof TransformationContext ? $field->toArray() : $field, $visibleFields); + $expectedVisibleFields = array_map(fn ($field) => $field instanceof TransformationContext ? $field->toArray() : $field, $expectedVisibleFields); - expect(findVisibleFields($dataClass, $factory))->toEqual($expectedVisibleFields); + expect($visibleFields)->toEqual($expectedVisibleFields); - expect($dataClass->transform($factory))->toEqual($expectedTransformed); + expect($data->transform($factory))->toEqual($expectedTransformed); })->with(function () { yield 'single field' => [ 'factory' => TransformationContextFactory::create() - ->except('simple'), + ->except('single'), 'fields' => [ 'string' => null, + 'int' => null, + 'nested' => new TransformationContext(), + 'collection' => new TransformationContext(), + ], + 'transformed' => [ + 'string' => 'hello', + 'int' => 42, + 'nested' => [ + 'a' => ['string' => 'hello', 'int' => 42], + 'b' => ['string' => 'hello', 'int' => 42], + ], + 'collection' => [ + ['string' => 'hello', 'int' => 42], + ['string' => 'hello', 'int' => 42], + ], + ], + ]; + + yield 'multiple fields' => [ + 'factory' => TransformationContextFactory::create() + ->except('{string,int,single}'), + 'fields' => [ 'nested' => new TransformationContext(), 'collection' => new TransformationContext(), ], 'transformed' => [ - 'string' => 'string', 'nested' => [ - 'simple' => ['string' => 'simple'], + 'a' => ['string' => 'hello', 'int' => 42], + 'b' => ['string' => 'hello', 'int' => 42], ], 'collection' => [ - [ - 'simple' => 'simple', - ], - [ - 'simple' => 'simple', - ], + ['string' => 'hello', 'int' => 42], + ['string' => 'hello', 'int' => 42], + ], + ], + ]; + + yield 'all' => [ + 'factory' => TransformationContextFactory::create() + ->except('*'), + 'fields' => [], + 'transformed' => [], + ]; + + yield 'nested data object single field' => [ + 'factory' => TransformationContextFactory::create() + ->except('string', 'int', 'single', 'collection') // ignore non nested object fields + ->except('nested.a'), + 'fields' => [ + 'nested' => new TransformationContext( + exceptPartials: ResolvedPartialsCollection::create( + new ResolvedPartial([new NestedPartialSegment('nested'), new FieldsPartialSegment(['a'])], 1) + ), + ), + ], + 'transformed' => [ + 'nested' => [ + 'b' => ['string' => 'hello', 'int' => 42], + ], + ], + ]; + + yield 'nested data object multiple fields' => [ + 'factory' => TransformationContextFactory::create() + ->except('string', 'int', 'single', 'collection') // ignore non nested object fields + ->except('nested.{a,b}'), + 'fields' => [ + 'nested' => new TransformationContext( + exceptPartials: ResolvedPartialsCollection::create( + new ResolvedPartial([new NestedPartialSegment('nested'), new FieldsPartialSegment(['a', 'b'])], 1) + ), + ), + ], + 'transformed' => [ + 'nested' => [], + ], + ]; + + yield 'nested data object all' => [ + 'factory' => TransformationContextFactory::create() + ->except('string', 'int', 'single', 'collection') // ignore non nested object fields + ->except('nested.*'), + 'fields' => [ + 'nested' => new TransformationContext( + exceptPartials: ResolvedPartialsCollection::create( + new ResolvedPartial([new NestedPartialSegment('nested'), new AllPartialSegment()], 1) + ), + ), + ], + 'transformed' => [ + 'nested' => [], + ], + ]; + + yield 'nested data collectable single field' => [ + 'factory' => TransformationContextFactory::create() + ->except('string', 'int', 'single', 'nested') // ignore non collection fields + ->except('collection.string'), + 'fields' => [ + 'collection' => new TransformationContext( + exceptPartials: ResolvedPartialsCollection::create( + new ResolvedPartial([new NestedPartialSegment('collection'), new FieldsPartialSegment(['string'])], 1) + ), + ), + ], + 'transformed' => [ + 'collection' => [ + ['int' => 42], + ['int' => 42], + ], + ], + ]; + + yield 'nested data collectable multiple fields' => [ + 'factory' => TransformationContextFactory::create() + ->except('string', 'int', 'single', 'nested') // ignore non collection fields + ->except('collection.{string,int}'), + 'fields' => [ + 'collection' => new TransformationContext( + exceptPartials: ResolvedPartialsCollection::create( + new ResolvedPartial([new NestedPartialSegment('collection'), new FieldsPartialSegment(['string', 'int'])], 1) + ), + ), + ], + 'transformed' => [ + 'collection' => [ + [], + [], + ], + ], + ]; + + yield 'nested data collectable all' => [ + 'factory' => TransformationContextFactory::create() + ->except('string', 'int', 'single', 'nested') // ignore non collection fields + ->except('collection.*'), + 'fields' => [ + 'collection' => new TransformationContext( + exceptPartials: ResolvedPartialsCollection::create( + new ResolvedPartial([new NestedPartialSegment('collection'), new AllPartialSegment()], 1) + ), + ), + ], + 'transformed' => [ + 'collection' => [ + [], + [], + ], + ], + ]; + + yield 'combination' => [ + 'factory' => TransformationContextFactory::create() + ->except('string', 'int', 'single.string') + ->except('collection.string') + ->except('nested.a.string'), + 'fields' => [ + 'single' => new TransformationContext( + exceptPartials: ResolvedPartialsCollection::create( + new ResolvedPartial([new NestedPartialSegment('single'), new FieldsPartialSegment(['string'])], 1) + ), + ), + 'collection' => new TransformationContext( + exceptPartials: ResolvedPartialsCollection::create( + new ResolvedPartial([new NestedPartialSegment('collection'), new FieldsPartialSegment(['string'])], 1) + ), + ), + 'nested' => new TransformationContext( + exceptPartials: ResolvedPartialsCollection::create( + new ResolvedPartial([new NestedPartialSegment('nested'), new NestedPartialSegment('a') , new FieldsPartialSegment(['string'])], 1) + ), + ), + ], + 'transformed' => [ + 'single' => ['int' => 42], + 'collection' => [ + ['int' => 42], + ['int' => 42], + ], + 'nested' => [ + 'a' => ['int' => 42], + 'b' => ['string' => 'hello', 'int' => 42], ], ], ]; }); -// TODO write tests - -it('can perform an excepts', function () { - // $dataClass = new class() extends Data { - // public function __construct( - // public string $visible = 'visible', - // public SimpleData $simple = new SimpleData('simple'), - // public NestedData $nestedData = new NestedData(new SimpleData('simple')), - // public array $collection = - // ) { - // } - // }; - // - // expect(findVisibleFields($dataClass, TransformationContextFactory::create()))->toMatchArray([ - // 'multi' => new TransformationContext( - // transformValues: true, - // mapPropertyNames: true, - // wrapExecutionType: true, - // new SplObjectStorage(), - // new SplObjectStorage(), - // new SplObjectStorage(), - // new SplObjectStorage(), - // ), - // ]); +it("can execute only's", function ( + TransformationContextFactory $factory, + array $expectedVisibleFields, + array $expectedTransformed +) { + $data = VisibleFieldsData::instance(); + + $visibleFields = findVisibleFields($data, $factory); + + $visibleFields = array_map(fn ($field) => $field instanceof TransformationContext ? $field->toArray() : $field, $visibleFields); + $expectedVisibleFields = array_map(fn ($field) => $field instanceof TransformationContext ? $field->toArray() : $field, $expectedVisibleFields); + + expect($visibleFields)->toEqual($expectedVisibleFields); + + expect($data->transform($factory))->toEqual($expectedTransformed); +})->with(function () { + yield 'single field' => [ + 'factory' => TransformationContextFactory::create() + ->only('single'), + 'fields' => [ + 'single' => new TransformationContext(), + ], + 'transformed' => [ + 'single' => ['string' => 'hello', 'int' => 42,], + ], + ]; + + yield 'multiple fields' => [ + 'factory' => TransformationContextFactory::create() + ->only('{string,int,single}'), + 'fields' => [ + 'string' => null, + 'int' => null, + 'single' => new TransformationContext(), + ], + 'transformed' => [ + 'string' => 'hello', + 'int' => 42, + 'single' => ['string' => 'hello', 'int' => 42,], + ], + ]; + + yield 'all' => [ + 'factory' => TransformationContextFactory::create() + ->only('*'), + 'fields' => [ + 'string' => null, + 'int' => null, + 'single' => new TransformationContext(), + 'nested' => new TransformationContext(), + 'collection' => new TransformationContext(), + ], + 'transformed' => [ + 'string' => 'hello', + 'int' => 42, + 'single' => ['string' => 'hello', 'int' => 42,], + 'nested' => [ + 'a' => ['string' => 'hello', 'int' => 42], + 'b' => ['string' => 'hello', 'int' => 42], + ], + 'collection' => [ + ['string' => 'hello', 'int' => 42], + ['string' => 'hello', 'int' => 42], + ], + ], + ]; + + yield 'nested data object single field' => [ + 'factory' => TransformationContextFactory::create() + ->only('nested.a'), + 'fields' => [ + 'nested' => new TransformationContext( + onlyPartials: ResolvedPartialsCollection::create( + new ResolvedPartial([new NestedPartialSegment('nested'), new FieldsPartialSegment(['a'])], 1) + ), + ), + ], + 'transformed' => [ + 'nested' => [ + 'a' => ['string' => 'hello', 'int' => 42], + ], + ], + ]; + + yield 'nested data object multiple fields' => [ + 'factory' => TransformationContextFactory::create() + ->only('nested.{a,b}'), + 'fields' => [ + 'nested' => new TransformationContext( + onlyPartials: ResolvedPartialsCollection::create( + new ResolvedPartial([new NestedPartialSegment('nested'), new FieldsPartialSegment(['a', 'b'])], 1) + ), + ), + ], + 'transformed' => [ + 'nested' => [ + 'a' => ['string' => 'hello', 'int' => 42], + 'b' => ['string' => 'hello', 'int' => 42], + ], + ], + ]; + + yield 'nested data object all' => [ + 'factory' => TransformationContextFactory::create() + ->only('nested.*'), + 'fields' => [ + 'nested' => new TransformationContext( + onlyPartials: ResolvedPartialsCollection::create( + new ResolvedPartial([new NestedPartialSegment('nested'), new AllPartialSegment()], 1) + ), + ), + ], + 'transformed' => [ + 'nested' => [ + 'a' => ['string' => 'hello', 'int' => 42], + 'b' => ['string' => 'hello', 'int' => 42], + ], + ], + ]; + + yield 'nested data collectable single field' => [ + 'factory' => TransformationContextFactory::create() + ->only('collection.string'), + 'fields' => [ + 'collection' => new TransformationContext( + onlyPartials: ResolvedPartialsCollection::create( + new ResolvedPartial([new NestedPartialSegment('collection'), new FieldsPartialSegment(['string'])], 1) + ), + ), + ], + 'transformed' => [ + 'collection' => [ + ['string' => 'hello'], + ['string' => 'hello'], + ], + ], + ]; + + yield 'nested data collectable multiple fields' => [ + 'factory' => TransformationContextFactory::create() + ->only('collection.{string,int}'), + 'fields' => [ + 'collection' => new TransformationContext( + onlyPartials: ResolvedPartialsCollection::create( + new ResolvedPartial([new NestedPartialSegment('collection'), new FieldsPartialSegment(['string', 'int'])], 1) + ), + ), + ], + 'transformed' => [ + 'collection' => [ + ['string' => 'hello', 'int' => 42], + ['string' => 'hello', 'int' => 42], + ], + ], + ]; + + yield 'nested data collectable all' => [ + 'factory' => TransformationContextFactory::create() + ->only('collection.*'), + 'fields' => [ + 'collection' => new TransformationContext( + onlyPartials: ResolvedPartialsCollection::create( + new ResolvedPartial([new NestedPartialSegment('collection'), new AllPartialSegment()], 1) + ), + ), + ], + 'transformed' => [ + 'collection' => [ + ['string' => 'hello', 'int' => 42], + ['string' => 'hello', 'int' => 42], + ], + ], + ]; + + yield 'combination' => [ + 'factory' => TransformationContextFactory::create() + ->only('string', 'single.string') + ->only('collection.string') + ->only('nested.a.string'), + 'fields' => [ + 'string' => null, + 'single' => new TransformationContext( + onlyPartials: ResolvedPartialsCollection::create( + new ResolvedPartial([new NestedPartialSegment('single'), new FieldsPartialSegment(['string'])], 1) + ), + ), + 'collection' => new TransformationContext( + onlyPartials: ResolvedPartialsCollection::create( + new ResolvedPartial([new NestedPartialSegment('collection'), new FieldsPartialSegment(['string'])], 1) + ), + ), + 'nested' => new TransformationContext( + onlyPartials: ResolvedPartialsCollection::create( + new ResolvedPartial([new NestedPartialSegment('nested'), new NestedPartialSegment('a') , new FieldsPartialSegment(['string'])], 1) + ), + ), + ], + 'transformed' => [ + 'string' => 'hello', + 'single' => ['string' => 'hello'], + 'collection' => [ + ['string' => 'hello'], + ['string' => 'hello'], + ], + 'nested' => [ + 'a' => ['string' => 'hello'], + ], + ], + ]; }); diff --git a/tests/Support/Annotations/DataCollectableAnnotationReaderTest.php b/tests/Support/Annotations/DataCollectableAnnotationReaderTest.php index cdff60e5..f201d651 100644 --- a/tests/Support/Annotations/DataCollectableAnnotationReaderTest.php +++ b/tests/Support/Annotations/DataCollectableAnnotationReaderTest.php @@ -101,12 +101,15 @@ function (string $property, ?DataCollectableAnnotation $expected) { $annotations = app(DataCollectableAnnotationReader::class)->getForMethod(new ReflectionMethod(CollectionAnnotationsData::class, 'method')); expect($annotations)->toEqualCanonicalizing([ - new DataCollectableAnnotation(SimpleData::class, property: 'propertyA'), - new DataCollectableAnnotation(SimpleData::class, property: 'propertyB'), - new DataCollectableAnnotation(SimpleData::class, property: 'propertyC'), - new DataCollectableAnnotation(SimpleData::class, property: 'propertyD'), - new DataCollectableAnnotation(SimpleData::class, property: 'propertyE'), - new DataCollectableAnnotation(SimpleData::class, property: 'propertyF'), - new DataCollectableAnnotation(SimpleData::class, property: 'propertyG'), + new DataCollectableAnnotation(SimpleData::class, property: 'paramA'), + new DataCollectableAnnotation(SimpleData::class, property: 'paramB'), + new DataCollectableAnnotation(SimpleData::class, property: 'paramC'), + new DataCollectableAnnotation(SimpleData::class, property: 'paramD'), + new DataCollectableAnnotation(SimpleData::class, property: 'paramE'), + new DataCollectableAnnotation(SimpleData::class, property: 'paramF'), + new DataCollectableAnnotation(SimpleData::class, property: 'paramG'), + new DataCollectableAnnotation(SimpleData::class, property: 'paramH'), + new DataCollectableAnnotation(SimpleData::class, property: 'paramJ'), + new DataCollectableAnnotation(SimpleData::class, property: 'paramI'), ]); }); diff --git a/tests/TransformationTest.php b/tests/TransformationTest.php index 0dd8c7e0..84f0aca2 100644 --- a/tests/TransformationTest.php +++ b/tests/TransformationTest.php @@ -12,10 +12,13 @@ use Spatie\LaravelData\Lazy; use Spatie\LaravelData\Optional; use Spatie\LaravelData\PaginatedDataCollection; +use Spatie\LaravelData\Support\Annotations\DataCollectableAnnotationReader; +use Spatie\LaravelData\Support\DataConfig; use Spatie\LaravelData\Support\DataProperty; use Spatie\LaravelData\Support\Transformation\TransformationContext; use Spatie\LaravelData\Support\Transformation\TransformationContextFactory; use Spatie\LaravelData\Tests\Fakes\CircData; +use Spatie\LaravelData\Tests\Fakes\CollectionAnnotationsData; use Spatie\LaravelData\Tests\Fakes\EnumData; use Spatie\LaravelData\Tests\Fakes\Enums\DummyBackedEnum; use Spatie\LaravelData\Tests\Fakes\SimpleData; @@ -25,7 +28,6 @@ use Spatie\LaravelData\Tests\Fakes\UlarData; use Spatie\LaravelData\Transformers\DateTimeInterfaceTransformer; use Spatie\LaravelData\Transformers\Transformer; - use function Spatie\Snapshots\assertMatchesJsonSnapshot; it('can transform a data object', function () {