@@ -62,11 +62,43 @@ public function testApplyToCollection()
62
62
$ extension ->applyToCollection ($ queryBuilder , new QueryNameGenerator (), 'Foo ' , 'op ' );
63
63
}
64
64
65
+ public function testApplyToCollectionWithItemPerPageZero ()
66
+ {
67
+ $ requestStack = new RequestStack ();
68
+ $ requestStack ->push (new Request (['pagination ' => true , 'itemsPerPage ' => 0 , '_page ' => 1 ]));
69
+
70
+ $ resourceMetadataFactoryProphecy = $ this ->prophesize (ResourceMetadataFactoryInterface::class);
71
+ $ attributes = [
72
+ 'pagination_enabled ' => true ,
73
+ 'pagination_client_enabled ' => true ,
74
+ 'pagination_items_per_page ' => 0 ,
75
+ ];
76
+ $ resourceMetadataFactoryProphecy ->create ('Foo ' )->willReturn (new ResourceMetadata (null , null , null , [], [], $ attributes ))->shouldBeCalled ();
77
+ $ resourceMetadataFactory = $ resourceMetadataFactoryProphecy ->reveal ();
78
+
79
+ $ queryBuilderProphecy = $ this ->prophesize (QueryBuilder::class);
80
+ $ queryBuilderProphecy ->setFirstResult (0 )->willReturn ($ queryBuilderProphecy )->shouldBeCalled ();
81
+ $ queryBuilderProphecy ->setMaxResults (0 )->shouldBeCalled ();
82
+ $ queryBuilder = $ queryBuilderProphecy ->reveal ();
83
+
84
+ $ extension = new PaginationExtension (
85
+ $ this ->prophesize (ManagerRegistry::class)->reveal (),
86
+ $ requestStack ,
87
+ $ resourceMetadataFactory ,
88
+ true ,
89
+ false ,
90
+ false ,
91
+ 0 ,
92
+ '_page '
93
+ );
94
+ $ extension ->applyToCollection ($ queryBuilder , new QueryNameGenerator (), 'Foo ' , 'op ' );
95
+ }
96
+
65
97
/**
66
98
* @expectedException \ApiPlatform\Core\Exception\InvalidArgumentException
67
- * @expectedExceptionMessage Item per page parameter should not be less than or equal to 0
99
+ * @expectedExceptionMessage Page should not be greater than 1 if itemsPegPage is equal to 0
68
100
*/
69
- public function testApplyToCollectionWithItemPerPageZero ()
101
+ public function testApplyToCollectionWithItemPerPageZeroAndPage2 ()
70
102
{
71
103
$ requestStack = new RequestStack ();
72
104
$ requestStack ->push (new Request (['pagination ' => true , 'itemsPerPage ' => 0 , '_page ' => 2 ]));
@@ -81,8 +113,8 @@ public function testApplyToCollectionWithItemPerPageZero()
81
113
$ resourceMetadataFactory = $ resourceMetadataFactoryProphecy ->reveal ();
82
114
83
115
$ queryBuilderProphecy = $ this ->prophesize (QueryBuilder::class);
84
- $ queryBuilderProphecy ->setFirstResult (40 )->willReturn ($ queryBuilderProphecy )->shouldNotBeCalled ();
85
- $ queryBuilderProphecy ->setMaxResults (40 )->shouldNotBeCalled ();
116
+ $ queryBuilderProphecy ->setFirstResult (0 )->willReturn ($ queryBuilderProphecy )->shouldNotBeCalled ();
117
+ $ queryBuilderProphecy ->setMaxResults (0 )->shouldNotBeCalled ();
86
118
$ queryBuilder = $ queryBuilderProphecy ->reveal ();
87
119
88
120
$ extension = new PaginationExtension (
@@ -100,7 +132,7 @@ public function testApplyToCollectionWithItemPerPageZero()
100
132
101
133
/**
102
134
* @expectedException \ApiPlatform\Core\Exception\InvalidArgumentException
103
- * @expectedExceptionMessage Item per page parameter should not be less than or equal to 0
135
+ * @expectedExceptionMessage Item per page parameter should not be less than 0
104
136
*/
105
137
public function testApplyToCollectionWithItemPerPageLessThen0 ()
106
138
{
@@ -111,7 +143,7 @@ public function testApplyToCollectionWithItemPerPageLessThen0()
111
143
$ attributes = [
112
144
'pagination_enabled ' => true ,
113
145
'pagination_client_enabled ' => true ,
114
- 'pagination_items_per_page ' => 0 ,
146
+ 'pagination_items_per_page ' => - 20 ,
115
147
];
116
148
$ resourceMetadataFactoryProphecy ->create ('Foo ' )->willReturn (new ResourceMetadata (null , null , null , [], [], $ attributes ))->shouldBeCalled ();
117
149
$ resourceMetadataFactory = $ resourceMetadataFactoryProphecy ->reveal ();
0 commit comments