查询语言.whereDate

Testing Is Documentation

tests/Database/Query/TimeTest.php查询语言.whereDate - 图1

Uses

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

whereDate 时间查询

  1. public function testBaseUse(): void
  2. {
  3. $connect = $this->createDatabaseConnectMock();
  4. $sql = <<<'eot'
  5. [
  6. "SELECT `test_query`.* FROM `test_query` WHERE `test_query`.`create_date` = :test_query_create_date LIMIT 1",
  7. {
  8. "test_query_create_date": [
  9. %d
  10. ]
  11. },
  12. false
  13. ]
  14. eot;
  15. $value = strtotime('+5 month');
  16. $value2 = $value + 1;
  17. $value3 = $value + 2;
  18. $this->assertTimeRange(
  19. $this->varJson(
  20. $connect
  21. ->table('test_query')
  22. ->whereDate('create_date', '+5 month')
  23. ->findOne(true)
  24. ),
  25. sprintf($sql, $value),
  26. sprintf($sql, $value2),
  27. sprintf($sql, $value3)
  28. );
  29. }

whereDay 时间查询

  1. public function testWhereDay(): void
  2. {
  3. $connect = $this->createDatabaseConnectMock();
  4. $sql = <<<'eot'
  5. [
  6. "SELECT `test_query`.* FROM `test_query` WHERE `test_query`.`create_date` = :test_query_create_date LIMIT 1",
  7. {
  8. "test_query_create_date": [
  9. %d
  10. ]
  11. },
  12. false
  13. ]
  14. eot;
  15. $date = getdate();
  16. $value = mktime(0, 0, 0, $date['mon'], 5, $date['year']);
  17. $value2 = $value + 1;
  18. $value3 = $value + 2;
  19. $this->assertTimeRange(
  20. $this->varJson(
  21. $connect
  22. ->table('test_query')
  23. ->whereDay('create_date', 5)
  24. ->findOne(true)
  25. ),
  26. sprintf($sql, $value),
  27. sprintf($sql, $value2),
  28. sprintf($sql, $value3)
  29. );
  30. }

whereMonth 时间查询

  1. public function testWhereMonth(): void
  2. {
  3. $connect = $this->createDatabaseConnectMock();
  4. $sql = <<<'eot'
  5. [
  6. "SELECT `test_query`.* FROM `test_query` WHERE `test_query`.`create_date` = :test_query_create_date LIMIT 1",
  7. {
  8. "test_query_create_date": [
  9. %d
  10. ]
  11. },
  12. false
  13. ]
  14. eot;
  15. $date = getdate();
  16. $value = mktime(0, 0, 0, 5, 1, $date['year']);
  17. $value2 = $value + 1;
  18. $value3 = $value + 2;
  19. $this->assertTimeRange(
  20. $this->varJson(
  21. $connect
  22. ->table('test_query')
  23. ->whereMonth('create_date', 5)
  24. ->findOne(true)
  25. ),
  26. sprintf($sql, $value),
  27. sprintf($sql, $value2),
  28. sprintf($sql, $value3)
  29. );
  30. }

whereYear 时间查询

  1. public function testWhereYear(): void
  2. {
  3. $connect = $this->createDatabaseConnectMock();
  4. $sql = <<<'eot'
  5. [
  6. "SELECT `test_query`.* FROM `test_query` WHERE `test_query`.`create_date` = :test_query_create_date LIMIT 1",
  7. {
  8. "test_query_create_date": [
  9. %d
  10. ]
  11. },
  12. false
  13. ]
  14. eot;
  15. $value = mktime(0, 0, 0, 1, 1, 2018);
  16. $value2 = $value + 1;
  17. $value3 = $value + 2;
  18. $this->assertTimeRange(
  19. $this->varJson(
  20. $connect
  21. ->table('test_query')
  22. ->whereYear('create_date', 2018)
  23. ->findOne(true)
  24. ),
  25. sprintf($sql, $value),
  26. sprintf($sql, $value2),
  27. sprintf($sql, $value3)
  28. );
  29. }

time().where.endTime 时间查询,等价于 whereDate

  1. public function testTime(): void
  2. {
  3. $connect = $this->createDatabaseConnectMock();
  4. $sql = <<<'eot'
  5. [
  6. "SELECT `test_query`.* FROM `test_query` WHERE `test_query`.`create_date` = :test_query_create_date LIMIT 1",
  7. {
  8. "test_query_create_date": [
  9. %d
  10. ]
  11. },
  12. false
  13. ]
  14. eot;
  15. $value = strtotime('+5 month');
  16. $value2 = $value + 1;
  17. $value3 = $value + 2;
  18. $this->assertTimeRange(
  19. $this->varJson(
  20. $connect
  21. ->table('test_query')
  22. ->time()
  23. ->where('create_date', '+5 month')
  24. ->endTime()
  25. ->findOne(true)
  26. ),
  27. sprintf($sql, $value),
  28. sprintf($sql, $value2),
  29. sprintf($sql, $value3)
  30. );
  31. }

time(date).where.endTime 时间查询,等价于 whereDate

  1. public function testTimeDateIsDefault(): void
  2. {
  3. $connect = $this->createDatabaseConnectMock();
  4. $sql = <<<'eot'
  5. [
  6. "SELECT `test_query`.* FROM `test_query` WHERE `test_query`.`create_date` = :test_query_create_date LIMIT 1",
  7. {
  8. "test_query_create_date": [
  9. %d
  10. ]
  11. },
  12. false
  13. ]
  14. eot;
  15. $value = strtotime('+5 month');
  16. $value2 = $value + 1;
  17. $value3 = $value + 2;
  18. $this->assertTimeRange(
  19. $this->varJson(
  20. $connect
  21. ->table('test_query')
  22. ->time('date')
  23. ->where('create_date', '+5 month')
  24. ->endTime()
  25. ->findOne(true)
  26. ),
  27. sprintf($sql, $value),
  28. sprintf($sql, $value2),
  29. sprintf($sql, $value3)
  30. );
  31. }

time(day).where.endTime 时间查询,等价于 whereDay

  1. public function testTimeDay(): void
  2. {
  3. $connect = $this->createDatabaseConnectMock();
  4. $sql = <<<'eot'
  5. [
  6. "SELECT `test_query`.* FROM `test_query` WHERE `test_query`.`create_date` = :test_query_create_date LIMIT 1",
  7. {
  8. "test_query_create_date": [
  9. %d
  10. ]
  11. },
  12. false
  13. ]
  14. eot;
  15. $date = getdate();
  16. $value = mktime(0, 0, 0, $date['mon'], 5, $date['year']);
  17. $value2 = $value + 1;
  18. $value3 = $value + 2;
  19. $this->assertTimeRange(
  20. $this->varJson(
  21. $connect
  22. ->table('test_query')
  23. ->time('day')
  24. ->where('create_date', 5)
  25. ->endTime()
  26. ->findOne(true)
  27. ),
  28. sprintf($sql, $value),
  29. sprintf($sql, $value2),
  30. sprintf($sql, $value3)
  31. );
  32. }

time(month).where.endTime 时间查询,等价于 whereMonth

  1. public function testTimeMonth(): void
  2. {
  3. $connect = $this->createDatabaseConnectMock();
  4. $sql = <<<'eot'
  5. [
  6. "SELECT `test_query`.* FROM `test_query` WHERE `test_query`.`create_date` = :test_query_create_date LIMIT 1",
  7. {
  8. "test_query_create_date": [
  9. %d
  10. ]
  11. },
  12. false
  13. ]
  14. eot;
  15. $date = getdate();
  16. $value = mktime(0, 0, 0, 5, 1, $date['year']);
  17. $value2 = $value + 1;
  18. $value3 = $value + 2;
  19. $this->assertTimeRange(
  20. $this->varJson(
  21. $connect
  22. ->table('test_query')
  23. ->time('month')
  24. ->where('create_date', 5)
  25. ->endTime()
  26. ->findOne(true)
  27. ),
  28. sprintf($sql, $value),
  29. sprintf($sql, $value2),
  30. sprintf($sql, $value3)
  31. );
  32. }

time(year).where.endTime 时间查询,等价于 whereYear

  1. public function testTimeYear(): void
  2. {
  3. $connect = $this->createDatabaseConnectMock();
  4. $sql = <<<'eot'
  5. [
  6. "SELECT `test_query`.* FROM `test_query` WHERE `test_query`.`create_date` = :test_query_create_date LIMIT 1",
  7. {
  8. "test_query_create_date": [
  9. %d
  10. ]
  11. },
  12. false
  13. ]
  14. eot;
  15. $value = mktime(0, 0, 0, 1, 1, 2018);
  16. $value2 = $value + 1;
  17. $value3 = $value + 2;
  18. $this->assertTimeRange(
  19. $this->varJson(
  20. $connect
  21. ->table('test_query')
  22. ->time('year')
  23. ->where('create_date', 2018)
  24. ->endTime()
  25. ->findOne(true)
  26. ),
  27. sprintf($sql, $value),
  28. sprintf($sql, $value2),
  29. sprintf($sql, $value3)
  30. );
  31. }