UpdateTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace Medoo\Tests;
  3. use Medoo\Medoo;
  4. /**
  5. * @coversDefaultClass \Medoo\Medoo
  6. */
  7. class UpdateTest extends MedooTestCase
  8. {
  9. /**
  10. * @covers \Medoo\Medoo::update()
  11. * @dataProvider typesProvider
  12. */
  13. public function testUpdate($type)
  14. {
  15. $this->setType($type);
  16. $objectData = new Foo();
  17. $this->database->update("account", [
  18. "type" => "user",
  19. "age[+]" => 1,
  20. "level[-]" => 5,
  21. "score[*]" => 2,
  22. "lang" => ["en", "fr"],
  23. "lang [JSON]" => ["en", "fr"],
  24. "is_locked" => true,
  25. "uuid" => Medoo::raw("UUID()"),
  26. "object" => $objectData
  27. ], [
  28. "user_id[<]" => 1000
  29. ]);
  30. $this->assertQuery([
  31. 'default' => <<<EOD
  32. UPDATE "account"
  33. SET "type" = 'user',
  34. "age" = "age" + 1,
  35. "level" = "level" - 5,
  36. "score" = "score" * 2,
  37. "lang" = 'a:2:{i:0;s:2:"en";i:1;s:2:"fr";}',
  38. "lang" = '["en","fr"]',
  39. "is_locked" = 1,
  40. "uuid" = UUID(),
  41. "object" = :MeD7_mK
  42. WHERE "user_id" < 1000
  43. EOD,
  44. 'mysql' => <<<EOD
  45. UPDATE "account"
  46. SET "type" = 'user',
  47. "age" = "age" + 1,
  48. "level" = "level" - 5,
  49. "score" = "score" * 2,
  50. "lang" = 'a:2:{i:0;s:2:\"en\";i:1;s:2:\"fr\";}',
  51. "lang" = '[\"en\",\"fr\"]',
  52. "is_locked" = 1,
  53. "uuid" = UUID(),
  54. "object" = :MeD7_mK
  55. WHERE "user_id" < 1000
  56. EOD,
  57. ], $this->database->queryString);
  58. }
  59. }