1515
1616use ApiPlatform \Core \Api \CachedIdentifiersExtractor ;
1717use ApiPlatform \Core \Api \IdentifiersExtractorInterface ;
18+ use ApiPlatform \Core \Tests \Fixtures \TestBundle \Doctrine \Generator \Uuid ;
1819use ApiPlatform \Core \Tests \Fixtures \TestBundle \Entity \Dummy ;
1920use ApiPlatform \Core \Tests \Fixtures \TestBundle \Entity \RelatedDummy ;
2021use PHPUnit \Framework \TestCase ;
2627 */
2728class CachedIdentifiersExtractorTest extends TestCase
2829{
29- public function testFirstPass ()
30+ public function identifiersProvider ()
31+ {
32+ yield [1 , 1 ];
33+ yield [$ uuid = new Uuid (), $ uuid ->__toString ()];
34+ }
35+
36+ /**
37+ * @dataProvider identifiersProvider
38+ */
39+ public function testFirstPass ($ identifier , $ identifierValue )
3040 {
3141 $ key = 'iri_identifiers ' .md5 (Dummy::class);
3242
@@ -39,14 +49,14 @@ public function testFirstPass()
3949 $ cacheItemPool ->save ($ cacheItem )->shouldBeCalled ();
4050
4151 $ dummy = new Dummy ();
42- $ dummy ->setId (1 );
52+ $ dummy ->setId ($ identifier );
4353
4454 $ decoration = $ this ->prophesize (IdentifiersExtractorInterface::class);
45- $ decoration ->getIdentifiersFromItem ($ dummy )->shouldBeCalled ()->willReturn (['id ' => 1 ]);
55+ $ decoration ->getIdentifiersFromItem ($ dummy )->shouldBeCalled ()->willReturn (['id ' => $ identifierValue ]);
4656
4757 $ identifiersExtractor = new CachedIdentifiersExtractor ($ cacheItemPool ->reveal (), $ decoration ->reveal (), null );
4858
49- $ expectedResult = ['id ' => 1 ];
59+ $ expectedResult = ['id ' => $ identifierValue ];
5060 $ this ->assertEquals ($ expectedResult , $ identifiersExtractor ->getIdentifiersFromItem ($ dummy ));
5161 $ this ->assertEquals ($ expectedResult , $ identifiersExtractor ->getIdentifiersFromItem ($ dummy ), 'Trigger the local cache ' );
5262
@@ -57,7 +67,10 @@ public function testFirstPass()
5767 $ this ->assertEquals ($ expectedResult , $ identifiersExtractor ->getIdentifiersFromResourceClass (Dummy::class), 'Trigger the local cache ' );
5868 }
5969
60- public function testSecondPass ()
70+ /**
71+ * @dataProvider identifiersProvider
72+ */
73+ public function testSecondPass ($ identifier , $ identifierValue )
6174 {
6275 $ key = 'iri_identifiers ' .md5 (Dummy::class);
6376
@@ -69,19 +82,19 @@ public function testSecondPass()
6982 $ cacheItemPool ->getItem ($ key )->shouldBeCalled ()->willReturn ($ cacheItem );
7083
7184 $ dummy = new Dummy ();
72- $ dummy ->setId (1 );
85+ $ dummy ->setId ($ identifier );
7386
7487 $ decoration = $ this ->prophesize (IdentifiersExtractorInterface::class);
7588 $ decoration ->getIdentifiersFromItem ($ dummy )->shouldNotBeCalled ();
7689
7790 $ identifiersExtractor = new CachedIdentifiersExtractor ($ cacheItemPool ->reveal (), $ decoration ->reveal (), null );
7891
79- $ expectedResult = ['id ' => 1 ];
92+ $ expectedResult = ['id ' => $ identifierValue ];
8093 $ this ->assertEquals ($ expectedResult , $ identifiersExtractor ->getIdentifiersFromItem ($ dummy ));
8194 $ this ->assertEquals ($ expectedResult , $ identifiersExtractor ->getIdentifiersFromItem ($ dummy ), 'Trigger the local cache ' );
8295 }
8396
84- public function testSecondPassWithRelatedNotCached ()
97+ public function testFirstPassWithRelated ()
8598 {
8699 $ key = 'iri_identifiers ' .md5 (Dummy::class);
87100 $ keyRelated = 'iri_identifiers ' .md5 (RelatedDummy::class);
@@ -114,7 +127,7 @@ public function testSecondPassWithRelatedNotCached()
114127 $ this ->assertEquals ($ expectedResult , $ identifiersExtractor ->getIdentifiersFromItem ($ dummy ), 'Trigger the local cache ' );
115128 }
116129
117- public function testSecondPassWithRelatedCached ()
130+ public function testSecondPassWithRelated ()
118131 {
119132 $ key = 'iri_identifiers ' .md5 (Dummy::class);
120133 $ keyRelated = 'iri_identifiers ' .md5 (RelatedDummy::class);
0 commit comments