Unverified Commit 5f3b3c01 authored by Klaus Purer's avatar Klaus Purer Committed by GitHub
Browse files

test(phpunit): Remove PHP 7.0 compatibility layer (#156)

parent 260ed687
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@
        "sort-packages": true
    },
    "require-dev": {
        "phpunit/phpunit": "^6.0 || ^7.0 || ^8.0",
        "phpunit/phpunit": "^7.0 || ^8.0",
        "phpstan/phpstan": "^1.2.0"
    }
}
+0 −2
Original line number Diff line number Diff line
@@ -10,8 +10,6 @@ parameters:
        - 'tests/*/good.php'
        - 'tests/*/bad.php'
        - 'tests/*/drupal[678]/*.php'
        # Compatibilty layer class for PHPUnit that should not be checked.
        - 'tests/Drupal/PhpunitCompatibilityTestCase.php'
    bootstrapFiles:
        - tests/Drupal/phpunit-bootstrap.php
        # PHPStan does not find the constants in this file, so load it manually.
+4 −3
Original line number Diff line number Diff line
@@ -19,8 +19,9 @@ use PHP_CodeSniffer\Files\LocalFile;
use PHP_CodeSniffer\Exceptions\RuntimeException;
use PHP_CodeSniffer\Util\Common;
use PHP_CodeSniffer\Util\Tokens;
use PHPUnit\Framework\TestCase;

abstract class CoderSniffUnitTest extends PhpunitCompatibilityTestCase
abstract class CoderSniffUnitTest extends TestCase
{

    /**
@@ -59,7 +60,7 @@ abstract class CoderSniffUnitTest extends PhpunitCompatibilityTestCase
     *
     * @return void
     */
    protected function compatibleSetUp()
    public function setUp(): void
    {
        $class = get_class($this);

@@ -75,7 +76,7 @@ abstract class CoderSniffUnitTest extends PhpunitCompatibilityTestCase
            define('PHP_CODESNIFFER_CBF', 0);
        }

    }//end compatibleSetUp()
    }//end setUp()


    /**
+0 −76
Original line number Diff line number Diff line
<?php
/**
 * Helper class to be compatible with different PHPUnit major versions.
 *
 * We want to support PHP 7.0 which does not have the "void" return type hint.
 * For PHP 8 we need a higher PHPUnit version that enforces the type hint. Our
 * solution is to define a compatibility class depending on PHP version. It
 * routes around the setup method with a compatibleSetUp() method that child
 * classes use.
 */

namespace Drupal\Test;

use PHPUnit\Framework\TestCase;

if (version_compare(PHP_VERSION, '7.1.0') >= 0) {
    class PhpunitCompatibilityTestCase extends TestCase
    {


        /**
         * {@inheritdoc}
         *
         * @return void
         */
        protected function setUp(): void
        {
            $this->compatibleSetUp();

        }//end setUp()


        /**
         * Helper method that is used in place of ::setUp().
         *
         * @return void
         */
        protected function compatibleSetUp()
        {

        }//end compatibleSetUp()


    }//end class

} else {
    class PhpunitCompatibilityTestCase extends TestCase
    {


        /**
         * {@inheritdoc}
         *
         * @return void
         */
        protected function setUp()
        {
            $this->compatibleSetUp();

        }//end setUp()


        /**
         * Helper method that is used in place of ::setUp().
         *
         * @return void
         */
        protected function compatibleSetUp()
        {

        }//end compatibleSetUp()


    }//end class

}//end if
+0 −1
Original line number Diff line number Diff line
<?php

require 'vendor/autoload.php';
require 'tests/Drupal/PhpunitCompatibilityTestCase.php';
require 'tests/Drupal/CoderSniffUnitTest.php';
require 'vendor/squizlabs/php_codesniffer/autoload.php';
Loading