Skip to content

Commit 3a579d5

Browse files
committed
Increase test coverage
1 parent 69cc1c0 commit 3a579d5

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

tests/AssociativeArrayTest.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ public function testSelect()
2626
['id' => 1002, 'price' => 25],
2727
['id' => 1003, 'price' => 10],
2828
], $associativeArray->select(['id', 'price'])->toArray());
29+
30+
$this->assertEquals([
31+
['category' => 'C'],
32+
['category' => 'A'],
33+
['category' => 'B'],
34+
], $associativeArray->select('category')->toArray());
2935
}
3036

3137
public function testWhere()
@@ -127,13 +133,22 @@ public function testOrderBy()
127133
['id' => 1001, 'category' => 'C', 'price' => 10],
128134
['id' => 1002, 'category' => 'A', 'price' => 25],
129135
['id' => 1003, 'category' => 'B', 'price' => 10],
136+
['id' => 1004, 'category' => 'C', 'price' => 10],
130137
]);
131138

132139
$this->assertEquals([
133140
['id' => 1002, 'category' => 'A', 'price' => 25],
134141
['id' => 1003, 'category' => 'B', 'price' => 10],
135142
['id' => 1001, 'category' => 'C', 'price' => 10],
143+
['id' => 1004, 'category' => 'C', 'price' => 10],
136144
], $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());
137152
}
138153

139154
public function testGroupBy()
@@ -150,6 +165,11 @@ public function testGroupBy()
150165
['id' => 1002, 'category' => 'A', 'price' => 25],
151166
['id' => 1004, 'category' => 'A', 'price' => 30],
152167
], $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());
153173
}
154174

155175
public function testFirst()
@@ -164,6 +184,8 @@ public function testFirst()
164184
['id' => 1001, 'category' => 'C', 'price' => 10],
165185
$associativeArray->first()
166186
);
187+
188+
$this->assertNull((new AssociativeArray())->first());
167189
}
168190

169191
public function testLast()
@@ -178,6 +200,8 @@ public function testLast()
178200
['id' => 1003, 'category' => 'B', 'price' => 10],
179201
$associativeArray->last()
180202
);
203+
204+
$this->assertNull((new AssociativeArray())->last());
181205
}
182206

183207
public function testCount()
@@ -369,7 +393,9 @@ public function testGetAssociativeRows()
369393
['id' => 1003, 'category' => 'B', 'price' => 10],
370394
];
371395

372-
$this->assertSame($data, $method->invokeArgs($associativeArray, [new AssociativeArray($data)]));
373396
$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]));
374400
}
375401
}

0 commit comments

Comments
 (0)