diff --git a/composer.json b/composer.json index 338e28bc..87349790 100644 --- a/composer.json +++ b/composer.json @@ -21,10 +21,10 @@ "composer/composer": "^1.9.1", "drupal/coder": "^8.3.7", "mikey179/vfsstream": "^1.6.8", - "phpunit/phpunit": "^8.4.1", + "phpunit/phpunit": "^8.4.1 || ^9", "phpspec/prophecy": "^1.7", "symfony/css-selector": "^4.4", - "symfony/phpunit-bridge": "^4.4", + "symfony/phpunit-bridge": "^4.4.8", "symfony/error-handler": "^4.4", "justinrainbow/json-schema": "^5.2", "symfony/filesystem": "^4.4", diff --git a/composer/Metapackage/DevDependencies/composer.json b/composer/Metapackage/DevDependencies/composer.json index ceb0cffc..5af2af70 100644 --- a/composer/Metapackage/DevDependencies/composer.json +++ b/composer/Metapackage/DevDependencies/composer.json @@ -16,7 +16,7 @@ "justinrainbow/json-schema": "^5.2", "mikey179/vfsstream": "^1.6.8", "phpspec/prophecy": "^1.7", - "phpunit/phpunit": "^8.4.1", + "phpunit/phpunit": "^8.4.1 || ^9", "symfony/browser-kit": "^4.4", "symfony/css-selector": "^4.4", "symfony/dom-crawler": "^4.4 !=4.4.5", @@ -24,6 +24,6 @@ "symfony/filesystem": "^4.4", "symfony/finder": "^4.4", "symfony/lock": "^4.4", - "symfony/phpunit-bridge": "^4.4" + "symfony/phpunit-bridge": "^4.4.8" } } diff --git a/core/lib/Drupal/Core/Composer/Composer.php b/core/lib/Drupal/Core/Composer/Composer.php index 6b7d5899..2f60ab9d 100644 --- a/core/lib/Drupal/Core/Composer/Composer.php +++ b/core/lib/Drupal/Core/Composer/Composer.php @@ -310,7 +310,7 @@ public static function upgradePHPUnit(Event $event) { return; } - // If the PHP version is 7.3 or above and PHPUnit is less than version 7 + // If the PHP version is 7.4 or above and PHPUnit is less than version 9 // call the drupal-phpunit-upgrade script to upgrade PHPUnit. if (!static::upgradePHPUnitCheck($phpunit_package->getVersion())) { $event->getComposer() @@ -332,7 +332,7 @@ public static function upgradePHPUnit(Event $event) { * TRUE if the PHPUnit needs to be upgraded, FALSE if not. */ public static function upgradePHPUnitCheck($phpunit_version) { - return !(version_compare(PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION, '7.3') >= 0 && version_compare($phpunit_version, '7.0') < 0); + return !(version_compare(PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION, '7.4') >= 0 && version_compare($phpunit_version, '9.0') < 0); } } diff --git a/core/modules/hal/tests/src/Kernel/EntityTranslationNormalizeTest.php b/core/modules/hal/tests/src/Kernel/EntityTranslationNormalizeTest.php index bd31f529..af1f10a2 100644 --- a/core/modules/hal/tests/src/Kernel/EntityTranslationNormalizeTest.php +++ b/core/modules/hal/tests/src/Kernel/EntityTranslationNormalizeTest.php @@ -70,8 +70,8 @@ public function testNodeTranslation() { $normalized = $this->serializer->normalize($node, $this->format); - $this->assertContains(['lang' => 'en', 'value' => $node->getTitle()], $normalized['title'], 'Original language title has been normalized.'); - $this->assertContains(['lang' => 'de', 'value' => $translation->getTitle()], $normalized['title'], 'Translation language title has been normalized.'); + $this->assertContainsEquals(['lang' => 'en', 'value' => $node->getTitle()], $normalized['title'], 'Original language title has been normalized.'); + $this->assertContainsEquals(['lang' => 'de', 'value' => $translation->getTitle()], $normalized['title'], 'Translation language title has been normalized.'); /** @var \Drupal\node\NodeInterface $denormalized_node */ $denormalized_node = $this->serializer->denormalize($normalized, 'Drupal\node\Entity\Node', $this->format); diff --git a/core/modules/migrate/tests/src/Unit/MigrateStubTest.php b/core/modules/migrate/tests/src/Unit/MigrateStubTest.php index fcf171b1..dbdc5e8e 100644 --- a/core/modules/migrate/tests/src/Unit/MigrateStubTest.php +++ b/core/modules/migrate/tests/src/Unit/MigrateStubTest.php @@ -3,6 +3,7 @@ namespace Drupal\Tests\migrate\Unit; use Drupal\Component\Plugin\Exception\PluginNotFoundException; +use Drupal\Tests\Traits\PhpUnitWarningsCompatibilityTrait; use Drupal\migrate\MigrateStub; use Drupal\migrate\Plugin\MigrateDestinationInterface; use Drupal\migrate\Plugin\MigrateIdMapInterface; @@ -22,6 +23,8 @@ */ class MigrateStubTest extends TestCase { + use PhpUnitWarningsCompatibilityTrait; + /** * The plugin manager prophecy. * diff --git a/core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelectionReferenceableTest.php b/core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelectionReferenceableTest.php index c2ca15e1..2110aa8b 100644 --- a/core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelectionReferenceableTest.php +++ b/core/modules/system/tests/src/Kernel/Entity/EntityReferenceSelectionReferenceableTest.php @@ -126,7 +126,7 @@ public function testReferenceablesWithNoLabelKey($match, $match_operator, $limit // entity labels. // @see \Drupal\Core\Entity\EntityReferenceSelection\SelectionInterface::getReferenceableEntities() $item = is_string($item) ? Html::escape($item) : $item; - $this->assertContains($item, $referenceables[$this->bundle]); + $this->assertContainsEquals($item, $referenceables[$this->bundle]); } // Test ::countReferenceableEntities(). diff --git a/core/modules/views/tests/src/Kernel/Plugin/ViewsSqlExceptionTest.php b/core/modules/views/tests/src/Kernel/Plugin/ViewsSqlExceptionTest.php index 39574d65..f08ac5be 100644 --- a/core/modules/views/tests/src/Kernel/Plugin/ViewsSqlExceptionTest.php +++ b/core/modules/views/tests/src/Kernel/Plugin/ViewsSqlExceptionTest.php @@ -47,7 +47,7 @@ public function testSqlException() { ]); $this->expectException(DatabaseExceptionWrapper::class); - $this->expectExceptionMessageRegExp('/^Exception in Test filters\[test_filter\]:/'); + $this->expectExceptionMessageMatches('/^Exception in Test filters\[test_filter\]:/'); $this->executeView($view); } diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh index 955eb5bf..91b47782 100755 --- a/core/scripts/run-tests.sh +++ b/core/scripts/run-tests.sh @@ -149,7 +149,7 @@ } if (!Composer::upgradePHPUnitCheck(Version::id())) { - simpletest_script_print_error("PHPUnit testing framework version 7 or greater is required when running on PHP 7.3 or greater. Run the command 'composer run-script drupal-phpunit-upgrade' in order to fix this."); + simpletest_script_print_error("PHPUnit testing framework version 9 or greater is required when running on PHP 7.4 or greater. Run the command 'composer run-script drupal-phpunit-upgrade' in order to fix this."); exit(SIMPLETEST_SCRIPT_EXIT_FAILURE); } diff --git a/core/tests/Drupal/BuildTests/Framework/BuildTestBase.php b/core/tests/Drupal/BuildTests/Framework/BuildTestBase.php index cddc6d58..be8ae2e4 100644 --- a/core/tests/Drupal/BuildTests/Framework/BuildTestBase.php +++ b/core/tests/Drupal/BuildTests/Framework/BuildTestBase.php @@ -7,7 +7,7 @@ use Behat\Mink\Mink; use Behat\Mink\Session; use Drupal\Component\FileSystem\FileSystem as DrupalFilesystem; -use Drupal\Tests\Traits\PHPUnit8Warnings; +use Drupal\Tests\Traits\PhpUnitWarningsCompatibilityTrait; use PHPUnit\Framework\TestCase; use Symfony\Component\BrowserKit\Client as SymfonyClient; use Symfony\Component\Filesystem\Filesystem as SymfonyFilesystem; @@ -53,7 +53,7 @@ abstract class BuildTestBase extends TestCase { use ExternalCommandRequirementsTrait; - use PHPUnit8Warnings; + use PhpUnitWarningsCompatibilityTrait; /** * The working directory where this test will manipulate files. diff --git a/core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php b/core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php index d0542986..0235a421 100644 --- a/core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php +++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigImporterTest.php @@ -617,7 +617,7 @@ public function testUnmetDependency() { 'Configuration unknown.config depends on the unknown extension that will not be installed after import.', ]; foreach ($expected as $expected_message) { - $this->assertContains($expected_message, $error_log, $expected_message); + $this->assertContainsEquals($expected_message, $error_log, $expected_message); } } @@ -663,7 +663,7 @@ public function testUnmetDependency() { 'Configuration config_test.dynamic.dotted.theme depends on themes (unknown, Seven) that will not be installed after import.', ]; foreach ($expected as $expected_message) { - $this->assertContains($expected_message, $error_log, $expected_message); + $this->assertContainsEquals($expected_message, $error_log, $expected_message); } } } diff --git a/core/tests/Drupal/KernelTests/Core/File/NameMungingTest.php b/core/tests/Drupal/KernelTests/Core/File/NameMungingTest.php index 6e1becc6..a32ed0c3 100644 --- a/core/tests/Drupal/KernelTests/Core/File/NameMungingTest.php +++ b/core/tests/Drupal/KernelTests/Core/File/NameMungingTest.php @@ -42,7 +42,7 @@ public function testMunging() { $munged_name = file_munge_filename($this->name, '', TRUE); $messages = \Drupal::messenger()->all(); \Drupal::messenger()->deleteAll(); - $this->assertContains(strtr('For security reasons, your upload has been renamed to %filename.', ['%filename' => $munged_name]), $messages['status'], 'Alert properly set when a file is renamed.'); + $this->assertContainsEquals(strtr('For security reasons, your upload has been renamed to %filename.', ['%filename' => $munged_name]), $messages['status'], 'Alert properly set when a file is renamed.'); $this->assertNotEqual($munged_name, $this->name, new FormattableMarkup('The new filename (%munged) has been modified from the original (%original)', ['%munged' => $munged_name, '%original' => $this->name])); } diff --git a/core/tests/Drupal/KernelTests/Core/Messenger/MessengerTest.php b/core/tests/Drupal/KernelTests/Core/Messenger/MessengerTest.php index ac305022..e244e05e 100644 --- a/core/tests/Drupal/KernelTests/Core/Messenger/MessengerTest.php +++ b/core/tests/Drupal/KernelTests/Core/Messenger/MessengerTest.php @@ -49,7 +49,7 @@ public function testRemoveSingleMessage() { // Check we only have the second one. $this->assertCount(1, $this->messenger->messagesByType(MessengerInterface::TYPE_STATUS)); - $this->assertContains('Second message with markup! (not removed).', $this->messenger->deleteByType(MessengerInterface::TYPE_STATUS)); + $this->assertContainsEquals('Second message with markup! (not removed).', $this->messenger->deleteByType(MessengerInterface::TYPE_STATUS)); } diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php index b1ebad5e..8dc01420 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBase.php +++ b/core/tests/Drupal/KernelTests/KernelTestBase.php @@ -20,7 +20,7 @@ use Drupal\Tests\ConfigTestTrait; use Drupal\Tests\RandomGeneratorTrait; use Drupal\Tests\TestRequirementsTrait; -use Drupal\Tests\Traits\PHPUnit8Warnings; +use Drupal\Tests\Traits\PhpUnitWarningsCompatibilityTrait; use Drupal\TestTools\Comparator\MarkupInterfaceComparator; use PHPUnit\Framework\Exception; use PHPUnit\Framework\TestCase; @@ -80,7 +80,7 @@ use RandomGeneratorTrait; use ConfigTestTrait; use TestRequirementsTrait; - use PHPUnit8Warnings; + use PhpUnitWarningsCompatibilityTrait; /** * {@inheritdoc} diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index afea7671..239d182f 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -16,7 +16,7 @@ use Drupal\Tests\block\Traits\BlockCreationTrait; use Drupal\Tests\node\Traits\ContentTypeCreationTrait; use Drupal\Tests\node\Traits\NodeCreationTrait; -use Drupal\Tests\Traits\PHPUnit8Warnings; +use Drupal\Tests\Traits\PhpUnitWarningsCompatibilityTrait; use Drupal\Tests\user\Traits\UserCreationTrait; use Drupal\TestTools\Comparator\MarkupInterfaceComparator; use GuzzleHttp\Cookie\CookieJar; @@ -64,7 +64,7 @@ createUser as drupalCreateUser; } use XdebugRequestTrait; - use PHPUnit8Warnings; + use PhpUnitWarningsCompatibilityTrait; /** * The database prefix of this test run. diff --git a/core/tests/Drupal/Tests/Component/Annotation/Plugin/Discovery/AnnotationBridgeDecoratorTest.php b/core/tests/Drupal/Tests/Component/Annotation/Plugin/Discovery/AnnotationBridgeDecoratorTest.php index 12732e11..5cbfa08e 100644 --- a/core/tests/Drupal/Tests/Component/Annotation/Plugin/Discovery/AnnotationBridgeDecoratorTest.php +++ b/core/tests/Drupal/Tests/Component/Annotation/Plugin/Discovery/AnnotationBridgeDecoratorTest.php @@ -6,6 +6,7 @@ use Drupal\Component\Annotation\Plugin\Discovery\AnnotationBridgeDecorator; use Drupal\Component\Plugin\Definition\PluginDefinition; use Drupal\Component\Plugin\Discovery\DiscoveryInterface; +use Drupal\Tests\Traits\PhpUnitWarningsCompatibilityTrait; use PHPUnit\Framework\TestCase; /** @@ -14,6 +15,8 @@ */ class AnnotationBridgeDecoratorTest extends TestCase { + use PhpUnitWarningsCompatibilityTrait; + /** * @covers ::getDefinitions */ diff --git a/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php b/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php index 2172f201..302bf3f0 100644 --- a/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php +++ b/core/tests/Drupal/Tests/Component/DependencyInjection/ContainerTest.php @@ -8,6 +8,7 @@ namespace Drupal\Tests\Component\DependencyInjection; use Drupal\Component\Utility\Crypt; +use Drupal\Tests\Traits\PhpUnitWarningsCompatibilityTrait; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException; @@ -24,6 +25,8 @@ */ class ContainerTest extends TestCase { + use PhpUnitWarningsCompatibilityTrait; + /** * The tested container. * diff --git a/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php b/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php index 12c847d3..1a12ac25 100644 --- a/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php +++ b/core/tests/Drupal/Tests/Component/DependencyInjection/Dumper/OptimizedPhpArrayDumperTest.php @@ -8,6 +8,7 @@ namespace Drupal\Tests\Component\DependencyInjection\Dumper { use Drupal\Component\Utility\Crypt; + use Drupal\Tests\Traits\PhpUnitWarningsCompatibilityTrait; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\DependencyInjection\Reference; @@ -24,6 +25,8 @@ */ class OptimizedPhpArrayDumperTest extends TestCase { + use PhpUnitWarningsCompatibilityTrait; + /** * The container builder instance. * diff --git a/core/tests/Drupal/Tests/Component/Diff/Engine/DiffOpTest.php b/core/tests/Drupal/Tests/Component/Diff/Engine/DiffOpTest.php index be205481..76f0064e 100644 --- a/core/tests/Drupal/Tests/Component/Diff/Engine/DiffOpTest.php +++ b/core/tests/Drupal/Tests/Component/Diff/Engine/DiffOpTest.php @@ -4,7 +4,6 @@ use Drupal\Component\Diff\Engine\DiffOp; use PHPUnit\Framework\TestCase; -use PHPUnit\Framework\Error\Error; /** * Test DiffOp base class. @@ -25,7 +24,7 @@ class DiffOpTest extends TestCase { * @covers ::reverse */ public function testReverse() { - $this->expectException(Error::class); + $this->expectError(); $op = new DiffOp(); $result = $op->reverse(); } diff --git a/core/tests/Drupal/Tests/Component/Gettext/PoStreamWriterTest.php b/core/tests/Drupal/Tests/Component/Gettext/PoStreamWriterTest.php index 75f50d5b..d2482a20 100644 --- a/core/tests/Drupal/Tests/Component/Gettext/PoStreamWriterTest.php +++ b/core/tests/Drupal/Tests/Component/Gettext/PoStreamWriterTest.php @@ -4,6 +4,7 @@ use Drupal\Component\Gettext\PoItem; use Drupal\Component\Gettext\PoStreamWriter; +use Drupal\Tests\Traits\PhpUnitWarningsCompatibilityTrait; use org\bovigo\vfs\vfsStream; use org\bovigo\vfs\vfsStreamFile; use PHPUnit\Framework\TestCase; @@ -14,6 +15,8 @@ */ class PoStreamWriterTest extends TestCase { + use PhpUnitWarningsCompatibilityTrait; + /** * The PO writer object under test. * diff --git a/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php b/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php index 6230bdbd..4ac9559a 100644 --- a/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php +++ b/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php @@ -4,8 +4,8 @@ use Drupal\Component\PhpStorage\FileStorage; use Drupal\Component\Utility\Random; +use Drupal\Tests\Traits\PhpUnitWarningsCompatibilityTrait; use org\bovigo\vfs\vfsStreamDirectory; -use PHPUnit\Framework\Error\Warning; /** * @coversDefaultClass \Drupal\Component\PhpStorage\FileStorage @@ -14,6 +14,8 @@ */ class FileStorageTest extends PhpStorageTestBase { + use PhpUnitWarningsCompatibilityTrait; + /** * Standard test settings to pass to storage instances. * @@ -99,8 +101,8 @@ public function testCreateDirectoryFailWarning() { 'bin' => 'test', ]); $code = "expectException(Warning::class); - $this->expectExceptionMessage('mkdir(): Permission Denied'); + $this->expectWarning(); + $this->expectWarningMessage('mkdir(): Permission Denied'); $storage->save('subdirectory/foo.php', $code); } diff --git a/core/tests/Drupal/Tests/Component/Plugin/PluginManagerBaseTest.php b/core/tests/Drupal/Tests/Component/Plugin/PluginManagerBaseTest.php index 954ff701..64586b29 100644 --- a/core/tests/Drupal/Tests/Component/Plugin/PluginManagerBaseTest.php +++ b/core/tests/Drupal/Tests/Component/Plugin/PluginManagerBaseTest.php @@ -5,6 +5,7 @@ use Drupal\Component\Plugin\Exception\PluginNotFoundException; use Drupal\Component\Plugin\Mapper\MapperInterface; use Drupal\Component\Plugin\PluginManagerBase; +use Drupal\Tests\Traits\PhpUnitWarningsCompatibilityTrait; use PHPUnit\Framework\TestCase; /** @@ -13,6 +14,8 @@ */ class PluginManagerBaseTest extends TestCase { + use PhpUnitWarningsCompatibilityTrait; + /** * A callback method for mocking FactoryInterface objects. */ diff --git a/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/AssertUtilsTrait.php b/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/AssertUtilsTrait.php index 96dab849..6119fe2a 100644 --- a/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/AssertUtilsTrait.php +++ b/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/AssertUtilsTrait.php @@ -2,13 +2,13 @@ namespace Drupal\Tests\Composer\Plugin\Scaffold; -use Drupal\Tests\Traits\PHPUnit8Warnings; +use Drupal\Tests\Traits\PhpUnitWarningsCompatibilityTrait; /** * Convenience class for creating fixtures. */ trait AssertUtilsTrait { - use PHPUnit8Warnings; + use PhpUnitWarningsCompatibilityTrait; /** * Asserts that a given file exists and is/is not a symlink. diff --git a/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Integration/AppendOpTest.php b/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Integration/AppendOpTest.php index e37d06f1..f358a815 100644 --- a/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Integration/AppendOpTest.php +++ b/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Integration/AppendOpTest.php @@ -5,7 +5,7 @@ use Drupal\Composer\Plugin\Scaffold\Operations\AppendOp; use Drupal\Composer\Plugin\Scaffold\ScaffoldOptions; use Drupal\Tests\Composer\Plugin\Scaffold\Fixtures; -use Drupal\Tests\Traits\PHPUnit8Warnings; +use Drupal\Tests\Traits\PhpUnitWarningsCompatibilityTrait; use PHPUnit\Framework\TestCase; /** @@ -14,7 +14,7 @@ * @group Scaffold */ class AppendOpTest extends TestCase { - use PHPUnit8Warnings; + use PhpUnitWarningsCompatibilityTrait; /** * @covers ::process diff --git a/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Integration/ReplaceOpTest.php b/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Integration/ReplaceOpTest.php index cb5d6c7c..1df61ff7 100644 --- a/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Integration/ReplaceOpTest.php +++ b/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Integration/ReplaceOpTest.php @@ -5,7 +5,7 @@ use Drupal\Composer\Plugin\Scaffold\Operations\ReplaceOp; use Drupal\Composer\Plugin\Scaffold\ScaffoldOptions; use Drupal\Tests\Composer\Plugin\Scaffold\Fixtures; -use Drupal\Tests\Traits\PHPUnit8Warnings; +use Drupal\Tests\Traits\PhpUnitWarningsCompatibilityTrait; use PHPUnit\Framework\TestCase; /** @@ -14,7 +14,7 @@ * @group Scaffold */ class ReplaceOpTest extends TestCase { - use PHPUnit8Warnings; + use PhpUnitWarningsCompatibilityTrait; /** * @covers ::process diff --git a/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Integration/SkipOpTest.php b/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Integration/SkipOpTest.php index ba8313bb..859f931d 100644 --- a/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Integration/SkipOpTest.php +++ b/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/Integration/SkipOpTest.php @@ -5,7 +5,7 @@ use Drupal\Composer\Plugin\Scaffold\Operations\SkipOp; use Drupal\Composer\Plugin\Scaffold\ScaffoldOptions; use Drupal\Tests\Composer\Plugin\Scaffold\Fixtures; -use Drupal\Tests\Traits\PHPUnit8Warnings; +use Drupal\Tests\Traits\PhpUnitWarningsCompatibilityTrait; use PHPUnit\Framework\TestCase; /** @@ -14,7 +14,7 @@ * @group Scaffold */ class SkipOpTest extends TestCase { - use PHPUnit8Warnings; + use PhpUnitWarningsCompatibilityTrait; /** * @covers ::process diff --git a/core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/ConfigTest.php b/core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/ConfigTest.php index 9755278b..670ddff0 100644 --- a/core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/ConfigTest.php +++ b/core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/ConfigTest.php @@ -4,6 +4,7 @@ use Composer\Package\RootPackageInterface; use Drupal\Composer\Plugin\VendorHardening\Config; +use Drupal\Tests\Traits\PhpUnitWarningsCompatibilityTrait; use PHPUnit\Framework\TestCase; /** @@ -12,6 +13,8 @@ */ class ConfigTest extends TestCase { + use PhpUnitWarningsCompatibilityTrait; + /** * @covers ::getPathsForPackage */ diff --git a/core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/VendorHardeningPluginTest.php b/core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/VendorHardeningPluginTest.php index 089b9067..4378c1bd 100644 --- a/core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/VendorHardeningPluginTest.php +++ b/core/tests/Drupal/Tests/Composer/Plugin/VendorHardening/VendorHardeningPluginTest.php @@ -8,6 +8,7 @@ use Composer\Package\RootPackageInterface; use Drupal\Composer\VendorHardening\Config; use Drupal\Composer\Plugin\VendorHardening\VendorHardeningPlugin; +use Drupal\Tests\Traits\PhpUnitWarningsCompatibilityTrait; use org\bovigo\vfs\vfsStream; use PHPUnit\Framework\TestCase; @@ -17,6 +18,8 @@ */ class VendorHardeningPluginTest extends TestCase { + use PhpUnitWarningsCompatibilityTrait; + public function setUp(): void { parent::setUp(); vfsStream::setup('vendor', NULL, [ diff --git a/core/tests/Drupal/Tests/Core/Asset/CssCollectionGrouperUnitTest.php b/core/tests/Drupal/Tests/Core/Asset/CssCollectionGrouperUnitTest.php index 7e5fe848..40efadf4 100644 --- a/core/tests/Drupal/Tests/Core/Asset/CssCollectionGrouperUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Asset/CssCollectionGrouperUnitTest.php @@ -113,8 +113,8 @@ public function testGrouper() { $this->assertSame('all', $group['media']); $this->assertTrue($group['preprocess']); $this->assertCount(3, $group['items']); - $this->assertContains($css_assets['system.base.css'], $group['items']); - $this->assertContains($css_assets['js.module.css'], $group['items']); + $this->assertContainsEquals($css_assets['system.base.css'], $group['items']); + $this->assertContainsEquals($css_assets['js.module.css'], $group['items']); // Check group 2. $group = $groups[1]; @@ -123,7 +123,7 @@ public function testGrouper() { $this->assertSame('all', $group['media']); $this->assertTrue($group['preprocess']); $this->assertCount(1, $group['items']); - $this->assertContains($css_assets['field.css'], $group['items']); + $this->assertContainsEquals($css_assets['field.css'], $group['items']); // Check group 3. $group = $groups[2]; @@ -132,7 +132,7 @@ public function testGrouper() { $this->assertSame('all', $group['media']); $this->assertTrue($group['preprocess']); $this->assertCount(1, $group['items']); - $this->assertContains($css_assets['external.css'], $group['items']); + $this->assertContainsEquals($css_assets['external.css'], $group['items']); // Check group 4. $group = $groups[3]; @@ -141,7 +141,7 @@ public function testGrouper() { $this->assertSame('all', $group['media']); $this->assertTrue($group['preprocess']); $this->assertCount(1, $group['items']); - $this->assertContains($css_assets['elements.css'], $group['items']); + $this->assertContainsEquals($css_assets['elements.css'], $group['items']); // Check group 5. $group = $groups[4]; @@ -150,7 +150,7 @@ public function testGrouper() { $this->assertSame('print', $group['media']); $this->assertTrue($group['preprocess']); $this->assertCount(1, $group['items']); - $this->assertContains($css_assets['print.css'], $group['items']); + $this->assertContainsEquals($css_assets['print.css'], $group['items']); } } diff --git a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php index 3f36ec29..6d36191e 100644 --- a/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Config/Entity/ConfigEntityBaseUnitTest.php @@ -636,7 +636,7 @@ public function testToArraySchemaException() { ->method('getPropertiesToExport') ->willReturn(NULL); $this->expectException(SchemaIncompleteException::class); - $this->expectExceptionMessageRegExp("/Entity type 'Mock_ConfigEntityTypeInterface_[^']*' is missing 'config_export' definition in its annotation/"); + $this->expectExceptionMessageMatches("/Entity type 'Mock_ConfigEntityTypeInterface_[^']*' is missing 'config_export' definition in its annotation/"); $this->entity->toArray(); } diff --git a/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php index d6f17a04..c528883e 100644 --- a/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php +++ b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php @@ -212,6 +212,8 @@ public static function getSkippedDeprecations() { 'AssertLegacyTrait::assertHeader() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseHeaderEquals() instead. See https://www.drupal.org/node/3129738', 'AssertLegacyTrait::buildXPathQuery() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->buildXPathQuery() instead. See https://www.drupal.org/node/3129738', 'AssertLegacyTrait::constructFieldXpath() is deprecated in drupal:8.5.0 and is removed from drupal:10.0.0. Use $this->getSession()->getPage()->findField() instead. See https://www.drupal.org/node/3129738', + // 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 a3f7916e..a85c3204 100644 --- a/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php +++ b/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php @@ -2,15 +2,27 @@ namespace Drupal\Tests\Listeners; +use Drupal\TestTools\PhpUnitCompatibility\RunnerVersion; use PHPUnit\Framework\TestResult; -use PHPUnit\TextUI\ResultPrinter; + +// 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); + } +} /** * Defines a class for providing html output results for functional tests. * * @internal */ -class HtmlOutputPrinter extends ResultPrinter { +class HtmlOutputPrinter extends ResultPrinterBase { use HtmlOutputPrinterTrait; diff --git a/core/tests/Drupal/Tests/Traits/PHPUnit8Warnings.php b/core/tests/Drupal/Tests/Traits/PHPUnit8Warnings.php deleted file mode 100644 index 5b802646..00000000 --- a/core/tests/Drupal/Tests/Traits/PHPUnit8Warnings.php +++ /dev/null @@ -1,43 +0,0 @@ -