Issue #3252257 by Spokje, beatrizrodrigues, longwave, paulocs, mondrake: Remove PHPUnit 8 support

merge-requests/1222/head
Alex Pott 2021-12-29 18:34:48 +00:00
parent 934f42ae87
commit eb1adb0b92
No known key found for this signature in database
GPG Key ID: BDA67E7EE836E5CE
11 changed files with 7 additions and 142 deletions

View File

@ -48,7 +48,6 @@ class Config {
'phpspec/prophecy' => ['fixtures', 'spec', 'tests'],
'phpunit/php-code-coverage' => ['tests'],
'phpunit/php-timer' => ['tests'],
'phpunit/php-token-stream' => ['tests'],
'phpunit/phpunit' => ['tests'],
'sebastian/code-unit-reverse-lookup' => ['tests'],
'sebastian/comparator' => ['tests'],

View File

@ -44,7 +44,6 @@ class Composer {
'phpspec/prophecy' => ['fixtures', 'spec', 'tests'],
'phpunit/php-code-coverage' => ['tests'],
'phpunit/php-timer' => ['tests'],
'phpunit/php-token-stream' => ['tests'],
'phpunit/phpunit' => ['tests'],
'sebastian/code-unit-reverse-lookup' => ['tests'],
'sebastian/comparator' => ['tests'],

View File

@ -7,7 +7,7 @@ use Drupal\Component\Annotation\Reflection\MockFileFinder;
use Drupal\Component\Utility\NestedArray;
use Drupal\Core\Extension\ExtensionDiscovery;
use Drupal\Core\Test\Exception\MissingGroupException;
use Drupal\TestTools\PhpUnitCompatibility\PhpUnit8\ClassWriter;
use Drupal\TestTools\PhpUnitCompatibility\ClassWriter;
use PHPUnit\Util\Test;
/**

View File

@ -18,7 +18,7 @@ use Drupal\Core\Test\RunTests\TestFileParser;
use Drupal\Core\Test\TestDatabase;
use Drupal\Core\Test\TestRunnerKernel;
use Drupal\Core\Test\TestDiscovery;
use Drupal\TestTools\PhpUnitCompatibility\PhpUnit8\ClassWriter;
use Drupal\TestTools\PhpUnitCompatibility\ClassWriter;
use PHPUnit\Framework\TestCase;
use PHPUnit\Runner\Version;
use Symfony\Component\Console\Output\ConsoleOutput;

View File

@ -1,6 +1,6 @@
<?php
namespace Drupal\TestTools\PhpUnitCompatibility\PhpUnit8;
namespace Drupal\TestTools\PhpUnitCompatibility;
use Composer\Autoload\ClassLoader;

View File

@ -1,10 +0,0 @@
<?php
namespace Drupal\TestTools\PhpUnitCompatibility\PhpUnit8;
/**
* Drupal's forward compatibility layer with multiple versions of PHPUnit.
*/
trait TestCompatibilityTrait {
}

View File

@ -5,7 +5,6 @@ namespace Drupal\Tests;
use Drupal\Composer\Plugin\VendorHardening\Config;
use Drupal\Core\Composer\Composer;
use Drupal\Tests\Composer\ComposerIntegrationTrait;
use Drupal\TestTools\PhpUnitCompatibility\RunnerVersion;
use Symfony\Component\Yaml\Yaml;
/**
@ -266,11 +265,6 @@ class ComposerIntegrationTest extends UnitTestCase {
$reflection = new \ReflectionProperty($class, $property);
$reflection->setAccessible(TRUE);
$config = $reflection->getValue();
// PHPUnit 9.5.3 removes 'phpunit/php-token-stream' from its dependencies.
// @todo remove the check below when PHPUnit 9 is the minimum.
if (RunnerVersion::getMajor() >= 9) {
unset($config['phpunit/php-token-stream']);
}
foreach (array_keys($config) as $package) {
$this->assertContains(strtolower($package), $packages);
}

View File

@ -125,12 +125,10 @@ trait DeprecationListenerTrait {
// testing using \Symfony\Component\ErrorHandler\DebugClassLoader.
'The "Twig\Environment::getTemplateClass()" method is considered internal. It may change without further notice. You should not extend it from "Drupal\Core\Template\TwigEnvironment".',
'"Symfony\Component\DomCrawler\Crawler::text()" will normalize whitespaces by default in Symfony 5.0, set the second "$normalizeWhitespace" argument to false to retrieve the non-normalized version of the text.',
// PHPUnit 8.
"The \"PHPUnit\TextUI\ResultPrinter\" class is considered internal This class is not covered by the backward compatibility promise for PHPUnit. It may change without further notice. You should not use it from \"Drupal\Tests\Listeners\HtmlOutputPrinter\".",
// PHPUnit 9.
"The \"Drupal\Tests\Listeners\DrupalListener\" class implements \"PHPUnit\Framework\TestListener\" that is deprecated Use the `TestHook` interfaces instead.",
"The \"Drupal\Tests\Listeners\DrupalListener\" class uses \"PHPUnit\Framework\TestListenerDefaultImplementation\" that is deprecated The `TestListener` interface is deprecated.",
"The \"PHPUnit\Framework\TestSuite\" class is considered internal This class is not covered by the backward compatibility promise for PHPUnit. It may change without further notice. You should not use it from \"Drupal\Tests\TestSuites\TestSuiteBase\".",
// PHPUnit 9.
"The \"PHPUnit\TextUI\DefaultResultPrinter\" class is considered internal This class is not covered by the backward compatibility promise for PHPUnit. It may change without further notice. You should not use it from \"Drupal\Tests\Listeners\HtmlOutputPrinter\".",
];
}

View File

@ -2,27 +2,15 @@
namespace Drupal\Tests\Listeners;
use Drupal\TestTools\PhpUnitCompatibility\RunnerVersion;
use PHPUnit\Framework\TestResult;
// In order to manage different implementations across PHPUnit versions, we
// dynamically load the base ResultPrinter class dependent on the PHPUnit runner
// version.
if (!class_exists(ResultPrinterBase::class, FALSE)) {
if (RunnerVersion::getMajor() < 9) {
class_alias('PHPUnit\TextUI\ResultPrinter', ResultPrinterBase::class);
}
else {
class_alias('PHPUnit\TextUI\DefaultResultPrinter', ResultPrinterBase::class);
}
}
use PHPUnit\TextUI\DefaultResultPrinter;
/**
* Defines a class for providing html output results for functional tests.
*
* @internal
*/
class HtmlOutputPrinter extends ResultPrinterBase {
class HtmlOutputPrinter extends DefaultResultPrinter {
use HtmlOutputPrinterTrait;

View File

@ -2,8 +2,6 @@
namespace Drupal\Tests;
use Drupal\TestTools\PhpUnitCompatibility\RunnerVersion;
/**
* @coversDefaultClass \Drupal\Tests\Traits\PhpUnitWarnings
* @group legacy
@ -18,105 +16,4 @@ class PhpUnitWarningsTest extends UnitTestCase {
$this->addWarning('Test warning for \Drupal\Tests\PhpUnitWarningsTest::testAddWarning()');
}
/**
* Tests assertContains.
*/
public function testAssertContains() {
if (RunnerVersion::getMajor() > 8) {
$this->markTestSkipped("In PHPUnit 9+, argument 2 passed to PHPUnit\Framework\Assert::assertContains() must be iterable.");
}
$this->expectDeprecation('Using assertContains() with string haystacks is deprecated and will not be supported in PHPUnit 9. Refactor your test to use assertStringContainsString() or assertStringContainsStringIgnoringCase() instead.');
$this->expectDeprecation('The optional $ignoreCase parameter of assertContains() is deprecated and will be removed in PHPUnit 9.');
$this->assertContains('string', 'aaaa_string_aaa');
$this->assertContains('STRING', 'aaaa_string_aaa', '', TRUE);
}
/**
* Tests assertNotContains.
*/
public function testAssertNotContains() {
if (RunnerVersion::getMajor() > 8) {
$this->markTestSkipped("In PHPUnit 9+, argument 2 passed to PHPUnit\Framework\Assert::assertNotContains() must be iterable.");
}
$this->expectDeprecation('Using assertNotContains() with string haystacks is deprecated and will not be supported in PHPUnit 9. Refactor your test to use assertStringNotContainsString() or assertStringNotContainsStringIgnoringCase() instead.');
$this->expectDeprecation('The optional $ignoreCase parameter of assertNotContains() is deprecated and will be removed in PHPUnit 9.');
$this->assertNotContains('foo', 'bar');
$this->assertNotContains('FOO', 'bar', '', TRUE);
}
/**
* Tests assertArraySubset.
*/
public function testAssertArraySubset() {
if (RunnerVersion::getMajor() > 8) {
$this->markTestSkipped("In PHPUnit 9+, assertArraySubset() is removed.");
}
$this->expectDeprecation('assertArraySubset() is deprecated and will be removed in PHPUnit 9.');
$this->assertArraySubset(['a'], ['a', 'b']);
}
/**
* Tests assertInternalType.
*/
public function testAssertInternalType() {
if (RunnerVersion::getMajor() > 8) {
$this->markTestSkipped("In PHPUnit 9+, assertInternalType() is removed.");
}
$this->expectDeprecation('assertInternalType() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertIsString() instead.');
$this->assertInternalType('string', 'string');
}
/**
* Tests assertion methods accessing class attributes.
*/
public function testAssertAttribute() {
if (RunnerVersion::getMajor() > 8) {
$this->markTestSkipped("In PHPUnit 9+, assertion methods accessing class attributes are removed.");
}
$this->expectDeprecation('assertAttributeEquals() is deprecated and will be removed in PHPUnit 9.');
$this->expectDeprecation('readAttribute() is deprecated and will be removed in PHPUnit 9.');
$this->expectDeprecation('getObjectAttribute() is deprecated and will be removed in PHPUnit 9.');
$this->expectDeprecation('assertAttributeSame() is deprecated and will be removed in PHPUnit 9.');
$this->expectDeprecation('assertAttributeInstanceOf() is deprecated and will be removed in PHPUnit 9.');
$this->expectDeprecation('assertAttributeEmpty() is deprecated and will be removed in PHPUnit 9.');
$obj = new class() {
protected $attribute = 'value';
protected $class;
protected $empty;
public function __construct() {
$this->class = new \stdClass();
}
};
$this->assertAttributeEquals('value', 'attribute', $obj);
$this->assertAttributeSame('value', 'attribute', $obj);
$this->assertAttributeInstanceOf(\stdClass::class, 'class', $obj);
$this->assertAttributeEmpty('empty', $obj);
}
/**
* Tests assertEquals.
*/
public function testAssertEquals() {
if (RunnerVersion::getMajor() > 8) {
$this->markTestSkipped("In PHPUnit 9+, the \$canonicalize parameter of assertEquals() is removed.");
}
$this->expectDeprecation('The optional $canonicalize parameter of assertEquals() is deprecated and will be removed in PHPUnit 9. Refactor your test to use assertEqualsCanonicalizing() instead.');
$this->assertEquals(['a', 'b'], ['b', 'a'], '', 0.0, 10, TRUE);
}
/**
* Tests expectExceptionMessageRegExp.
*/
public function testExpectExceptionMessageRegExp() {
if (RunnerVersion::getMajor() > 8) {
$this->markTestSkipped("In PHPUnit 9+, expectExceptionMessageRegExp() is removed.");
}
$this->expectDeprecation('expectExceptionMessageRegExp() is deprecated in PHPUnit 8 and will be removed in PHPUnit 9. Use expectExceptionMessageMatches() instead.');
$this->expectException(\Exception::class);
$this->expectExceptionMessageRegExp('/An exception .*/');
throw new \Exception('An exception has been triggered');
}
}

View File

@ -8,7 +8,7 @@
*/
use Drupal\Component\Assertion\Handle;
use Drupal\TestTools\PhpUnitCompatibility\PhpUnit8\ClassWriter;
use Drupal\TestTools\PhpUnitCompatibility\ClassWriter;
/**
* Finds all valid extension directories recursively within a given directory.