查询语言.limit
Testing Is Documentation
tests/Database/Query/LimitTest.php
Uses
<?php
use Tests\Database\DatabaseTestCase as TestCase;
limit 限制条数
public function testBaseUse(): void
{
$connect = $this->createDatabaseConnectMock();
$sql = <<<'eot'
[
"SELECT `test_query`.* FROM `test_query` LIMIT 5,10",
[],
false
]
eot;
$this->assertSame(
$sql,
$this->varJson(
$connect
->table('test_query')
->limit(5, 10)
->find(null, true)
)
);
}
指示仅查询第一个符合条件的记录
public function testOne(): void
{
$connect = $this->createDatabaseConnectMock();
$sql = <<<'eot'
[
"SELECT `test_query`.* FROM `test_query` LIMIT 1",
[],
false
]
eot;
$this->assertSame(
$sql,
$this->varJson(
$connect
->table('test_query')
->one()
->find(null, true),
1
)
);
}
指示查询所有符合条件的记录
public function testAll(): void
{
$connect = $this->createDatabaseConnectMock();
$sql = <<<'eot'
[
"SELECT `test_query`.* FROM `test_query`",
[],
false
]
eot;
$this->assertSame(
$sql,
$this->varJson(
$connect
->table('test_query')
->all()
->find(null, true),
2
)
);
}
查询几条记录
public function testTop(): void
{
$connect = $this->createDatabaseConnectMock();
$sql = <<<'eot'
[
"SELECT `test_query`.* FROM `test_query` LIMIT 0,15",
[],
false
]
eot;
$this->assertSame(
$sql,
$this->varJson(
$connect
->table('test_query')
->top(15)
->find(null, true),
3
)
);
}