Skip to content

Commit

Permalink
Merge e2c7ddb into 21f4cf0
Browse files Browse the repository at this point in the history
  • Loading branch information
soyuka committed Feb 2, 2021
2 parents 21f4cf0 + e2c7ddb commit fea1613
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Bridge/Symfony/Bundle/Resources/config/api.xml
Expand Up @@ -275,11 +275,11 @@
</service>

<service id="api_platform.identifier.integer" class="ApiPlatform\Core\Identifier\Normalizer\IntegerDenormalizer" public="false">
<tag name="api_platform.identifier.denormalizer" />
<tag name="api_platform.identifier.denormalizer" priority="-100" />
</service>

<service id="api_platform.identifier.date_normalizer" class="ApiPlatform\Core\Identifier\Normalizer\DateTimeIdentifierDenormalizer" public="false">
<tag name="api_platform.identifier.denormalizer" />
<tag name="api_platform.identifier.denormalizer" priority="-100" />
</service>

<!-- Subresources -->
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Symfony/Bundle/Resources/config/ramsey_uuid.xml
Expand Up @@ -6,7 +6,7 @@

<services>
<service id="api_platform.identifier.uuid_normalizer" class="ApiPlatform\Core\Bridge\RamseyUuid\Identifier\Normalizer\UuidNormalizer" public="false">
<tag name="api_platform.identifier.denormalizer" />
<tag name="api_platform.identifier.denormalizer" priority="-100" />
</service>

<service id="api_platform.serializer.uuid_denormalizer" class="ApiPlatform\Core\Bridge\RamseyUuid\Serializer\UuidDenormalizer" public="false">
Expand Down
1 change: 1 addition & 0 deletions src/Identifier/IdentifierConverter.php
Expand Up @@ -69,6 +69,7 @@ public function convert($data, string $class, array $context = []): array

try {
$identifiers[$identifier] = $identifierTransformer->denormalize($value, $type);
break;
} catch (InvalidIdentifierException $e) {
throw new InvalidIdentifierException(sprintf('Identifier "%s" could not be denormalized.', $identifier), $e->getCode(), $e);
}
Expand Down
23 changes: 23 additions & 0 deletions tests/Identifier/IdentifierConverterTest.php
Expand Up @@ -22,6 +22,7 @@
use ApiPlatform\Core\Tests\ProphecyTrait;
use PHPUnit\Framework\TestCase;
use Symfony\Component\PropertyInfo\Type;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;

/**
* @author Antoine Bluchet <soyuka@gmail.com>
Expand Down Expand Up @@ -98,4 +99,26 @@ public function testIntegerIdentifier()

$this->assertSame(['id' => 42], $identifierDenormalizer->convert($identifier, $class));
}

public function testShouldBreakAfterTransforming()
{
$identifier = ['id' => '42'];
$class = 'Dummy';

$integerIdentifierPropertyMetadata = (new PropertyMetadata())->withIdentifier(true)->withType(new Type(Type::BUILTIN_TYPE_INT));

$propertyMetadataFactory = $this->prophesize(PropertyMetadataFactoryInterface::class);
$propertyMetadataFactory->create($class, 'id')->shouldBeCalled()->willReturn($integerIdentifierPropertyMetadata);

$identifiersExtractor = $this->prophesize(IdentifiersExtractorInterface::class);
$identifiersExtractor->getIdentifiersFromResourceClass($class)->willReturn(['id']);

$shouldNotBeCalled = $this->prophesize(DenormalizerInterface::class);
$shouldNotBeCalled->supportsDenormalization()->shouldNotBeCalled();

$identifierDenormalizers = [new IntegerDenormalizer(), $shouldNotBeCalled->reveal()];
$identifierDenormalizer = new IdentifierConverter($identifiersExtractor->reveal(), $propertyMetadataFactory->reveal(), $identifierDenormalizers);

$this->assertSame(['id' => 42], $identifierDenormalizer->convert($identifier, $class));
}
}

0 comments on commit fea1613

Please sign in to comment.