Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
......@@ -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"
}
}
......@@ -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.
......
......@@ -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()
/**
......
<?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
<?php
require 'vendor/autoload.php';
require 'tests/Drupal/PhpunitCompatibilityTestCase.php';
require 'tests/Drupal/CoderSniffUnitTest.php';
require 'vendor/squizlabs/php_codesniffer/autoload.php';
......@@ -2,13 +2,13 @@
namespace DrupalPractice\Test\ProjectDetection;
use Drupal\Test\PhpunitCompatibilityTestCase;
use DrupalPractice\Project;
use PHPUnit\Framework\TestCase;
/**
* Tests that project and version detection works.
*/
class ProjectUnitTest extends PhpunitCompatibilityTestCase
class ProjectUnitTest extends TestCase
{
/**
......@@ -24,13 +24,13 @@ class ProjectUnitTest extends PhpunitCompatibilityTestCase
*
* @return void
*/
protected function compatibleSetUp()
public function setUp(): void
{
$this->phpcsFile = $this->getMockBuilder('\PHP_CodeSniffer\Files\File')
->disableOriginalConstructor()
->getMock();
}//end compatibleSetUp()
}//end setUp()
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment