2
2
3
3
namespace LibraryTest \Repository ;
4
4
5
+ use Application \Library \QueryFilter \Exception \UnrecognizedFieldException ;
6
+ use Application \Library \QueryFilter \Exception \UnsupportedTypeException ;
5
7
use Application \Library \QueryFilter \QueryFilter ;
6
- use Application \Library \QueryFilter \Command \ Repository ;
8
+ use Application \Library \QueryFilter \Command ;
7
9
use Doctrine \ORM \Query ;
8
10
use Doctrine \ORM \QueryBuilder ;
9
11
use DoctrineModule \Stdlib \Hydrator \DoctrineObject ;
13
15
use PHPUnit_Framework_MockObject_MockObject as MockObject ;
14
16
use Test \Bootstrap ;
15
17
16
- class BookRepositoryTestCase extends AbstractRepositoryTestCase
18
+ class BookRepositoryTest extends AbstractRepositoryTestCase
17
19
{
18
20
/**
19
21
* @var BookRepository
@@ -152,7 +154,7 @@ public function testDelete_WithoutFlush()
152
154
$ this ->testedObj ->delete ($ bookEntity , false );
153
155
}
154
156
155
- public function testFindByQueryFilter ()
157
+ public function testFindByQueryFilter_WithValidQueryData ()
156
158
{
157
159
$ sm = Bootstrap::getServiceManager ();
158
160
@@ -188,7 +190,7 @@ public function testFindByQueryFilter()
188
190
$ queryFilter = $ sm ->get (QueryFilter::class);
189
191
$ queryFilter ->setQueryParameters ($ queryData );
190
192
191
- $ commandCollection = $ sm ->get (Repository \CommandCollection::class);
193
+ $ commandCollection = $ sm ->get (Command \ Repository \CommandCollection::class);
192
194
193
195
$ this ->classMetadataMock ->expects ($ this ->any ())
194
196
->method ('getFieldNames ' )
@@ -213,4 +215,69 @@ public function testFindByQueryFilter()
213
215
214
216
$ this ->testedObj ->findByQueryFilter ($ queryFilter , $ commandCollection );
215
217
}
218
+
219
+ public function testFindByQueryFilter_WithNotFoundCriteriaCommand ()
220
+ {
221
+ $ sm = Bootstrap::getServiceManager ();
222
+
223
+ $ queryData = [
224
+ '$fields ' => 'id,author,title ' ,
225
+ ];
226
+
227
+ $ fieldNames = [
228
+ 'id ' ,
229
+ 'author ' ,
230
+ 'title ' ,
231
+ 'year ' ,
232
+ 'price ' ,
233
+ 'name ' ,
234
+ 'status '
235
+ ];
236
+
237
+ /** @var QueryFilter $queryFilter */
238
+ $ queryFilter = $ sm ->get (QueryFilter::class);
239
+ $ queryFilter ->setQueryParameters ($ queryData );
240
+
241
+ $ commandCollection = new Command \Repository \CommandCollection (
242
+ [
243
+ new Command \Repository \BetweenCommand ()
244
+ ]
245
+ );
246
+
247
+ $ this ->classMetadataMock ->expects ($ this ->any ())
248
+ ->method ('getFieldNames ' )
249
+ ->will ($ this ->returnValue ($ fieldNames ));
250
+
251
+ $ this ->setExpectedException (UnsupportedTypeException::class, 'Unsupported condition type: fields ' );
252
+
253
+ $ this ->testedObj ->findByQueryFilter ($ queryFilter , $ commandCollection );
254
+ }
255
+
256
+ public function testFindByQueryFilter_WithUnrecognizedField ()
257
+ {
258
+ $ sm = Bootstrap::getServiceManager ();
259
+
260
+ $ queryData = [
261
+ '$fields ' => 'id,author,title ' ,
262
+ ];
263
+
264
+ $ fieldNames = [
265
+ 'author ' ,
266
+ 'title ' ,
267
+ ];
268
+
269
+ /** @var QueryFilter $queryFilter */
270
+ $ queryFilter = $ sm ->get (QueryFilter::class);
271
+ $ queryFilter ->setQueryParameters ($ queryData );
272
+
273
+ $ commandCollection = $ sm ->get (Command \Repository \CommandCollection::class);
274
+
275
+ $ this ->classMetadataMock ->expects ($ this ->any ())
276
+ ->method ('getFieldNames ' )
277
+ ->will ($ this ->returnValue ($ fieldNames ));
278
+
279
+ $ this ->setExpectedException (UnrecognizedFieldException::class, 'Field unrecognized in entity: id ' );
280
+
281
+ $ this ->testedObj ->findByQueryFilter ($ queryFilter , $ commandCollection );
282
+ }
216
283
}
0 commit comments