@@ -26,6 +26,12 @@ public function testSelect()
26
26
['id ' => 1002 , 'price ' => 25 ],
27
27
['id ' => 1003 , 'price ' => 10 ],
28
28
], $ associativeArray ->select (['id ' , 'price ' ])->toArray ());
29
+
30
+ $ this ->assertEquals ([
31
+ ['category ' => 'C ' ],
32
+ ['category ' => 'A ' ],
33
+ ['category ' => 'B ' ],
34
+ ], $ associativeArray ->select ('category ' )->toArray ());
29
35
}
30
36
31
37
public function testWhere ()
@@ -127,13 +133,22 @@ public function testOrderBy()
127
133
['id ' => 1001 , 'category ' => 'C ' , 'price ' => 10 ],
128
134
['id ' => 1002 , 'category ' => 'A ' , 'price ' => 25 ],
129
135
['id ' => 1003 , 'category ' => 'B ' , 'price ' => 10 ],
136
+ ['id ' => 1004 , 'category ' => 'C ' , 'price ' => 10 ],
130
137
]);
131
138
132
139
$ this ->assertEquals ([
133
140
['id ' => 1002 , 'category ' => 'A ' , 'price ' => 25 ],
134
141
['id ' => 1003 , 'category ' => 'B ' , 'price ' => 10 ],
135
142
['id ' => 1001 , 'category ' => 'C ' , 'price ' => 10 ],
143
+ ['id ' => 1004 , 'category ' => 'C ' , 'price ' => 10 ],
136
144
], $ associativeArray ->orderBy (['price ' , 'category ' ], ['desc ' , 'asc ' ])->toArray ());
145
+
146
+ $ this ->assertEquals ([
147
+ ['id ' => 1004 , 'category ' => 'C ' , 'price ' => 10 ],
148
+ ['id ' => 1003 , 'category ' => 'B ' , 'price ' => 10 ],
149
+ ['id ' => 1002 , 'category ' => 'A ' , 'price ' => 25 ],
150
+ ['id ' => 1001 , 'category ' => 'C ' , 'price ' => 10 ],
151
+ ], $ associativeArray ->orderBy ('id ' , 'desc ' )->toArray ());
137
152
}
138
153
139
154
public function testGroupBy ()
@@ -150,6 +165,11 @@ public function testGroupBy()
150
165
['id ' => 1002 , 'category ' => 'A ' , 'price ' => 25 ],
151
166
['id ' => 1004 , 'category ' => 'A ' , 'price ' => 30 ],
152
167
], $ associativeArray ->groupBy (['category ' , 'price ' ])->toArray ());
168
+
169
+ $ this ->assertEquals ([
170
+ ['id ' => 1001 , 'category ' => 'B ' , 'price ' => 30 ],
171
+ ['id ' => 1002 , 'category ' => 'A ' , 'price ' => 25 ],
172
+ ], $ associativeArray ->groupBy ('category ' )->toArray ());
153
173
}
154
174
155
175
public function testFirst ()
@@ -164,6 +184,8 @@ public function testFirst()
164
184
['id ' => 1001 , 'category ' => 'C ' , 'price ' => 10 ],
165
185
$ associativeArray ->first ()
166
186
);
187
+
188
+ $ this ->assertNull ((new AssociativeArray ())->first ());
167
189
}
168
190
169
191
public function testLast ()
@@ -178,6 +200,8 @@ public function testLast()
178
200
['id ' => 1003 , 'category ' => 'B ' , 'price ' => 10 ],
179
201
$ associativeArray ->last ()
180
202
);
203
+
204
+ $ this ->assertNull ((new AssociativeArray ())->last ());
181
205
}
182
206
183
207
public function testCount ()
@@ -369,7 +393,9 @@ public function testGetAssociativeRows()
369
393
['id ' => 1003 , 'category ' => 'B ' , 'price ' => 10 ],
370
394
];
371
395
372
- $ this ->assertSame ($ data , $ method ->invokeArgs ($ associativeArray , [new AssociativeArray ($ data )]));
373
396
$ this ->assertSame ($ data , $ method ->invokeArgs ($ associativeArray , [$ data ]));
397
+ $ this ->assertSame ($ data , $ method ->invokeArgs ($ associativeArray , [new AssociativeArray ($ data )]));
398
+ $ this ->assertSame ($ data , $ method ->invokeArgs ($ associativeArray , [(new AssociativeArray ($ data ))->getIterator ()]));
399
+ $ this ->assertSame ($ data , $ method ->invokeArgs ($ associativeArray , [(object ) $ data ]));
374
400
}
375
401
}
0 commit comments