UpdateTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. "money" => 23.2,
  20. "age[+]" => 1,
  21. "level[-]" => 5,
  22. "score[*]" => 2,
  23. "lang" => ["en", "fr"],
  24. "lang [JSON]" => ["en", "fr"],
  25. "is_locked" => true,
  26. "uuid" => Medoo::raw("UUID()"),
  27. "object" => $objectData
  28. ], [
  29. "user_id[<]" => 1000
  30. ]);
  31. $this->assertQuery([
  32. 'default' => <<<EOD
  33. UPDATE "account"
  34. SET "type" = 'user',
  35. "money" = '23.2',
  36. "age" = "age" + 1,
  37. "level" = "level" - 5,
  38. "score" = "score" * 2,
  39. "lang" = 'a:2:{i:0;s:2:"en";i:1;s:2:"fr";}',
  40. "lang" = '["en","fr"]',
  41. "is_locked" = 1,
  42. "uuid" = UUID(),
  43. "object" = :MeD5_mK
  44. WHERE "user_id" < 1000
  45. EOD,
  46. 'mysql' => <<<EOD
  47. UPDATE "account"
  48. SET "type" = 'user',
  49. "money" = '23.2',
  50. "age" = "age" + 1,
  51. "level" = "level" - 5,
  52. "score" = "score" * 2,
  53. "lang" = 'a:2:{i:0;s:2:\"en\";i:1;s:2:\"fr\";}',
  54. "lang" = '[\"en\",\"fr\"]',
  55. "is_locked" = 1,
  56. "uuid" = UUID(),
  57. "object" = :MeD5_mK
  58. WHERE "user_id" < 1000
  59. EOD,
  60. ], $this->database->queryString);
  61. }
  62. public function testOracleLOBsUpdate()
  63. {
  64. $this->setType("oracle");
  65. $fp = fopen('README.md', 'r');
  66. $this->database->update("ACCOUNT", [
  67. "DATA" => $fp
  68. ], [
  69. "ID" => 1
  70. ]);
  71. $this->assertQuery(
  72. <<<EOD
  73. UPDATE "ACCOUNT"
  74. SET "DATA" = EMPTY_BLOB()
  75. WHERE "ID" = 1
  76. RETURNING "DATA" INTO :MeD0_mK
  77. EOD,
  78. $this->database->queryString
  79. );
  80. }
  81. }