14
14
namespace ApiPlatform \Core \Tests \DataProvider ;
15
15
16
16
use ApiPlatform \Core \DataProvider \ChainItemDataProvider ;
17
- use ApiPlatform \Core \DataProvider \DenormalizedIdentifiersAwareItemDataProviderInterface ;
18
17
use ApiPlatform \Core \DataProvider \ItemDataProviderInterface ;
19
18
use ApiPlatform \Core \DataProvider \RestrictedDataProviderInterface ;
20
19
use ApiPlatform \Core \Exception \ResourceClassNotSupportedException ;
21
- use ApiPlatform \Core \Tests \Fixtures \TestBundle \Entity \CompositePrimitiveItem ;
22
20
use ApiPlatform \Core \Tests \Fixtures \TestBundle \Entity \Dummy ;
23
21
use ApiPlatform \Core \Tests \ProphecyTrait ;
24
22
use PHPUnit \Framework \TestCase ;
@@ -37,47 +35,19 @@ public function testGetItem()
37
35
$ dummy = new Dummy ();
38
36
$ dummy ->setName ('Lucie ' );
39
37
40
- $ firstDataProvider = $ this ->prophesize (DenormalizedIdentifiersAwareItemDataProviderInterface::class);
41
- $ firstDataProvider ->willImplement (RestrictedDataProviderInterface::class);
42
- $ firstDataProvider ->supports (Dummy::class, null , [])->willReturn (false );
43
-
44
- $ secondDataProvider = $ this ->prophesize (DenormalizedIdentifiersAwareItemDataProviderInterface::class);
45
- $ secondDataProvider ->willImplement (RestrictedDataProviderInterface::class);
46
- $ secondDataProvider ->supports (Dummy::class, null , [])->willReturn (true );
47
- $ secondDataProvider ->getItem (Dummy::class, ['id ' => 1 ], null , [])->willReturn ($ dummy );
48
-
49
- $ thirdDataProvider = $ this ->prophesize (DenormalizedIdentifiersAwareItemDataProviderInterface::class);
50
- $ thirdDataProvider ->willImplement (RestrictedDataProviderInterface::class);
51
- $ thirdDataProvider ->supports (Dummy::class, null , [])->willReturn (true );
52
- $ thirdDataProvider ->getItem (Dummy::class, ['id ' => 1 ], null , [])->willReturn (new \stdClass ());
53
-
54
- $ chainItemDataProvider = new ChainItemDataProvider ([
55
- $ firstDataProvider ->reveal (),
56
- $ secondDataProvider ->reveal (),
57
- $ thirdDataProvider ->reveal (),
58
- ]);
59
-
60
- $ this ->assertEquals ($ dummy , $ chainItemDataProvider ->getItem (Dummy::class, ['id ' => 1 ]));
61
- }
62
-
63
- public function testGetItemWithoutDenormalizedIdentifiers ()
64
- {
65
- $ dummy = new Dummy ();
66
- $ dummy ->setName ('Lucie ' );
67
-
68
38
$ firstDataProvider = $ this ->prophesize (ItemDataProviderInterface::class);
69
39
$ firstDataProvider ->willImplement (RestrictedDataProviderInterface::class);
70
40
$ firstDataProvider ->supports (Dummy::class, null , [])->willReturn (false );
71
41
72
42
$ secondDataProvider = $ this ->prophesize (ItemDataProviderInterface::class);
73
43
$ secondDataProvider ->willImplement (RestrictedDataProviderInterface::class);
74
44
$ secondDataProvider ->supports (Dummy::class, null , [])->willReturn (true );
75
- $ secondDataProvider ->getItem (Dummy::class, ' 1 ' , null , [])->willReturn ($ dummy );
45
+ $ secondDataProvider ->getItem (Dummy::class, [ ' id ' => 1 ] , null , [])->willReturn ($ dummy );
76
46
77
47
$ thirdDataProvider = $ this ->prophesize (ItemDataProviderInterface::class);
78
48
$ thirdDataProvider ->willImplement (RestrictedDataProviderInterface::class);
79
49
$ thirdDataProvider ->supports (Dummy::class, null , [])->willReturn (true );
80
- $ thirdDataProvider ->getItem (Dummy::class, 1 , null , [])->willReturn (new \stdClass ());
50
+ $ thirdDataProvider ->getItem (Dummy::class, [ ' id ' => 1 ] , null , [])->willReturn (new \stdClass ());
81
51
82
52
$ chainItemDataProvider = new ChainItemDataProvider ([
83
53
$ firstDataProvider ->reveal (),
@@ -96,7 +66,7 @@ public function testGetItemExceptions()
96
66
97
67
$ chainItemDataProvider = new ChainItemDataProvider ([$ firstDataProvider ->reveal ()]);
98
68
99
- $ this ->assertEquals ('' , $ chainItemDataProvider ->getItem ('notfound ' , 1 ));
69
+ $ this ->assertEquals ('' , $ chainItemDataProvider ->getItem ('notfound ' , [ ' id ' => 1 ] ));
100
70
}
101
71
102
72
/**
@@ -109,37 +79,17 @@ public function testLegacyGetItem()
109
79
$ dummy ->setName ('Lucie ' );
110
80
111
81
$ firstDataProvider = $ this ->prophesize (ItemDataProviderInterface::class);
112
- $ firstDataProvider ->getItem (Dummy::class, 1 , null , [])->willThrow (ResourceClassNotSupportedException::class);
82
+ $ firstDataProvider ->getItem (Dummy::class, [ ' test ' => 1 ] , null , [])->willThrow (ResourceClassNotSupportedException::class);
113
83
114
84
$ secondDataProvider = $ this ->prophesize (ItemDataProviderInterface::class);
115
- $ secondDataProvider ->getItem (Dummy::class, 1 , null , [])->willReturn ($ dummy );
85
+ $ secondDataProvider ->getItem (Dummy::class, [ ' test ' => 1 ] , null , [])->willReturn ($ dummy );
116
86
117
87
$ thirdDataProvider = $ this ->prophesize (ItemDataProviderInterface::class);
118
- $ thirdDataProvider ->getItem (Dummy::class, 1 , null , [])->willReturn (new \stdClass ());
88
+ $ thirdDataProvider ->getItem (Dummy::class, [ ' test ' => 1 ] , null , [])->willReturn (new \stdClass ());
119
89
120
90
$ chainItemDataProvider = new ChainItemDataProvider ([$ firstDataProvider ->reveal (), $ secondDataProvider ->reveal (), $ thirdDataProvider ->reveal ()]);
121
91
122
- $ chainItemDataProvider ->getItem (Dummy::class, 1 );
123
- }
124
-
125
- /**
126
- * @group legacy
127
- * @expectedDeprecation Receiving "$id" as non-array in an item data provider is deprecated in 2.3 in favor of implementing "ApiPlatform\Core\DataProvider\DenormalizedIdentifiersAwareItemDataProviderInterface".
128
- */
129
- public function testLegacyGetItemWithoutDenormalizedIdentifiersAndCompositeIdentifier ()
130
- {
131
- $ dummy = new CompositePrimitiveItem ('Lucie ' , 1984 );
132
-
133
- $ dataProvider = $ this ->prophesize (ItemDataProviderInterface::class);
134
- $ dataProvider ->willImplement (RestrictedDataProviderInterface::class);
135
- $ dataProvider ->supports (CompositePrimitiveItem::class, null , [])->willReturn (true );
136
- $ dataProvider ->getItem (CompositePrimitiveItem::class, 'name=Lucie;year=1984 ' , null , [])->willReturn ($ dummy );
137
-
138
- $ chainItemDataProvider = new ChainItemDataProvider ([
139
- $ dataProvider ->reveal (),
140
- ]);
141
-
142
- $ this ->assertEquals ($ dummy , $ chainItemDataProvider ->getItem (CompositePrimitiveItem::class, ['name ' => 'Lucie ' , 'year ' => 1984 ]));
92
+ $ chainItemDataProvider ->getItem (Dummy::class, ['test ' => 1 ]);
143
93
}
144
94
145
95
/**
@@ -149,10 +99,10 @@ public function testLegacyGetItemWithoutDenormalizedIdentifiersAndCompositeIdent
149
99
public function testLegacyGetItemExceptions ()
150
100
{
151
101
$ firstDataProvider = $ this ->prophesize (ItemDataProviderInterface::class);
152
- $ firstDataProvider ->getItem ('notfound ' , 1 , null , [])->willThrow (ResourceClassNotSupportedException::class);
102
+ $ firstDataProvider ->getItem ('notfound ' , [ ' test ' => 1 ] , null , [])->willThrow (ResourceClassNotSupportedException::class);
153
103
154
104
$ chainItemDataProvider = new ChainItemDataProvider ([$ firstDataProvider ->reveal ()]);
155
105
156
- $ this ->assertEquals ('' , $ chainItemDataProvider ->getItem ('notfound ' , 1 ));
106
+ $ this ->assertEquals ('' , $ chainItemDataProvider ->getItem ('notfound ' , [ ' test ' => 1 ] ));
157
107
}
158
108
}
0 commit comments