UpdateTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace Test\Michel\SqlMapper;
  3. use Michel\SqlMapper\Update;
  4. use Michel\UniTester\TestCase;
  5. class UpdateTest extends TestCase
  6. {
  7. protected function execute(): void
  8. {
  9. $this->testNoTable();
  10. $this->testToString();
  11. $this->testWhereWithoutColumns();
  12. $this->testSet();
  13. }
  14. public function testNoTable()
  15. {
  16. $update = new Update('my_table', 't');
  17. $this->expectException(\LogicException::class, function () use ($update) {
  18. $update->__toString();
  19. });
  20. }
  21. public function testToString()
  22. {
  23. $update = new Update('my_table');
  24. $update->set('column1', 'value1')->set('column2', 'value2')->where('condition1');
  25. $this->assertEquals('UPDATE my_table SET column1 = value1, column2 = value2 WHERE condition1', (string)$update);
  26. }
  27. public function testWhereWithoutColumns()
  28. {
  29. $update = new Update('my_table');
  30. $update->where('condition1', 'condition2');
  31. $this->expectException(\LogicException::class, function () use ($update) {
  32. $update->__toString();
  33. });
  34. }
  35. public function testSet()
  36. {
  37. $update = new Update('my_table');
  38. $update->set('column1', 'value1')->set('column2', 'value2');
  39. $this->assertEquals('UPDATE my_table SET column1 = value1, column2 = value2', (string)$update);
  40. }
  41. protected function setUp(): void
  42. {
  43. // TODO: Implement setUp() method.
  44. }
  45. protected function tearDown(): void
  46. {
  47. // TODO: Implement tearDown() method.
  48. }
  49. }