Skip to content

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
inxilpro authored and github-actions[bot] committed Nov 20, 2023
1 parent 7a25738 commit 5aa98ce
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 48 deletions.
8 changes: 4 additions & 4 deletions src/Support/Normalization/CollectionNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,10 @@ public function getSupportedTypes(?string $format): array
protected function determineContainedType(Collection $collection): ?string
{
[$only_objects, $types] = $this->getCollectionMetadata($collection);
if ($types->isEmpty()) {
return null;
}

if ($types->isEmpty()) {
return null;
}

// If the whole collection contains one type, then we're golden
if ($types->count() === 1) {
Expand Down
88 changes: 44 additions & 44 deletions tests/Unit/CollectionNormalizerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,52 +16,52 @@
use Thunk\Verbs\Support\Normalization\SelfSerializingNormalizer;
use Thunk\Verbs\Support\Normalization\StateNormalizer;

it('it can normalize an empty collection', function() {
$serializer = new SymfonySerializer(
normalizers: [$normalizer = new CollectionNormalizer()],
encoders: [new JsonEncoder()],
);
$collection = new Collection();
expect($normalizer->supportsNormalization($collection))->toBeTrue();
$normalized = $serializer->normalize($collection, 'json');
expect($normalized)->toBe([]);
$encoded = json_encode($normalized);
expect($encoded)->toBe('[]')
->and($normalizer->supportsDenormalization($encoded, Collection::class, 'json'))->toBeTrue();
$denormalized = $serializer->denormalize($normalized, Collection::class);
// And the denormalized data should be the same
expect($denormalized)->toBeInstanceOf(Collection::class)
->and($denormalized->isEmpty())->toBeTrue();
it('it can normalize an empty collection', function () {
$serializer = new SymfonySerializer(
normalizers: [$normalizer = new CollectionNormalizer()],
encoders: [new JsonEncoder()],
);

$collection = new Collection();

expect($normalizer->supportsNormalization($collection))->toBeTrue();

$normalized = $serializer->normalize($collection, 'json');
expect($normalized)->toBe([]);

$encoded = json_encode($normalized);
expect($encoded)->toBe('[]')
->and($normalizer->supportsDenormalization($encoded, Collection::class, 'json'))->toBeTrue();

$denormalized = $serializer->denormalize($normalized, Collection::class);

// And the denormalized data should be the same
expect($denormalized)->toBeInstanceOf(Collection::class)
->and($denormalized->isEmpty())->toBeTrue();
});

it('it can normalize an empty Eloquent collection', function() {
$serializer = new SymfonySerializer(
normalizers: [$normalizer = new CollectionNormalizer()],
encoders: [new JsonEncoder()],
);
$collection = new EloquentCollection();
expect($normalizer->supportsNormalization($collection))->toBeTrue();
$normalized = $serializer->normalize($collection, 'json');
expect($normalized)->toBe(['fqcn' => EloquentCollection::class]);
$encoded = json_encode($normalized);
expect($encoded)->toBe('{"fqcn":'.json_encode(EloquentCollection::class).'}')
->and($normalizer->supportsDenormalization($encoded, EloquentCollection::class, 'json'))->toBeTrue();
$denormalized = $serializer->denormalize($normalized, EloquentCollection::class);
// And the denormalized data should be the same
expect($denormalized)->toBeInstanceOf(EloquentCollection::class)
->and($denormalized->isEmpty())->toBeTrue();
it('it can normalize an empty Eloquent collection', function () {
$serializer = new SymfonySerializer(
normalizers: [$normalizer = new CollectionNormalizer()],
encoders: [new JsonEncoder()],
);

$collection = new EloquentCollection();

expect($normalizer->supportsNormalization($collection))->toBeTrue();

$normalized = $serializer->normalize($collection, 'json');
expect($normalized)->toBe(['fqcn' => EloquentCollection::class]);

$encoded = json_encode($normalized);
expect($encoded)->toBe('{"fqcn":'.json_encode(EloquentCollection::class).'}')
->and($normalizer->supportsDenormalization($encoded, EloquentCollection::class, 'json'))->toBeTrue();

$denormalized = $serializer->denormalize($normalized, EloquentCollection::class);

// And the denormalized data should be the same
expect($denormalized)->toBeInstanceOf(EloquentCollection::class)
->and($denormalized->isEmpty())->toBeTrue();
});

it('it can normalize a collection all of scalars', function () {
Expand Down

0 comments on commit 5aa98ce

Please sign in to comment.