Skip to content

Commit 414c5bc

Browse files
committed
Add unit tests. Fix a bug in DateTimeIdentifierNormalizer.
1 parent 25317bd commit 414c5bc

28 files changed

+125
-10
lines changed

src/Hydra/Serializer/PartialCollectionViewNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function supportsNormalization($data, $format = null)
108108
*/
109109
public function hasCacheableSupportsMethod(): bool
110110
{
111-
return true;
111+
return $this->collectionNormalizer instanceof CacheableSupportsMethodInterface && $this->collectionNormalizer->hasCacheableSupportsMethod();
112112
}
113113

114114
/**

src/Identifier/Normalizer/DateTimeIdentifierDenormalizer.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,16 @@
1414
namespace ApiPlatform\Core\Identifier\Normalizer;
1515

1616
use ApiPlatform\Core\Exception\InvalidIdentifierException;
17-
use Symfony\Component\Serializer\Exception\InvalidArgumentException;
18-
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
17+
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
1918
use Symfony\Component\Serializer\Normalizer\DateTimeNormalizer;
20-
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
2119

22-
final class DateTimeIdentifierDenormalizer extends DateTimeNormalizer implements DenormalizerInterface, CacheableSupportsMethodInterface
20+
final class DateTimeIdentifierDenormalizer extends DateTimeNormalizer
2321
{
2422
public function denormalize($data, $class, $format = null, array $context = [])
2523
{
2624
try {
2725
return parent::denormalize($data, $class, $format, $context);
28-
} catch (InvalidArgumentException $e) {
26+
} catch (NotNormalizableValueException $e) {
2927
throw new InvalidIdentifierException($e->getMessage(), $e->getCode(), $e);
3028
}
3129
}

src/Identifier/Normalizer/IntegerDenormalizer.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@
1414
namespace ApiPlatform\Core\Identifier\Normalizer;
1515

1616
use Symfony\Component\PropertyInfo\Type;
17+
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
1718
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
1819

19-
final class IntegerDenormalizer implements DenormalizerInterface
20+
final class IntegerDenormalizer implements DenormalizerInterface, CacheableSupportsMethodInterface
2021
{
2122
public function denormalize($data, $class, $format = null, array $context = []): int
2223
{
@@ -30,4 +31,12 @@ public function supportsDenormalization($data, $type, $format = null): bool
3031
{
3132
return Type::BUILTIN_TYPE_INT === $type && \is_string($data);
3233
}
34+
35+
/**
36+
* {@inheritdoc}
37+
*/
38+
public function hasCacheableSupportsMethod(): bool
39+
{
40+
return true;
41+
}
3342
}

src/Swagger/Serializer/ApiGatewayNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,6 @@ public function supportsNormalization($data, $format = null)
115115
*/
116116
public function hasCacheableSupportsMethod(): bool
117117
{
118-
return true;
118+
return $this->documentationNormalizer instanceof CacheableSupportsMethodInterface && $this->documentationNormalizer->hasCacheableSupportsMethod();
119119
}
120120
}

tests/Hal/Serializer/CollectionNormalizerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function testSupportsNormalize()
3434
$this->assertTrue($normalizer->supportsNormalization(new \ArrayObject(), CollectionNormalizer::FORMAT));
3535
$this->assertFalse($normalizer->supportsNormalization([], 'xml'));
3636
$this->assertFalse($normalizer->supportsNormalization(new \ArrayObject(), 'xml'));
37+
$this->assertTrue($normalizer->hasCacheableSupportsMethod());
3738
}
3839

3940
public function testNormalizeApiSubLevel()

tests/Hal/Serializer/EntrypointNormalizerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public function testSupportNormalization()
4242
$this->assertTrue($normalizer->supportsNormalization($entrypoint, EntrypointNormalizer::FORMAT));
4343
$this->assertFalse($normalizer->supportsNormalization($entrypoint, 'json'));
4444
$this->assertFalse($normalizer->supportsNormalization(new \stdClass(), EntrypointNormalizer::FORMAT));
45+
$this->assertTrue($normalizer->hasCacheableSupportsMethod());
4546
}
4647

4748
public function testNormalize()

tests/Hal/Serializer/ItemNormalizerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ public function testSupportsNormalization()
8686
$this->assertTrue($normalizer->supportsNormalization($dummy, 'jsonhal'));
8787
$this->assertFalse($normalizer->supportsNormalization($dummy, 'xml'));
8888
$this->assertFalse($normalizer->supportsNormalization($std, 'jsonhal'));
89+
$this->assertTrue($normalizer->hasCacheableSupportsMethod());
8990
}
9091

9192
public function testNormalize()

tests/Hydra/Serializer/CollectionFiltersNormalizerTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Dummy;
2323
use PHPUnit\Framework\TestCase;
2424
use Psr\Container\ContainerInterface;
25+
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
2526
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
2627

2728
/**
@@ -32,7 +33,9 @@ class CollectionFiltersNormalizerTest extends TestCase
3233
public function testSupportsNormalization()
3334
{
3435
$decoratedProphecy = $this->prophesize(NormalizerInterface::class);
36+
$decoratedProphecy->willImplement(CacheableSupportsMethodInterface::class);
3537
$decoratedProphecy->supportsNormalization('foo', 'abc')->willReturn(true)->shouldBeCalled();
38+
$decoratedProphecy->hasCacheableSupportsMethod()->willReturn(true)->shouldBeCalled();
3639

3740
$normalizer = new CollectionFiltersNormalizer(
3841
$decoratedProphecy->reveal(),
@@ -42,6 +45,7 @@ public function testSupportsNormalization()
4245
);
4346

4447
$this->assertTrue($normalizer->supportsNormalization('foo', 'abc'));
48+
$this->assertTrue($normalizer->hasCacheableSupportsMethod());
4549
}
4650

4751
public function testDoNothingIfSubLevel()

tests/Hydra/Serializer/CollectionNormalizerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function testSupportsNormalize()
4444
$this->assertTrue($normalizer->supportsNormalization(new \ArrayObject(), CollectionNormalizer::FORMAT));
4545
$this->assertFalse($normalizer->supportsNormalization([], 'xml'));
4646
$this->assertFalse($normalizer->supportsNormalization(new \ArrayObject(), 'xml'));
47+
$this->assertTrue($normalizer->hasCacheableSupportsMethod());
4748
}
4849

4950
public function testNormalizeApiSubLevel()

tests/Hydra/Serializer/ConstraintViolationNormalizerTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public function testSupportNormalization()
3737
$this->assertTrue($normalizer->supportsNormalization(new ConstraintViolationList(), ConstraintViolationListNormalizer::FORMAT));
3838
$this->assertFalse($normalizer->supportsNormalization(new ConstraintViolationList(), 'xml'));
3939
$this->assertFalse($normalizer->supportsNormalization(new \stdClass(), ConstraintViolationListNormalizer::FORMAT));
40+
$this->assertTrue($normalizer->hasCacheableSupportsMethod());
4041
}
4142

4243
public function testNormalize()

0 commit comments

Comments
 (0)