15
15
16
16
use ApiPlatform \Core \Api \CachedIdentifiersExtractor ;
17
17
use ApiPlatform \Core \Api \IdentifiersExtractorInterface ;
18
+ use ApiPlatform \Core \Tests \Fixtures \TestBundle \Doctrine \Generator \Uuid ;
18
19
use ApiPlatform \Core \Tests \Fixtures \TestBundle \Entity \Dummy ;
19
20
use ApiPlatform \Core \Tests \Fixtures \TestBundle \Entity \RelatedDummy ;
20
21
use PHPUnit \Framework \TestCase ;
26
27
*/
27
28
class CachedIdentifiersExtractorTest extends TestCase
28
29
{
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 )
30
40
{
31
41
$ key = 'iri_identifiers ' .md5 (Dummy::class);
32
42
@@ -39,14 +49,14 @@ public function testFirstPass()
39
49
$ cacheItemPool ->save ($ cacheItem )->shouldBeCalled ();
40
50
41
51
$ dummy = new Dummy ();
42
- $ dummy ->setId (1 );
52
+ $ dummy ->setId ($ identifier );
43
53
44
54
$ decoration = $ this ->prophesize (IdentifiersExtractorInterface::class);
45
- $ decoration ->getIdentifiersFromItem ($ dummy )->shouldBeCalled ()->willReturn (['id ' => 1 ]);
55
+ $ decoration ->getIdentifiersFromItem ($ dummy )->shouldBeCalled ()->willReturn (['id ' => $ identifierValue ]);
46
56
47
57
$ identifiersExtractor = new CachedIdentifiersExtractor ($ cacheItemPool ->reveal (), $ decoration ->reveal (), null );
48
58
49
- $ expectedResult = ['id ' => 1 ];
59
+ $ expectedResult = ['id ' => $ identifierValue ];
50
60
$ this ->assertEquals ($ expectedResult , $ identifiersExtractor ->getIdentifiersFromItem ($ dummy ));
51
61
$ this ->assertEquals ($ expectedResult , $ identifiersExtractor ->getIdentifiersFromItem ($ dummy ), 'Trigger the local cache ' );
52
62
@@ -57,7 +67,10 @@ public function testFirstPass()
57
67
$ this ->assertEquals ($ expectedResult , $ identifiersExtractor ->getIdentifiersFromResourceClass (Dummy::class), 'Trigger the local cache ' );
58
68
}
59
69
60
- public function testSecondPass ()
70
+ /**
71
+ * @dataProvider identifiersProvider
72
+ */
73
+ public function testSecondPass ($ identifier , $ identifierValue )
61
74
{
62
75
$ key = 'iri_identifiers ' .md5 (Dummy::class);
63
76
@@ -69,19 +82,19 @@ public function testSecondPass()
69
82
$ cacheItemPool ->getItem ($ key )->shouldBeCalled ()->willReturn ($ cacheItem );
70
83
71
84
$ dummy = new Dummy ();
72
- $ dummy ->setId (1 );
85
+ $ dummy ->setId ($ identifier );
73
86
74
87
$ decoration = $ this ->prophesize (IdentifiersExtractorInterface::class);
75
88
$ decoration ->getIdentifiersFromItem ($ dummy )->shouldNotBeCalled ();
76
89
77
90
$ identifiersExtractor = new CachedIdentifiersExtractor ($ cacheItemPool ->reveal (), $ decoration ->reveal (), null );
78
91
79
- $ expectedResult = ['id ' => 1 ];
92
+ $ expectedResult = ['id ' => $ identifierValue ];
80
93
$ this ->assertEquals ($ expectedResult , $ identifiersExtractor ->getIdentifiersFromItem ($ dummy ));
81
94
$ this ->assertEquals ($ expectedResult , $ identifiersExtractor ->getIdentifiersFromItem ($ dummy ), 'Trigger the local cache ' );
82
95
}
83
96
84
- public function testSecondPassWithRelatedNotCached ()
97
+ public function testFirstPassWithRelated ()
85
98
{
86
99
$ key = 'iri_identifiers ' .md5 (Dummy::class);
87
100
$ keyRelated = 'iri_identifiers ' .md5 (RelatedDummy::class);
@@ -114,7 +127,7 @@ public function testSecondPassWithRelatedNotCached()
114
127
$ this ->assertEquals ($ expectedResult , $ identifiersExtractor ->getIdentifiersFromItem ($ dummy ), 'Trigger the local cache ' );
115
128
}
116
129
117
- public function testSecondPassWithRelatedCached ()
130
+ public function testSecondPassWithRelated ()
118
131
{
119
132
$ key = 'iri_identifiers ' .md5 (Dummy::class);
120
133
$ keyRelated = 'iri_identifiers ' .md5 (RelatedDummy::class);
0 commit comments