MedooTestCase.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. namespace Medoo\Tests;
  3. use Medoo\Medoo;
  4. use PHPUnit\Framework\TestCase;
  5. class MedooTestCase extends TestCase
  6. {
  7. protected $database;
  8. public function setUp(): void
  9. {
  10. $this->database = new Medoo([
  11. 'testMode' => true
  12. ]);
  13. }
  14. public function typesProvider(): array
  15. {
  16. return [
  17. 'MySQL' => ['mysql'],
  18. 'MSSQL' => ['mssql'],
  19. 'SQLite' => ['sqlite'],
  20. 'PostgreSQL' => ['pgsql'],
  21. 'Oracle' => ['oracle']
  22. ];
  23. }
  24. public function setType($type): void
  25. {
  26. $this->database->type = $type;
  27. }
  28. public function expectedQuery($expected): string
  29. {
  30. $identifier = [
  31. 'mysql' => '`$1`',
  32. 'mssql' => '[$1]'
  33. ];
  34. return preg_replace(
  35. '/(?!\'[^\s]+\s?)"((?![_\d])[\p{N}\p{L}\-_]+)"(?!\s?[^\s]+\')/u',
  36. $identifier[$this->database->type] ?? '"$1"',
  37. str_replace("\n", " ", $expected)
  38. );
  39. }
  40. public function assertQuery($expected, $query): void
  41. {
  42. if (is_array($expected)) {
  43. $this->assertEquals(
  44. $this->expectedQuery($expected[$this->database->type] ?? $expected['default']),
  45. $query
  46. );
  47. } else {
  48. $this->assertEquals($this->expectedQuery($expected), $query);
  49. }
  50. }
  51. }
  52. class Foo
  53. {
  54. public $bar = "cat";
  55. public function __wakeup()
  56. {
  57. $this->bar = "dog";
  58. }
  59. }