2
0

ExprTest.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace Test\Michel\SqlMapper;
  3. use Michel\SqlMapper\Expression\Expr;
  4. use Michel\UniTester\TestCase;
  5. class ExprTest extends TestCase
  6. {
  7. protected function setUp(): void
  8. {
  9. // TODO: Implement setUp() method.
  10. }
  11. protected function tearDown(): void
  12. {
  13. // TODO: Implement tearDown() method.
  14. }
  15. protected function execute(): void
  16. {
  17. $this->testEqual();
  18. $this->testNotEqual();
  19. $this->testGreaterThan();
  20. $this->testGreaterThanEqual();
  21. $this->testLowerThan();
  22. $this->testLowerThanEqual();
  23. $this->testIsNull();
  24. $this->testIsNotNull();
  25. $this->testIn();
  26. $this->testNotIn();
  27. }
  28. public function testEqual()
  29. {
  30. $this->assertEquals('id = 1', Expr::equal('id', '1'));
  31. }
  32. public function testNotEqual()
  33. {
  34. $this->assertEquals('name <> John', Expr::notEqual('name', 'John'));
  35. }
  36. public function testGreaterThan()
  37. {
  38. $this->assertEquals('quantity > 10', Expr::greaterThan('quantity', '10'));
  39. }
  40. public function testGreaterThanEqual()
  41. {
  42. $this->assertEquals('price >= 100', Expr::greaterThanEqual('price', '100'));
  43. }
  44. public function testLowerThan()
  45. {
  46. $this->assertEquals('age < 30', Expr::lowerThan('age', '30'));
  47. }
  48. public function testLowerThanEqual()
  49. {
  50. $this->assertEquals('score <= 80', Expr::lowerThanEqual('score', '80'));
  51. }
  52. public function testIsNull()
  53. {
  54. $this->assertEquals('description IS NULL', Expr::isNull('description'));
  55. }
  56. public function testIsNotNull()
  57. {
  58. $this->assertEquals('status IS NOT NULL', Expr::isNotNull('status'));
  59. }
  60. public function testIn()
  61. {
  62. $this->assertEquals('category IN (1, 2, 3)', Expr::in('category', [1, 2, 3]));
  63. }
  64. public function testNotIn()
  65. {
  66. $this->assertEquals("color NOT IN ('red', 'blue')", Expr::notIn('color', ['red', 'blue']));
  67. }
  68. }