查询语言.limit

Testing Is Documentation

tests/Database/Query/LimitTest.php查询语言.limit - 图1

Uses

  1. <?php
  2. use Tests\Database\DatabaseTestCase as TestCase;

limit 限制条数

  1. public function testBaseUse(): void
  2. {
  3. $connect = $this->createDatabaseConnectMock();
  4. $sql = <<<'eot'
  5. [
  6. "SELECT `test_query`.* FROM `test_query` LIMIT 5,10",
  7. [],
  8. false
  9. ]
  10. eot;
  11. $this->assertSame(
  12. $sql,
  13. $this->varJson(
  14. $connect
  15. ->table('test_query')
  16. ->limit(5, 10)
  17. ->find(null, true)
  18. )
  19. );
  20. }

指示仅查询第一个符合条件的记录

  1. public function testOne(): void
  2. {
  3. $connect = $this->createDatabaseConnectMock();
  4. $sql = <<<'eot'
  5. [
  6. "SELECT `test_query`.* FROM `test_query` LIMIT 1",
  7. [],
  8. false
  9. ]
  10. eot;
  11. $this->assertSame(
  12. $sql,
  13. $this->varJson(
  14. $connect
  15. ->table('test_query')
  16. ->one()
  17. ->find(null, true),
  18. 1
  19. )
  20. );
  21. }

指示查询所有符合条件的记录

  1. public function testAll(): void
  2. {
  3. $connect = $this->createDatabaseConnectMock();
  4. $sql = <<<'eot'
  5. [
  6. "SELECT `test_query`.* FROM `test_query`",
  7. [],
  8. false
  9. ]
  10. eot;
  11. $this->assertSame(
  12. $sql,
  13. $this->varJson(
  14. $connect
  15. ->table('test_query')
  16. ->all()
  17. ->find(null, true),
  18. 2
  19. )
  20. );
  21. }

查询几条记录

  1. public function testTop(): void
  2. {
  3. $connect = $this->createDatabaseConnectMock();
  4. $sql = <<<'eot'
  5. [
  6. "SELECT `test_query`.* FROM `test_query` LIMIT 0,15",
  7. [],
  8. false
  9. ]
  10. eot;
  11. $this->assertSame(
  12. $sql,
  13. $this->varJson(
  14. $connect
  15. ->table('test_query')
  16. ->top(15)
  17. ->find(null, true),
  18. 3
  19. )
  20. );
  21. }