MNT Add test to SQLSelect for Zero limit

This commit is contained in:
Maxime Rainville 2023-01-25 17:19:30 +13:00
parent 5090f49ecc
commit fc6c45df57
2 changed files with 16 additions and 2 deletions

View File

@ -121,7 +121,8 @@ class DataListTest extends SapphireTest
$this->assertEquals(['Joe', 'Phil'], $list->limit(2, 1)->column('Name')); $this->assertEquals(['Joe', 'Phil'], $list->limit(2, 1)->column('Name'));
} }
public function limitDataProvider(): array { public function limitDataProvider(): array
{
return [ return [
'no limit' => [null, 0, 3], 'no limit' => [null, 0, 3],
'smaller limit' => [2, 0, 2], 'smaller limit' => [2, 0, 2],
@ -151,7 +152,7 @@ class DataListTest extends SapphireTest
$this->assertCount($expectedCount, $list->limit($length, $offset)); $this->assertCount($expectedCount, $list->limit($length, $offset));
$this->assertCount( $this->assertCount(
$expectedCount, $expectedCount,
$list->limit(0,9999)->limit($length, $offset), $list->limit(0, 9999)->limit($length, $offset),
'Follow up limit calls unset previous ones' 'Follow up limit calls unset previous ones'
); );

View File

@ -173,6 +173,7 @@ class SQLSelectTest extends SapphireTest
$this->assertSQLEquals("SELECT * FROM MyTable LIMIT 99 OFFSET 97", $query->sql($parameters)); $this->assertSQLEquals("SELECT * FROM MyTable LIMIT 99 OFFSET 97", $query->sql($parameters));
} }
public function testSelectWithOrderbyClause() public function testSelectWithOrderbyClause()
{ {
$query = new SQLSelect(); $query = new SQLSelect();
@ -255,6 +256,18 @@ class SQLSelectTest extends SapphireTest
); );
} }
public function testZeroLimit()
{
$query = new SQLSelect();
$query->setFrom("MyTable");
$query->setLimit(0);
$this->assertSQLEquals(
'SELECT * FROM MyTable LIMIT 0',
$query->sql($parameters)
);
}
public function testNegativeLimit() public function testNegativeLimit()
{ {
$this->expectException(\InvalidArgumentException::class); $this->expectException(\InvalidArgumentException::class);