From eb1adb0b922570999de6e6f5f67c51bf5b06d035 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Wed, 29 Dec 2021 18:34:48 +0000 Subject: [PATCH] Issue #3252257 by Spokje, beatrizrodrigues, longwave, paulocs, mondrake: Remove PHPUnit 8 support --- composer/Plugin/VendorHardening/Config.php | 1 - core/lib/Drupal/Core/Composer/Composer.php | 1 - core/lib/Drupal/Core/Test/TestDiscovery.php | 2 +- core/scripts/run-tests.sh | 2 +- .../{PhpUnit8 => }/ClassWriter.php | 2 +- .../PhpUnit8/TestCompatibilityTrait.php | 10 -- .../Drupal/Tests/ComposerIntegrationTest.php | 6 - .../Listeners/DeprecationListenerTrait.php | 4 +- .../Tests/Listeners/HtmlOutputPrinter.php | 16 +-- .../Drupal/Tests/PhpUnitWarningsTest.php | 103 ------------------ core/tests/bootstrap.php | 2 +- 11 files changed, 7 insertions(+), 142 deletions(-) rename core/tests/Drupal/TestTools/PhpUnitCompatibility/{PhpUnit8 => }/ClassWriter.php (98%) delete mode 100644 core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit8/TestCompatibilityTrait.php diff --git a/composer/Plugin/VendorHardening/Config.php b/composer/Plugin/VendorHardening/Config.php index 603cac634ff0..b1c79e6e23d3 100644 --- a/composer/Plugin/VendorHardening/Config.php +++ b/composer/Plugin/VendorHardening/Config.php @@ -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'], diff --git a/core/lib/Drupal/Core/Composer/Composer.php b/core/lib/Drupal/Core/Composer/Composer.php index b812636423dc..9719d6c40ebf 100644 --- a/core/lib/Drupal/Core/Composer/Composer.php +++ b/core/lib/Drupal/Core/Composer/Composer.php @@ -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'], diff --git a/core/lib/Drupal/Core/Test/TestDiscovery.php b/core/lib/Drupal/Core/Test/TestDiscovery.php index cf0ca32f2810..89287b550314 100644 --- a/core/lib/Drupal/Core/Test/TestDiscovery.php +++ b/core/lib/Drupal/Core/Test/TestDiscovery.php @@ -7,7 +7,7 @@ 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; /** diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh index 17ec49b9a484..d9728a02e995 100755 --- a/core/scripts/run-tests.sh +++ b/core/scripts/run-tests.sh @@ -18,7 +18,7 @@ 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; diff --git a/core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit8/ClassWriter.php b/core/tests/Drupal/TestTools/PhpUnitCompatibility/ClassWriter.php similarity index 98% rename from core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit8/ClassWriter.php rename to core/tests/Drupal/TestTools/PhpUnitCompatibility/ClassWriter.php index dffce1d86395..0362882d1a66 100644 --- a/core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit8/ClassWriter.php +++ b/core/tests/Drupal/TestTools/PhpUnitCompatibility/ClassWriter.php @@ -1,6 +1,6 @@ <?php -namespace Drupal\TestTools\PhpUnitCompatibility\PhpUnit8; +namespace Drupal\TestTools\PhpUnitCompatibility; use Composer\Autoload\ClassLoader; diff --git a/core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit8/TestCompatibilityTrait.php b/core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit8/TestCompatibilityTrait.php deleted file mode 100644 index 9beee7d0a198..000000000000 --- a/core/tests/Drupal/TestTools/PhpUnitCompatibility/PhpUnit8/TestCompatibilityTrait.php +++ /dev/null @@ -1,10 +0,0 @@ -<?php - -namespace Drupal\TestTools\PhpUnitCompatibility\PhpUnit8; - -/** - * Drupal's forward compatibility layer with multiple versions of PHPUnit. - */ -trait TestCompatibilityTrait { - -} diff --git a/core/tests/Drupal/Tests/ComposerIntegrationTest.php b/core/tests/Drupal/Tests/ComposerIntegrationTest.php index c50f782f7eb6..7bff93a5f297 100644 --- a/core/tests/Drupal/Tests/ComposerIntegrationTest.php +++ b/core/tests/Drupal/Tests/ComposerIntegrationTest.php @@ -5,7 +5,6 @@ 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 @@ public function testVendorCleanup($class, $property) { $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); } diff --git a/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php index 8a85f29b3189..475262cb8d75 100644 --- a/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php +++ b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php @@ -125,12 +125,10 @@ public static function getSkippedDeprecations() { // 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\".", ]; } diff --git a/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php b/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php index a85c32049972..69eae01fd167 100644 --- a/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php +++ b/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php @@ -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; diff --git a/core/tests/Drupal/Tests/PhpUnitWarningsTest.php b/core/tests/Drupal/Tests/PhpUnitWarningsTest.php index 7fa46ab06b96..2e635be472a9 100644 --- a/core/tests/Drupal/Tests/PhpUnitWarningsTest.php +++ b/core/tests/Drupal/Tests/PhpUnitWarningsTest.php @@ -2,8 +2,6 @@ namespace Drupal\Tests; -use Drupal\TestTools\PhpUnitCompatibility\RunnerVersion; - /** * @coversDefaultClass \Drupal\Tests\Traits\PhpUnitWarnings * @group legacy @@ -18,105 +16,4 @@ public function testAddWarning() { $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'); - } - } diff --git a/core/tests/bootstrap.php b/core/tests/bootstrap.php index 5f5b494cfcfd..40f2870dda2a 100644 --- a/core/tests/bootstrap.php +++ b/core/tests/bootstrap.php @@ -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. -- GitLab