66
77class AbstractRepositoryTest extends TestCase
88{
9- protected $ hits ;
9+ /**
10+ * @test
11+ */
12+ public function preventInvalidUserInput ()
13+ {
14+ $ repo = $ this ->makeRepository ();
15+
16+ $ repo ->builderMock
17+ ->shouldReceive ('paginate ' )->once ()
18+ ->with (15 , ['* ' ], 'page ' , 0 )
19+ ->andReturn (true );
20+
21+ // Ensure the package casts the per page limit correctly and returns the default 15
22+ $ this ->assertEquals (true , $ repo ->paginate ('select * ' ));
23+ }
1024
1125 /**
1226 * @test
@@ -27,24 +41,24 @@ public function shouldGetAll()
2741 */
2842 public function testPluck ()
2943 {
30- $ expectedArray = [
44+ $ expected_array = [
3145 [
3246 'title ' => 'admin ' ,
3347 'name ' => 'Bill ' ,
3448 ],
3549 [
3650 'title ' => 'user ' ,
3751 'name ' => 'Kelly ' ,
38- ]
52+ ],
3953 ];
4054
4155 $ repo = $ this ->makeRepository ();
4256
4357 $ repo ->builderMock
4458 ->shouldReceive ('pluck ' )->once ()
45- ->andReturn ($ expectedArray );
59+ ->andReturn ($ expected_array );
4660
47- $ this ->assertEquals ($ expectedArray , $ repo ->pluck ('title ' , 'name ' ));
61+ $ this ->assertEquals ($ expected_array , $ repo ->pluck ('title ' , 'name ' ));
4862 }
4963
5064 /**
@@ -80,7 +94,7 @@ public function testSimplePaginate()
8094 */
8195 public function testFind ()
8296 {
83- $ expectedArray = [
97+ $ expected_array = [
8498 'id ' => 123 ,
8599 'email ' => 'admin@mail.com ' ,
86100 'name ' => 'Bill ' ,
@@ -90,17 +104,17 @@ public function testFind()
90104
91105 $ repo ->builderMock
92106 ->shouldReceive ('find ' )->once ()
93- ->andReturn ($ expectedArray );
107+ ->andReturn ($ expected_array );
94108
95- $ this ->assertEquals ($ expectedArray , $ repo ->find ($ expectedArray ['id ' ]));
109+ $ this ->assertEquals ($ expected_array , $ repo ->find ($ expected_array ['id ' ]));
96110 }
97111
98112 /**
99113 * @test
100114 */
101115 public function testFindBy ()
102116 {
103- $ expectedArray = [
117+ $ expected_array = [
104118 'id ' => 123 ,
105119 'email ' => 'admin@mail.com ' ,
106120 'name ' => 'Bill ' ,
@@ -111,21 +125,21 @@ public function testFindBy()
111125
112126 $ repo ->builderMock
113127 ->shouldReceive ('where ' )->once ()
114- ->with ('id ' , '= ' , $ expectedArray ['id ' ])->once ()
128+ ->with ('id ' , '= ' , $ expected_array ['id ' ])->once ()
115129 ->andReturn ($ query );
116130
117131 $ query ->shouldReceive ('first ' )->once ()
118- ->andReturn ($ expectedArray );
132+ ->andReturn ($ expected_array );
119133
120- $ this ->assertEquals ($ expectedArray , $ repo ->findBy ('id ' , $ expectedArray ['id ' ]));
134+ $ this ->assertEquals ($ expected_array , $ repo ->findBy ('id ' , $ expected_array ['id ' ]));
121135 }
122136
123137 /**
124138 * @test
125139 */
126140 public function testFindAllBy ()
127141 {
128- $ expectedArray = [
142+ $ expected_array = [
129143 [
130144 'id ' => 123 ,
131145 'email ' => 'admin@mail.com ' ,
@@ -135,7 +149,7 @@ public function testFindAllBy()
135149 'id ' => 124 ,
136150 'email ' => 'admin@mail.com ' ,
137151 'name ' => 'Todd ' ,
138- ]
152+ ],
139153 ];
140154
141155 $ repo = $ this ->makeRepository ();
@@ -147,9 +161,9 @@ public function testFindAllBy()
147161 ->andReturn ($ query );
148162
149163 $ query ->shouldReceive ('get ' )->once ()
150- ->andReturn ($ expectedArray );
164+ ->andReturn ($ expected_array );
151165
152- $ this ->assertEquals ($ expectedArray , $ repo ->findAllBy ('email ' , 'admin@mail.com ' ));
166+ $ this ->assertEquals ($ expected_array , $ repo ->findAllBy ('email ' , 'admin@mail.com ' ));
153167 }
154168
155169 /**
@@ -159,7 +173,7 @@ public function testFindAllByArray()
159173 {
160174 $ ids = [1 , 33 ];
161175
162- $ expectedArray = [
176+ $ expected_array = [
163177 [
164178 'id ' => 1 ,
165179 'email ' => 'admin@mail.com ' ,
@@ -169,7 +183,7 @@ public function testFindAllByArray()
169183 'id ' => 33 ,
170184 'email ' => 'admin@mail.com ' ,
171185 'name ' => 'Todd ' ,
172- ]
186+ ],
173187 ];
174188
175189 $ repo = $ this ->makeRepository ();
@@ -181,22 +195,22 @@ public function testFindAllByArray()
181195 ->andReturn ($ query );
182196
183197 $ query ->shouldReceive ('get ' )->once ()
184- ->andReturn ($ expectedArray );
198+ ->andReturn ($ expected_array );
185199
186- $ this ->assertEquals ($ expectedArray , $ repo ->findAllBy ('id ' , $ ids ));
200+ $ this ->assertEquals ($ expected_array , $ repo ->findAllBy ('id ' , $ ids ));
187201 }
188202
189203 /**
190204 * @test
191205 */
192206 public function testFindWhere ()
193207 {
194- $ expectedArray = [
208+ $ expected_array = [
195209 [
196210 'id ' => 123 ,
197211 'email ' => 'admin@mail.com ' ,
198212 'name ' => 'Bill ' ,
199- ]
213+ ],
200214 ];
201215
202216 $ repo = $ this ->makeRepository ();
@@ -205,10 +219,10 @@ public function testFindWhere()
205219 ->shouldReceive ('where ' )->once ()
206220 ->with ('id ' , '= ' , 123 )->once ()
207221 ->shouldReceive ('get ' )->once ()
208- ->andReturn ($ expectedArray );
222+ ->andReturn ($ expected_array );
209223
210- $ this ->assertEquals ($ expectedArray , $ repo ->findWhere ([
211- 'id ' => 123
224+ $ this ->assertEquals ($ expected_array , $ repo ->findWhere ([
225+ 'id ' => 123 ,
212226 ]));
213227 }
214228
@@ -217,12 +231,12 @@ public function testFindWhere()
217231 */
218232 public function testFindWhereWithConditions ()
219233 {
220- $ expectedArray = [
234+ $ expected_array = [
221235 [
222236 'id ' => 123 ,
223237 'email ' => 'admin@mail.com ' ,
224238 'name ' => 'Bill ' ,
225- ]
239+ ],
226240 ];
227241
228242 $ repo = $ this ->makeRepository ();
@@ -231,10 +245,10 @@ public function testFindWhereWithConditions()
231245 ->shouldReceive ('where ' )->once ()
232246 ->with ('id ' , '< ' , 123 )->once ()
233247 ->shouldReceive ('get ' )->once ()
234- ->andReturn ($ expectedArray );
248+ ->andReturn ($ expected_array );
235249
236- $ this ->assertEquals ($ expectedArray , $ repo ->findWhere ([
237- ['id ' , '< ' , 123 ]
250+ $ this ->assertEquals ($ expected_array , $ repo ->findWhere ([
251+ ['id ' , '< ' , 123 ],
238252 ]));
239253 }
240254
@@ -266,7 +280,7 @@ public function testCacheCallbackWithCache()
266280 */
267281 public function testFindUsingScope ()
268282 {
269- $ expectedArray = [
283+ $ expected_array = [
270284 [
271285 'id ' => 123 ,
272286 'email ' => 'admin@mail.com ' ,
@@ -278,7 +292,7 @@ public function testFindUsingScope()
278292 'email ' => 'admin@mail.com ' ,
279293 'name ' => 'Todd ' ,
280294 'is_admin ' => true ,
281- ]
295+ ],
282296 ];
283297
284298 $ repo = $ this ->makeRepository ();
@@ -290,8 +304,8 @@ public function testFindUsingScope()
290304 ->andReturn ($ query );
291305
292306 $ query ->shouldReceive ('get ' )->once ()
293- ->andReturn ($ expectedArray );
307+ ->andReturn ($ expected_array );
294308
295- $ this ->assertEquals ($ expectedArray , $ repo ->adminOnlyScope ()->all ());
309+ $ this ->assertEquals ($ expected_array , $ repo ->adminOnlyScope ()->all ());
296310 }
297311}
0 commit comments