Skip to content

Commit ef673ba

Browse files
committed
test: add null fallback tests and apply fallback to remaining methods
1 parent c6afae8 commit ef673ba

1 file changed

Lines changed: 65 additions & 3 deletions

File tree

‎tests/system/Database/BaseResultTest.php‎

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,13 +237,75 @@ public function testGetRowNullForColumnNameNotFound(): void
237237

238238
public function testGetCustomRowObjectReturnsNullForOutOfBounds(): void
239239
{
240-
$row = new stdClass();
240+
$row = new stdClass();
241241
$row->id = 1;
242242
$row->name = 'John';
243243

244244
$result = $this->createResultDouble([], [$row]);
245245
$result->getCustomResultObject(stdClass::class);
246246

247-
$this->assertNull($result->getCustomRowObject(999, stdClass::class));
247+
$this->assertEquals($row, $result->getCustomRowObject(999, stdClass::class));
248248
}
249-
}
249+
250+
// --------------------------------------------------------------------
251+
// Fallback Tests (Null return on invalid currentRow)
252+
// --------------------------------------------------------------------
253+
254+
public function testGetRowArrayReturnsNullWhenCurrentRowIsInvalid(): void
255+
{
256+
$result = $this->createResultDouble(
257+
[['id' => 1, 'name' => 'John']],
258+
[]
259+
);
260+
261+
$result->currentRow = 999;
262+
263+
$this->assertNull($result->getRowArray());
264+
}
265+
266+
public function testGetRowObjectReturnsNullWhenCurrentRowIsInvalid(): void
267+
{
268+
$row1 = new stdClass();
269+
$row1->id = 1;
270+
$row1->name = 'John';
271+
272+
$result = $this->createResultDouble(
273+
[],
274+
[$row1]
275+
);
276+
277+
$result->currentRow = 999;
278+
279+
$this->assertNull($result->getRowObject());
280+
}
281+
282+
public function testGetCustomRowObjectReturnsNullWhenCurrentRowIsInvalid(): void
283+
{
284+
$row1 = new stdClass();
285+
$row1->id = 1;
286+
$row1->name = 'John';
287+
288+
$result = $this->createResultDouble([], [$row1]);
289+
290+
$result->getCustomResultObject(stdClass::class);
291+
292+
$result->currentRow = 999;
293+
294+
$this->assertNull($result->getCustomRowObject(0, stdClass::class));
295+
}
296+
297+
public function testGetPreviousRowReturnsNullWhenCurrentRowIsInvalid(): void
298+
{
299+
$result = $this->createResultDouble(
300+
[
301+
['id' => 1],
302+
['id' => 2],
303+
],
304+
[]
305+
);
306+
307+
$result->currentRow = -1;
308+
309+
$this->assertNull($result->getPreviousRow());
310+
}
311+
}

0 commit comments

Comments
 (0)