DatabaseSuite.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. *
  7. * Licensed under The MIT License
  8. * For full copyright and license information, please see the LICENSE.txt
  9. * Redistributions of files must retain the above copyright notice.
  10. *
  11. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  12. * @link https://cakephp.org CakePHP(tm) Project
  13. * @since 3.0.0
  14. * @license https://opensource.org/licenses/mit-license.php MIT License
  15. */
  16. namespace Cake\Test\TestCase;
  17. use Cake\Datasource\ConnectionManager;
  18. use Cake\TestSuite\TestSuite;
  19. use PHPUnit\Framework\TestResult;
  20. /**
  21. * All tests related to database
  22. */
  23. class DatabaseSuite extends TestSuite
  24. {
  25. /**
  26. * Returns a suite containing all tests requiring a database connection,
  27. * tests are decorated so that they are run once with automatic
  28. *
  29. * @return static
  30. */
  31. public static function suite()
  32. {
  33. $suite = new static('Database related tests');
  34. $suite->addTestFile(__DIR__ . DS . 'Database' . DS . 'ConnectionTest.php');
  35. $suite->addTestDirectoryRecursive(__DIR__ . DS . 'Database');
  36. $suite->addTestDirectoryRecursive(__DIR__ . DS . 'ORM');
  37. return $suite;
  38. }
  39. /**
  40. * @param bool $preferCache
  41. * @return int
  42. */
  43. public function count($preferCache = false): int
  44. {
  45. return parent::count($preferCache) * 2;
  46. }
  47. /**
  48. * Runs the tests and collects their result in a TestResult.
  49. *
  50. * @param \PHPUnit\Framework\TestResult $result
  51. * @return \PHPUnit\Framework\TestResult
  52. */
  53. public function run(?TestResult $result = null): TestResult
  54. {
  55. $permutations = [
  56. 'Identifier Quoting' => function () {
  57. ConnectionManager::get('test')->getDriver()->enableAutoQuoting(true);
  58. },
  59. 'No identifier quoting' => function () {
  60. ConnectionManager::get('test')->getDriver()->enableAutoQuoting(false);
  61. },
  62. ];
  63. foreach ($permutations as $permutation) {
  64. $permutation();
  65. $result = parent::run($result);
  66. }
  67. return $result;
  68. }
  69. }