19
19
use ApiPlatform \Doctrine \Odm \State \CollectionProvider ;
20
20
use ApiPlatform \Exception \RuntimeException ;
21
21
use ApiPlatform \Metadata \ApiResource ;
22
- use ApiPlatform \Metadata \Get ;
23
22
use ApiPlatform \Metadata \GetCollection ;
24
23
use ApiPlatform \Metadata \Operations ;
25
24
use ApiPlatform \Metadata \Resource \Factory \ResourceMetadataCollectionFactoryInterface ;
26
25
use ApiPlatform \Metadata \Resource \ResourceMetadataCollection ;
27
- use ApiPlatform \Tests \Fixtures \TestBundle \Document \Dummy ;
28
26
use ApiPlatform \Tests \Fixtures \TestBundle \Document \ProviderEntity ;
29
27
use Doctrine \ODM \MongoDB \Aggregation \Builder ;
30
28
use Doctrine \ODM \MongoDB \DocumentManager ;
@@ -71,14 +69,14 @@ public function testGetCollection()
71
69
$ managerProphecy ->getRepository (ProviderEntity::class)->willReturn ($ repositoryProphecy ->reveal ())->shouldBeCalled ();
72
70
73
71
$ this ->managerRegistryProphecy ->getManagerForClass (ProviderEntity::class)->willReturn ($ managerProphecy ->reveal ())->shouldBeCalled ();
74
-
75
- $ this ->resourceMetadataFactoryProphecy ->create (ProviderEntity::class)->willReturn (new ResourceMetadataCollection (ProviderEntity::class, [(new ApiResource ())->withOperations (new Operations (['foo ' => new GetCollection () ]))]));
72
+ $ operation = ( new GetCollection ())-> withName ( ' foo ' )-> withClass (ProviderEntity::class);
73
+ $ this ->resourceMetadataFactoryProphecy ->create (ProviderEntity::class)->willReturn (new ResourceMetadataCollection (ProviderEntity::class, [(new ApiResource ())->withOperations (new Operations (['foo ' => $ operation ]))]));
76
74
77
75
$ extensionProphecy = $ this ->prophesize (AggregationCollectionExtensionInterface::class);
78
76
$ extensionProphecy ->applyToCollection ($ aggregationBuilder , ProviderEntity::class, 'foo ' , [])->shouldBeCalled ();
79
77
80
78
$ dataProvider = new CollectionProvider ($ this ->resourceMetadataFactoryProphecy ->reveal (), $ this ->managerRegistryProphecy ->reveal (), [$ extensionProphecy ->reveal ()]);
81
- $ this ->assertEquals ($ iterator , $ dataProvider ->provide (ProviderEntity::class , [], ' foo ' ));
79
+ $ this ->assertEquals ($ iterator , $ dataProvider ->provide ($ operation , []));
82
80
}
83
81
84
82
public function testGetCollectionWithExecuteOptions ()
@@ -98,13 +96,17 @@ public function testGetCollectionWithExecuteOptions()
98
96
99
97
$ this ->managerRegistryProphecy ->getManagerForClass (ProviderEntity::class)->willReturn ($ managerProphecy ->reveal ())->shouldBeCalled ();
100
98
101
- $ this ->resourceMetadataFactoryProphecy ->create (ProviderEntity::class)->willReturn (new ResourceMetadataCollection (ProviderEntity::class, [(new ApiResource ())->withOperations (new Operations (['foo ' => (new GetCollection ())->withExtraProperties (['doctrine_mongodb ' => ['execute_options ' => ['allowDiskUse ' => true ]]])]))]));
99
+ $ operation = (new GetCollection ())->withExtraProperties (['doctrine_mongodb ' => ['execute_options ' => ['allowDiskUse ' => true ]]])->withName ('foo ' )->withClass (ProviderEntity::class);
100
+ $ this ->resourceMetadataFactoryProphecy ->create (ProviderEntity::class)
101
+ ->willReturn (new ResourceMetadataCollection (ProviderEntity::class, [
102
+ (new ApiResource ())->withOperations (new Operations (['foo ' => $ operation ])),
103
+ ]));
102
104
103
105
$ extensionProphecy = $ this ->prophesize (AggregationCollectionExtensionInterface::class);
104
106
$ extensionProphecy ->applyToCollection ($ aggregationBuilder , ProviderEntity::class, 'foo ' , [])->shouldBeCalled ();
105
107
106
108
$ dataProvider = new CollectionProvider ($ this ->resourceMetadataFactoryProphecy ->reveal (), $ this ->managerRegistryProphecy ->reveal (), [$ extensionProphecy ->reveal ()]);
107
- $ this ->assertEquals ($ iterator , $ dataProvider ->provide (ProviderEntity::class , [], ' foo ' ));
109
+ $ this ->assertEquals ($ iterator , $ dataProvider ->provide ($ operation , []));
108
110
}
109
111
110
112
public function testAggregationResultExtension ()
@@ -119,14 +121,15 @@ public function testAggregationResultExtension()
119
121
$ managerProphecy ->getRepository (ProviderEntity::class)->willReturn ($ repositoryProphecy ->reveal ())->shouldBeCalled ();
120
122
121
123
$ this ->managerRegistryProphecy ->getManagerForClass (ProviderEntity::class)->willReturn ($ managerProphecy ->reveal ())->shouldBeCalled ();
124
+ $ operation = (new GetCollection ())->withName ('foo ' )->withClass (ProviderEntity::class);
122
125
123
126
$ extensionProphecy = $ this ->prophesize (AggregationResultCollectionExtensionInterface::class);
124
127
$ extensionProphecy ->applyToCollection ($ aggregationBuilder , ProviderEntity::class, 'foo ' , [])->shouldBeCalled ();
125
128
$ extensionProphecy ->supportsResult (ProviderEntity::class, 'foo ' , [])->willReturn (true )->shouldBeCalled ();
126
129
$ extensionProphecy ->getResult ($ aggregationBuilder , ProviderEntity::class, 'foo ' , [])->willReturn ([])->shouldBeCalled ();
127
130
128
131
$ dataProvider = new CollectionProvider ($ this ->resourceMetadataFactoryProphecy ->reveal (), $ this ->managerRegistryProphecy ->reveal (), [$ extensionProphecy ->reveal ()]);
129
- $ this ->assertEquals ([], $ dataProvider ->provide (ProviderEntity::class , [], ' foo ' ));
132
+ $ this ->assertEquals ([], $ dataProvider ->provide ($ operation , []));
130
133
}
131
134
132
135
public function testCannotCreateAggregationBuilder ()
@@ -142,43 +145,8 @@ public function testCannotCreateAggregationBuilder()
142
145
$ this ->managerRegistryProphecy ->getManagerForClass (ProviderEntity::class)->willReturn ($ managerProphecy ->reveal ())->shouldBeCalled ();
143
146
144
147
$ dataProvider = new CollectionProvider ($ this ->resourceMetadataFactoryProphecy ->reveal (), $ this ->managerRegistryProphecy ->reveal ());
145
- $ this ->assertEquals ([], $ dataProvider ->provide (ProviderEntity::class, [], 'foo ' ));
146
- }
147
-
148
- public function testSupportedClass ()
149
- {
150
- $ documentManagerProphecy = $ this ->prophesize (DocumentManager::class);
151
-
152
- $ this ->resourceMetadataFactoryProphecy ->create (ProviderEntity::class)->willReturn (new ResourceMetadataCollection (ProviderEntity::class, [(new ApiResource ())->withOperations (new Operations (['foo ' => new GetCollection ()]))]));
153
- $ this ->managerRegistryProphecy ->getManagerForClass (ProviderEntity::class)->willReturn ($ documentManagerProphecy ->reveal ())->shouldBeCalled ();
154
-
155
- $ extensionProphecy = $ this ->prophesize (AggregationResultCollectionExtensionInterface::class);
156
-
157
- $ dataProvider = new CollectionProvider ($ this ->resourceMetadataFactoryProphecy ->reveal (), $ this ->managerRegistryProphecy ->reveal (), [$ extensionProphecy ->reveal ()]);
158
- $ this ->assertTrue ($ dataProvider ->supports (ProviderEntity::class, [], 'foo ' ));
159
- }
160
-
161
- public function testUnsupportedClass ()
162
- {
163
- $ this ->managerRegistryProphecy ->getManagerForClass (Dummy::class)->willReturn (null )->shouldBeCalled ();
164
-
165
- $ extensionProphecy = $ this ->prophesize (AggregationResultCollectionExtensionInterface::class);
166
-
167
- $ dataProvider = new CollectionProvider ($ this ->resourceMetadataFactoryProphecy ->reveal (), $ this ->managerRegistryProphecy ->reveal (), [$ extensionProphecy ->reveal ()]);
168
- $ this ->assertFalse ($ dataProvider ->supports (Dummy::class, [], 'foo ' ));
169
- }
170
-
171
- public function testNotCollectionOperation ()
172
- {
173
- $ documentManagerProphecy = $ this ->prophesize (DocumentManager::class);
174
-
175
- $ this ->resourceMetadataFactoryProphecy ->create (ProviderEntity::class)->willReturn (new ResourceMetadataCollection (ProviderEntity::class, [(new ApiResource ())->withOperations (new Operations (['foo ' => new Get ()]))]));
176
- $ this ->managerRegistryProphecy ->getManagerForClass (ProviderEntity::class)->willReturn ($ documentManagerProphecy ->reveal ())->shouldBeCalled ();
177
-
178
- $ extensionProphecy = $ this ->prophesize (AggregationResultCollectionExtensionInterface::class);
179
-
180
- $ dataProvider = new CollectionProvider ($ this ->resourceMetadataFactoryProphecy ->reveal (), $ this ->managerRegistryProphecy ->reveal (), [$ extensionProphecy ->reveal ()]);
181
- $ this ->assertFalse ($ dataProvider ->supports (ProviderEntity::class, [], 'foo ' ));
148
+ $ operation = (new GetCollection ())->withName ('foo ' )->withClass (ProviderEntity::class);
149
+ $ this ->assertEquals ([], $ dataProvider ->provide ($ operation , []));
182
150
}
183
151
184
152
public function testOperationNotFound ()
@@ -204,6 +172,6 @@ public function testOperationNotFound()
204
172
$ extensionProphecy ->applyToCollection ($ aggregationBuilder , ProviderEntity::class, 'bar ' , [])->shouldBeCalled ();
205
173
206
174
$ dataProvider = new CollectionProvider ($ this ->resourceMetadataFactoryProphecy ->reveal (), $ this ->managerRegistryProphecy ->reveal (), [$ extensionProphecy ->reveal ()]);
207
- $ this ->assertEquals ($ iterator , $ dataProvider ->provide (ProviderEntity::class, [], ' bar ' ));
175
+ $ this ->assertEquals ($ iterator , $ dataProvider ->provide (( new GetCollection ())-> withName ( ' bar ' )-> withClass ( ProviderEntity::class) , []));
208
176
}
209
177
}
0 commit comments