AggregateTest.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <?php
  2. namespace Medoo\Tests;
  3. /**
  4. * @coversDefaultClass \Medoo\Medoo
  5. */
  6. class AggregateTest extends MedooTestCase
  7. {
  8. /**
  9. * @covers ::count()
  10. * @covers ::aggregate()
  11. * @covers ::selectContext()
  12. * @dataProvider typesProvider
  13. */
  14. public function testCount($type)
  15. {
  16. $this->setType($type);
  17. $this->database->count("account", [
  18. "gender" => "female"
  19. ]);
  20. $this->assertQuery(
  21. <<<EOD
  22. SELECT COUNT(*)
  23. FROM "account"
  24. WHERE "gender" = 'female'
  25. EOD,
  26. $this->database->queryString
  27. );
  28. }
  29. /**
  30. * @covers ::max()
  31. * @covers ::aggregate()
  32. * @covers ::selectContext()
  33. * @dataProvider typesProvider
  34. */
  35. public function testMax($type)
  36. {
  37. $this->setType($type);
  38. $this->database->max("account", "age");
  39. $this->assertQuery(
  40. <<<EOD
  41. SELECT MAX("age")
  42. FROM "account"
  43. EOD,
  44. $this->database->queryString
  45. );
  46. }
  47. /**
  48. * @covers ::min()
  49. * @covers ::aggregate()
  50. * @covers ::selectContext()
  51. * @dataProvider typesProvider
  52. */
  53. public function testMin($type)
  54. {
  55. $this->setType($type);
  56. $this->database->min("account", "age");
  57. $this->assertQuery(
  58. <<<EOD
  59. SELECT MIN("age")
  60. FROM "account"
  61. EOD,
  62. $this->database->queryString
  63. );
  64. }
  65. /**
  66. * @covers ::avg()
  67. * @covers ::aggregate()
  68. * @covers ::selectContext()
  69. * @dataProvider typesProvider
  70. */
  71. public function testAvg($type)
  72. {
  73. $this->setType($type);
  74. $this->database->avg("account", "age");
  75. $this->assertQuery(
  76. <<<EOD
  77. SELECT AVG("age")
  78. FROM "account"
  79. EOD,
  80. $this->database->queryString
  81. );
  82. }
  83. /**
  84. * @covers ::sum()
  85. * @covers ::aggregate()
  86. * @covers ::selectContext()
  87. * @dataProvider typesProvider
  88. */
  89. public function testSum($type)
  90. {
  91. $this->setType($type);
  92. $this->database->sum("account", "money");
  93. $this->assertQuery(
  94. <<<EOD
  95. SELECT SUM("money")
  96. FROM "account"
  97. EOD,
  98. $this->database->queryString
  99. );
  100. }
  101. }