ReplaceTest.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace Medoo\Tests;
  3. use InvalidArgumentException;
  4. /**
  5. * @coversDefaultClass \Medoo\Medoo
  6. */
  7. class ReplaceTest extends MedooTestCase
  8. {
  9. /**
  10. * @covers ::replace()
  11. * @dataProvider typesProvider
  12. */
  13. public function testReplace($type)
  14. {
  15. $this->setType($type);
  16. $this->database->replace("account", [
  17. "type" => [
  18. "user" => "new_user",
  19. "business" => "new_business"
  20. ],
  21. "column" => [
  22. "old_value" => "new_value"
  23. ]
  24. ], [
  25. "user_id[>]" => 1000
  26. ]);
  27. $this->assertQuery(
  28. <<<EOD
  29. UPDATE "account"
  30. SET "type" = REPLACE("type", 'user', 'new_user'),
  31. "type" = REPLACE("type", 'business', 'new_business'),
  32. "column" = REPLACE("column", 'old_value', 'new_value')
  33. WHERE "user_id" > 1000
  34. EOD,
  35. $this->database->queryString
  36. );
  37. }
  38. /**
  39. * @covers ::replace()
  40. */
  41. public function testReplaceEmptyColumns()
  42. {
  43. $this->expectException(InvalidArgumentException::class);
  44. $this->database->replace("account", [], [
  45. "user_id[>]" => 1000
  46. ]);
  47. }
  48. }