|
17 | 17 | use ApiPlatform\Core\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
|
18 | 18 | use ApiPlatform\Core\Metadata\Property\PropertyNameCollection;
|
19 | 19 | use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Dummy;
|
| 20 | +use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\UpperCaseIdentifierDummy; |
20 | 21 | use Doctrine\Common\Annotations\Reader;
|
21 | 22 | use Prophecy\Argument;
|
22 | 23 | use Prophecy\Prophecy\ProphecyInterface;
|
@@ -60,6 +61,36 @@ public function getDependencies()
|
60 | 61 | ];
|
61 | 62 | }
|
62 | 63 |
|
| 64 | + /** |
| 65 | + * @dataProvider getUpperCaseDependencies |
| 66 | + */ |
| 67 | + public function testUpperCaseCreate(ProphecyInterface $decorated = null, array $results) |
| 68 | + { |
| 69 | + $reader = $this->prophesize(Reader::class); |
| 70 | + $reader->getPropertyAnnotation(new \ReflectionProperty(UpperCaseIdentifierDummy::class, 'name'), ApiProperty::class)->willReturn(new ApiProperty())->shouldBeCalled(); |
| 71 | + $reader->getPropertyAnnotation(new \ReflectionProperty(UpperCaseIdentifierDummy::class, 'Uuid'), ApiProperty::class)->willReturn(new ApiProperty())->shouldBeCalled(); |
| 72 | + $reader->getPropertyAnnotation(Argument::type(\ReflectionProperty::class), ApiProperty::class)->willReturn(null)->shouldBeCalled(); |
| 73 | + $reader->getMethodAnnotation(new \ReflectionMethod(UpperCaseIdentifierDummy::class, 'getName'), ApiProperty::class)->willReturn(new ApiProperty())->shouldBeCalled(); |
| 74 | + $reader->getMethodAnnotation(new \ReflectionMethod(UpperCaseIdentifierDummy::class, 'getUuid'), ApiProperty::class)->willReturn(new ApiProperty())->shouldBeCalled(); |
| 75 | + $reader->getMethodAnnotation(Argument::type(\ReflectionMethod::class), ApiProperty::class)->willReturn(null)->shouldBeCalled(); |
| 76 | + |
| 77 | + $factory = new AnnotationPropertyNameCollectionFactory($reader->reveal(), $decorated ? $decorated->reveal() : null); |
| 78 | + $metadata = $factory->create(UpperCaseIdentifierDummy::class, []); |
| 79 | + |
| 80 | + $this->assertEquals($results, iterator_to_array($metadata)); |
| 81 | + } |
| 82 | + |
| 83 | + public function getUpperCaseDependencies() |
| 84 | + { |
| 85 | + $decoratedThrowsNotFound = $this->prophesize(PropertyNameCollectionFactoryInterface::class); |
| 86 | + $decoratedThrowsNotFound->create(UpperCaseIdentifierDummy::class, [])->willThrow(new ResourceClassNotFoundException())->shouldBeCalled(); |
| 87 | + |
| 88 | + return [ |
| 89 | + [null, ['Uuid', 'name']], |
| 90 | + [$decoratedThrowsNotFound, ['Uuid', 'name']], |
| 91 | + ]; |
| 92 | + } |
| 93 | + |
63 | 94 | /**
|
64 | 95 | * @expectedException \ApiPlatform\Core\Exception\ResourceClassNotFoundException
|
65 | 96 | * @expectedExceptionMessage The resource class "\DoNotExist" does not exist.
|
|
0 commit comments