查询语言.havingDate

Testing Is Documentation

tests/Database/Query/HavingTimeTest.php查询语言.havingDate - 图1

Uses

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

havingDate 时间查询

  1. public function testBaseUse(): void
  2. {
  3. $connect = $this->createDatabaseConnectMock();
  4. $sql = <<<'eot'
  5. [
  6. "SELECT `test_query`.* FROM `test_query` GROUP BY `test_query`.`create_date` HAVING `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. ->groupBy('create_date')
  23. ->havingDate('create_date', '+5 month')
  24. ->findOne(true)
  25. ),
  26. sprintf($sql, $value),
  27. sprintf($sql, $value2),
  28. sprintf($sql, $value3)
  29. );
  30. }

havingDay 时间查询

  1. public function testHavingDay(): void
  2. {
  3. $connect = $this->createDatabaseConnectMock();
  4. $sql = <<<'eot'
  5. [
  6. "SELECT `test_query`.* FROM `test_query` GROUP BY `test_query`.`create_date` HAVING `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. ->groupBy('create_date')
  24. ->havingDay('create_date', 5)
  25. ->findOne(true)
  26. ),
  27. sprintf($sql, $value),
  28. sprintf($sql, $value2),
  29. sprintf($sql, $value3)
  30. );
  31. }

havingMonth 时间查询

  1. public function testHavingMonth(): void
  2. {
  3. $connect = $this->createDatabaseConnectMock();
  4. $sql = <<<'eot'
  5. [
  6. "SELECT `test_query`.* FROM `test_query` GROUP BY `test_query`.`create_date` HAVING `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. ->groupBy('create_date')
  24. ->havingMonth('create_date', 5)
  25. ->findOne(true)
  26. ),
  27. sprintf($sql, $value),
  28. sprintf($sql, $value2),
  29. sprintf($sql, $value3)
  30. );
  31. }

havingYear 时间查询

  1. public function testHavingYear(): void
  2. {
  3. $connect = $this->createDatabaseConnectMock();
  4. $sql = <<<'eot'
  5. [
  6. "SELECT `test_query`.* FROM `test_query` GROUP BY `test_query`.`create_date` HAVING `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. ->groupBy('create_date')
  23. ->havingYear('create_date', 2018)
  24. ->findOne(true)
  25. ),
  26. sprintf($sql, $value),
  27. sprintf($sql, $value2),
  28. sprintf($sql, $value3)
  29. );
  30. }

time().having.endTime 时间查询,等价于 havingDate

  1. public function testTime(): void
  2. {
  3. $connect = $this->createDatabaseConnectMock();
  4. $sql = <<<'eot'
  5. [
  6. "SELECT `test_query`.* FROM `test_query` GROUP BY `test_query`.`create_date` HAVING `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->assertTrue(
  19. in_array(
  20. $this->varJson(
  21. $connect
  22. ->table('test_query')
  23. ->groupBy('create_date')
  24. ->time()
  25. ->having('create_date', '+5 month')
  26. ->endTime()
  27. ->findOne(true)
  28. ),
  29. [
  30. sprintf($sql, $value),
  31. sprintf($sql, $value2),
  32. sprintf($sql, $value3),
  33. ],
  34. true
  35. )
  36. );
  37. }

time(date).having.endTime 时间查询,等价于 havingDate

  1. public function testTimeDateIsDefault(): void
  2. {
  3. $connect = $this->createDatabaseConnectMock();
  4. $sql = <<<'eot'
  5. [
  6. "SELECT `test_query`.* FROM `test_query` GROUP BY `test_query`.`create_date` HAVING `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->assertTrue(
  19. in_array(
  20. $this->varJson(
  21. $connect
  22. ->table('test_query')
  23. ->groupBy('create_date')
  24. ->time('date')
  25. ->having('create_date', '+5 month')
  26. ->endTime()
  27. ->findOne(true)
  28. ),
  29. [
  30. sprintf($sql, $value),
  31. sprintf($sql, $value2),
  32. sprintf($sql, $value3),
  33. ],
  34. true
  35. )
  36. );
  37. }

time(day).having.endTime 时间查询,等价于 havingDay

  1. public function testTimeDay(): void
  2. {
  3. $connect = $this->createDatabaseConnectMock();
  4. $sql = <<<'eot'
  5. [
  6. "SELECT `test_query`.* FROM `test_query` GROUP BY `test_query`.`create_date` HAVING `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. ->groupBy('create_date')
  24. ->time('day')
  25. ->having('create_date', 5)
  26. ->endTime()
  27. ->findOne(true)
  28. ),
  29. sprintf($sql, $value),
  30. sprintf($sql, $value2),
  31. sprintf($sql, $value3)
  32. );
  33. }

time(month).having.endTime 时间查询,等价于 havingMonth

  1. public function testTimeMonth(): void
  2. {
  3. $connect = $this->createDatabaseConnectMock();
  4. $sql = <<<'eot'
  5. [
  6. "SELECT `test_query`.* FROM `test_query` GROUP BY `test_query`.`create_date` HAVING `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. ->groupBy('create_date')
  24. ->time('month')
  25. ->having('create_date', 5)
  26. ->endTime()
  27. ->findOne(true)
  28. ),
  29. sprintf($sql, $value),
  30. sprintf($sql, $value2),
  31. sprintf($sql, $value3)
  32. );
  33. }

time(year).having.endTime 时间查询,等价于 havingYear

  1. public function testTimeYear(): void
  2. {
  3. $connect = $this->createDatabaseConnectMock();
  4. $sql = <<<'eot'
  5. [
  6. "SELECT `test_query`.* FROM `test_query` GROUP BY `test_query`.`create_date` HAVING `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. ->groupBy('create_date')
  23. ->time('year')
  24. ->having('create_date', 2018)
  25. ->endTime()
  26. ->findOne(true)
  27. ),
  28. sprintf($sql, $value),
  29. sprintf($sql, $value2),
  30. sprintf($sql, $value3)
  31. );
  32. }