DatabaseSuite.php 2.2 KB

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