查询一列数据.list

Testing Is Documentation

tests/Database/Read/ListTest.php查询一列数据.list - 图1

Uses

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

list 查询基础用法

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

list 查询字段逗号分隔

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

list 查询字段多个字符串

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

list 查询字段数组

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

list 查询字段数组和字符串混合

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