RawTest.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. namespace Medoo\Tests;
  3. use Medoo\Medoo;
  4. /**
  5. * @coversDefaultClass \Medoo\Medoo
  6. */
  7. class RawTest extends MedooTestCase
  8. {
  9. /**
  10. * @covers ::raw()
  11. * @covers ::isRaw()
  12. * @covers ::buildRaw()
  13. * @dataProvider typesProvider
  14. */
  15. public function testRawWithPlaceholder($type)
  16. {
  17. $this->setType($type);
  18. $this->database->select('account', [
  19. 'score' => Medoo::raw('SUM(<age> + <experience>)')
  20. ]);
  21. $this->assertQuery(
  22. <<<EOD
  23. SELECT SUM("age" + "experience") AS "score"
  24. FROM "account"
  25. EOD,
  26. $this->database->queryString
  27. );
  28. }
  29. /**
  30. * @covers ::raw()
  31. * @covers ::isRaw()
  32. * @covers ::buildRaw()
  33. * @dataProvider typesProvider
  34. */
  35. public function testRawWithSamePlaceholderName($type)
  36. {
  37. $this->setType($type);
  38. $this->database->select('account', [
  39. 'system' => Medoo::raw("COUNT(<system> = 'window' OR <system> = 'mac')")
  40. ]);
  41. $this->assertQuery(
  42. <<<EOD
  43. SELECT COUNT("system" = 'window' OR "system" = 'mac') AS "system"
  44. FROM "account"
  45. EOD,
  46. $this->database->queryString
  47. );
  48. }
  49. }