Skip to content

Commit 38dbbe8

Browse files
authored
[9.x] Improve test for latest and oldest function in Query Builder class (#44287)
1 parent 754b12b commit 38dbbe8

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

tests/Database/DatabaseQueryBuilderTest.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1478,6 +1478,36 @@ public function testOrderBys()
14781478
$this->assertEquals([1, 1, 'news', 'opinion'], $builder->getBindings());
14791479
}
14801480

1481+
public function testLatest()
1482+
{
1483+
$builder = $this->getBuilder();
1484+
$builder->select('*')->from('users')->latest();
1485+
$this->assertSame('select * from "users" order by "created_at" desc', $builder->toSql());
1486+
1487+
$builder = $this->getBuilder();
1488+
$builder->select('*')->from('users')->latest()->limit(1);
1489+
$this->assertSame('select * from "users" order by "created_at" desc limit 1', $builder->toSql());
1490+
1491+
$builder = $this->getBuilder();
1492+
$builder->select('*')->from('users')->latest('updated_at');
1493+
$this->assertSame('select * from "users" order by "updated_at" desc', $builder->toSql());
1494+
}
1495+
1496+
public function testOldest()
1497+
{
1498+
$builder = $this->getBuilder();
1499+
$builder->select('*')->from('users')->oldest();
1500+
$this->assertSame('select * from "users" order by "created_at" asc', $builder->toSql());
1501+
1502+
$builder = $this->getBuilder();
1503+
$builder->select('*')->from('users')->oldest()->limit(1);
1504+
$this->assertSame('select * from "users" order by "created_at" asc limit 1', $builder->toSql());
1505+
1506+
$builder = $this->getBuilder();
1507+
$builder->select('*')->from('users')->oldest('updated_at');
1508+
$this->assertSame('select * from "users" order by "updated_at" asc', $builder->toSql());
1509+
}
1510+
14811511
public function testOrderBysSqlServer()
14821512
{
14831513
$builder = $this->getSqlServerBuilder();

0 commit comments

Comments
 (0)