Browse Source

Replace DatabaseSuite with directory-based testsuite. Run database testsuite twice with auto-qouting.

Corey Taylor 4 years ago
parent
commit
e3c577cfa2
4 changed files with 12 additions and 74 deletions
  1. 6 1
      .github/workflows/ci.yml
  2. 2 1
      phpunit.xml.dist
  3. 0 72
      tests/TestCase/DatabaseSuite.php
  4. 4 0
      tests/bootstrap.php

+ 6 - 1
.github/workflows/ci.yml

@@ -120,9 +120,12 @@ jobs:
         if [[ ${{ matrix.db-type }} == 'pgsql' ]]; then export DB_URL='postgres://postgres:postgres@127.0.0.1/postgres'; fi
 
         if [[ ${{ matrix.php-version }} == '8.0' ]]; then
-          export CODECOVERAGE=1 && vendor/bin/phpunit --verbose --coverage-clover=coverage.xml
+          export CODECOVERAGE=1
+          vendor/bin/phpunit --verbose --coverage-clover=coverage.xml
+          CAKE_TEST_AUTOQUOTE=1 vendor/bin/phpunit --verbose --testsuite=database
         else
           vendor/bin/phpunit
+          CAKE_TEST_AUTOQUOTE=1 vendor/bin/phpunit --testsuite=database
         fi
 
     - name: Submit code coverage
@@ -192,6 +195,8 @@ jobs:
         DB_URL: 'sqlserver://@(localdb)\MSSQLLocalDB/cakephp'
       run: |
           vendor/bin/phpunit --verbose
+          set CAKE_TEST_AUTOQUOTE=1
+          vendor/bin/phpunit --verbose --testsuite=database
 
   cs-stan:
     name: Coding Standard & Static Analysis

+ 2 - 1
phpunit.xml.dist

@@ -13,7 +13,8 @@
             <exclude>tests/TestCase/ORM/</exclude>
         </testsuite>
         <testsuite name="database">
-            <file>tests/TestCase/DatabaseSuite.php</file>
+            <directory>tests/TestCase/Database/</directory>
+            <directory>tests/TestCase/ORM/</directory>
         </testsuite>
     </testsuites>
 

+ 0 - 72
tests/TestCase/DatabaseSuite.php

@@ -1,72 +0,0 @@
-<?php
-declare(strict_types=1);
-
-/**
- * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
- * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
- *
- * Licensed under The MIT License
- * For full copyright and license information, please see the LICENSE.txt
- * Redistributions of files must retain the above copyright notice.
- *
- * @copyright     Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
- * @link          https://cakephp.org CakePHP(tm) Project
- * @since         3.0.0
- * @license       https://opensource.org/licenses/mit-license.php MIT License
- */
-namespace Cake\Test\TestCase;
-
-use Cake\Datasource\ConnectionManager;
-use Cake\TestSuite\TestSuite;
-use PHPUnit\Framework\TestResult;
-
-/**
- * All tests related to database
- */
-class DatabaseSuite extends TestSuite
-{
-    /**
-     * Returns a suite containing all tests requiring a database connection,
-     * tests are decorated so that they are run once with automatic
-     *
-     * @return static
-     */
-    public static function suite()
-    {
-        $suite = new static('Database related tests');
-        $suite->addTestDirectoryRecursive(__DIR__ . DS . 'Database');
-        $suite->addTestDirectoryRecursive(__DIR__ . DS . 'ORM');
-
-        return $suite;
-    }
-
-    /**
-     * @param bool $preferCache
-     */
-    public function count($preferCache = false): int
-    {
-        return parent::count($preferCache) * 2;
-    }
-
-    /**
-     * Runs the tests and collects their result in a TestResult.
-     */
-    public function run(?TestResult $result = null): TestResult
-    {
-        $permutations = [
-            'Identifier Quoting' => function (): void {
-                ConnectionManager::get('test')->getDriver()->enableAutoQuoting(true);
-            },
-            'No identifier quoting' => function (): void {
-                ConnectionManager::get('test')->getDriver()->enableAutoQuoting(false);
-            },
-        ];
-
-        foreach ($permutations as $permutation) {
-            $permutation();
-            $result = parent::run($result);
-        }
-
-        return $result;
-    }
-}

+ 4 - 0
tests/bootstrap.php

@@ -104,6 +104,10 @@ if (!getenv('DB_URL')) {
 
 ConnectionManager::setConfig('test', ['url' => getenv('DB_URL')]);
 
+if (env('CAKE_TEST_AUTOQUOTE')) {
+    ConnectionManager::get('test')->getDriver()->enableAutoQuoting(true);
+}
+
 Configure::write('Session', [
     'defaults' => 'php',
 ]);