diff --git a/composer.json b/composer.json index bad832ed4c..1ce08e2fbb 100644 --- a/composer.json +++ b/composer.json @@ -53,7 +53,7 @@ "post-package-install": "Drupal\\Core\\Composer\\Composer::vendorTestCodeCleanup", "post-package-update": "Drupal\\Core\\Composer\\Composer::vendorTestCodeCleanup", "drupal-phpunit-upgrade-check": "Drupal\\Core\\Composer\\Composer::upgradePHPUnit", - "drupal-phpunit-upgrade": "@composer update phpunit/phpunit phpspec/prophecy symfony/yaml --with-dependencies --no-progress", + "drupal-phpunit-upgrade": "@composer update phpunit/phpunit symfony/phpunit-bridge phpspec/prophecy symfony/yaml --with-dependencies --no-progress", "phpcs": "phpcs --standard=core/phpcs.xml.dist --runtime-set installed_paths $($COMPOSER_BINARY config vendor-dir)/drupal/coder/coder_sniffer --", "phpcbf": "phpcbf --standard=core/phpcs.xml.dist --runtime-set installed_paths $($COMPOSER_BINARY config vendor-dir)/drupal/coder/coder_sniffer --" }, diff --git a/core/composer.json b/core/composer.json index 37120ae8ce..20d4f88f2e 100644 --- a/core/composer.json +++ b/core/composer.json @@ -58,7 +58,7 @@ "jcalderonzumba/gastonjs": "^1.0.2", "jcalderonzumba/mink-phantomjs-driver": "^0.3.1", "mikey179/vfsStream": "^1.2", - "phpunit/phpunit": "^4.8.35 || ^6.5", + "phpunit/phpunit": "^4.8.35 || ^6.5 || ^7", "phpspec/prophecy": "^1.7", "symfony/css-selector": "^3.4.0", "symfony/phpunit-bridge": "^3.4.3", diff --git a/core/modules/file/tests/src/Functional/FileFieldTestBase.php b/core/modules/file/tests/src/Functional/FileFieldTestBase.php index dc2e8becc1..c0d8948249 100644 --- a/core/modules/file/tests/src/Functional/FileFieldTestBase.php +++ b/core/modules/file/tests/src/Functional/FileFieldTestBase.php @@ -203,8 +203,8 @@ public function replaceNodeFile($file, $field_name, $nid, $new_revision = TRUE) * @param string $message * (optional) A message to display with the assertion. */ - public static function assertFileExists($file, $message = NULL) { - $message = isset($message) ? $message : format_string('File %file exists on the disk.', ['%file' => $file->getFileUri()]); + public static function assertFileExists($file, string $message = ''): void { + $message = isset($message) && $message !== '' ? $message : format_string('File %file exists on the disk.', ['%file' => $file->getFileUri()]); $filename = $file instanceof FileInterface ? $file->getFileUri() : $file; parent::assertFileExists($filename, $message); } @@ -230,8 +230,8 @@ public function assertFileEntryExists($file, $message = NULL) { * @param string $message * (optional) A message to display with the assertion. */ - public static function assertFileNotExists($file, $message = NULL) { - $message = isset($message) ? $message : format_string('File %file exists on the disk.', ['%file' => $file->getFileUri()]); + public static function assertFileNotExists($file, string $message = ''): void { + $message = isset($message) && $message !== '' ? $message : format_string('File %file exists on the disk.', ['%file' => $file->getFileUri()]); $filename = $file instanceof FileInterface ? $file->getFileUri() : $file; parent::assertFileNotExists($filename, $message); } diff --git a/core/modules/system/src/Tests/Cache/AssertPageCacheContextsAndTagsTrait.php b/core/modules/system/src/Tests/Cache/AssertPageCacheContextsAndTagsTrait.php index b115a61ee2..7c512f7cf3 100644 --- a/core/modules/system/src/Tests/Cache/AssertPageCacheContextsAndTagsTrait.php +++ b/core/modules/system/src/Tests/Cache/AssertPageCacheContextsAndTagsTrait.php @@ -155,7 +155,7 @@ protected function assertCacheTags(array $expected_tags, $include_default_tags = * @return bool * TRUE if the assertion succeeded, FALSE otherwise. */ - protected function assertCacheContexts(array $expected_contexts, $message = NULL, $include_default_contexts = TRUE) { + protected function assertCacheContexts(array $expected_contexts, $message = '', $include_default_contexts = TRUE) { if ($include_default_contexts) { $default_contexts = ['languages:language_interface', 'theme']; // Add the user.permission context to the list of default contexts except diff --git a/core/modules/system/tests/src/Functional/Cache/AssertPageCacheContextsAndTagsTrait.php b/core/modules/system/tests/src/Functional/Cache/AssertPageCacheContextsAndTagsTrait.php index e0450d1660..75d65d13ae 100644 --- a/core/modules/system/tests/src/Functional/Cache/AssertPageCacheContextsAndTagsTrait.php +++ b/core/modules/system/tests/src/Functional/Cache/AssertPageCacheContextsAndTagsTrait.php @@ -149,7 +149,7 @@ protected function assertCacheTags(array $expected_tags, $include_default_tags = * @return bool * TRUE if the assertion succeeded, FALSE otherwise. */ - protected function assertCacheContexts(array $expected_contexts, $message = NULL, $include_default_contexts = TRUE) { + protected function assertCacheContexts(array $expected_contexts, $message = '', $include_default_contexts = TRUE) { if ($include_default_contexts) { $default_contexts = ['languages:language_interface', 'theme']; // Add the user.permission context to the list of default contexts except diff --git a/core/tests/Drupal/KernelTests/AssertLegacyTrait.php b/core/tests/Drupal/KernelTests/AssertLegacyTrait.php index f63c4bf0b6..a182885fff 100644 --- a/core/tests/Drupal/KernelTests/AssertLegacyTrait.php +++ b/core/tests/Drupal/KernelTests/AssertLegacyTrait.php @@ -26,7 +26,7 @@ protected function assert($actual, $message = '') { /** * @see \Drupal\simpletest\TestBase::assertTrue() */ - public static function assertTrue($actual, $message = '') { + public static function assertTrue($actual, string $message = ''): void { if (is_bool($actual)) { parent::assertTrue($actual, $message); } @@ -38,7 +38,7 @@ public static function assertTrue($actual, $message = '') { /** * @see \Drupal\simpletest\TestBase::assertFalse() */ - public static function assertFalse($actual, $message = '') { + public static function assertFalse($actual, string $message = ''): void { if (is_bool($actual)) { parent::assertFalse($actual, $message); } diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php index 5e9bffc2dd..bb797811aa 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBase.php +++ b/core/tests/Drupal/KernelTests/KernelTestBase.php @@ -1121,16 +1121,4 @@ public function __sleep() { return []; } - /** - * {@inheritdoc} - */ - public static function assertEquals($expected, $actual, $message = '', $delta = 0.0, $maxDepth = 10, $canonicalize = FALSE, $ignoreCase = FALSE) { - // Cast objects implementing MarkupInterface to string instead of - // relying on PHP casting them to string depending on what they are being - // comparing with. - $expected = static::castSafeStrings($expected); - $actual = static::castSafeStrings($actual); - parent::assertEquals($expected, $actual, $message, $delta, $maxDepth, $canonicalize, $ignoreCase); - } - } diff --git a/core/tests/Drupal/Tests/AssertHelperTrait.php b/core/tests/Drupal/Tests/AssertHelperTrait.php index ba814d9641..6f47692520 100644 --- a/core/tests/Drupal/Tests/AssertHelperTrait.php +++ b/core/tests/Drupal/Tests/AssertHelperTrait.php @@ -9,6 +9,18 @@ */ trait AssertHelperTrait { + /** + * {@inheritdoc} + */ + public static function assertEquals($expected, $actual, string $message = '', float $delta = 0, int $maxDepth = 10, bool $canonicalize = false, bool $ignoreCase = false): void { + // Cast objects implementing MarkupInterface to string instead of + // relying on PHP casting them to string depending on what they are being + // comparing with. + $expected = static::castSafeStrings($expected); + $actual = static::castSafeStrings($actual); + parent::assertEquals($expected, $actual, $message, $delta, $maxDepth, $canonicalize, $ignoreCase); + } + /** * Casts MarkupInterface objects into strings. * diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index 204eacb4f5..198a73fbbc 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -687,18 +687,6 @@ protected function getDrupalSettings() { return []; } - /** - * {@inheritdoc} - */ - public static function assertEquals($expected, $actual, $message = '', $delta = 0.0, $maxDepth = 10, $canonicalize = FALSE, $ignoreCase = FALSE) { - // Cast objects implementing MarkupInterface to string instead of - // relying on PHP casting them to string depending on what they are being - // comparing with. - $expected = static::castSafeStrings($expected); - $actual = static::castSafeStrings($actual); - parent::assertEquals($expected, $actual, $message, $delta, $maxDepth, $canonicalize, $ignoreCase); - } - /** * Retrieves the current calling line in the class under test. * diff --git a/core/tests/Drupal/Tests/Core/Test/TestSuiteBaseTest.php b/core/tests/Drupal/Tests/Core/Test/TestSuiteBaseTest.php index 853a788f5f..fdcc901511 100644 --- a/core/tests/Drupal/Tests/Core/Test/TestSuiteBaseTest.php +++ b/core/tests/Drupal/Tests/Core/Test/TestSuiteBaseTest.php @@ -142,7 +142,7 @@ protected function findExtensionDirectories($root) { /** * {@inheritdoc} */ - public function addTestFiles($filenames) { + public function addTestFiles($filenames): void { // We stub addTestFiles() because the parent implementation can't deal with // vfsStream-based filesystems due to an error in // stream_resolve_include_path(). See diff --git a/core/tests/Drupal/Tests/Listeners/DrupalListener.php b/core/tests/Drupal/Tests/Listeners/DrupalListener.php index cafaa2292b..abf0a41c13 100644 --- a/core/tests/Drupal/Tests/Listeners/DrupalListener.php +++ b/core/tests/Drupal/Tests/Listeners/DrupalListener.php @@ -2,7 +2,8 @@ namespace Drupal\Tests\Listeners; -use PHPUnit\Framework\BaseTestListener; +use PHPUnit\Framework\TestListener; +use PHPUnit\Framework\TestListenerDefaultImplementation; use PHPUnit\Framework\Test; if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) { @@ -18,7 +19,8 @@ class_alias('Drupal\Tests\Listeners\Legacy\DrupalListener', 'Drupal\Tests\Listen * * @internal */ - class DrupalListener extends BaseTestListener { + class DrupalListener implements TestListener { + use TestListenerDefaultImplementation; use DeprecationListenerTrait; use DrupalComponentTestListenerTrait; use DrupalStandardsListenerTrait; @@ -26,14 +28,14 @@ class DrupalListener extends BaseTestListener { /** * {@inheritdoc} */ - public function startTest(Test $test) { + public function startTest(Test $test): void { $this->deprecationStartTest($test); } /** * {@inheritdoc} */ - public function endTest(Test $test, $time) { + public function endTest(Test $test, $time): void { $this->deprecationEndTest($test, $time); $this->componentEndTest($test, $time); $this->standardsEndTest($test, $time); diff --git a/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php b/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php index 49618b8172..62e5c095bf 100644 --- a/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php +++ b/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php @@ -33,7 +33,7 @@ public function __construct($out = NULL, $verbose = FALSE, $colors = self::COLOR /** * {@inheritdoc} */ - public function printResult(TestResult $result) { + public function printResult(TestResult $result): void { parent::printResult($result); $this->printHtmlOutput(); diff --git a/core/tests/Drupal/Tests/Listeners/SimpletestUiPrinter.php b/core/tests/Drupal/Tests/Listeners/SimpletestUiPrinter.php index bfb91d7b9f..4e6e692ff2 100644 --- a/core/tests/Drupal/Tests/Listeners/SimpletestUiPrinter.php +++ b/core/tests/Drupal/Tests/Listeners/SimpletestUiPrinter.php @@ -12,7 +12,7 @@ class SimpletestUiPrinter extends HtmlOutputPrinter { /** * {@inheritdoc} */ - public function write($buffer) { + public function write(string $buffer): void { $buffer = Html::escape($buffer); // Turn HTML output URLs into clickable link tags. $url_pattern = '@https?://[^\s]+@'; diff --git a/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php b/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php index e0a5f72846..d4b5697214 100644 --- a/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php +++ b/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php @@ -2,6 +2,8 @@ namespace Drupal\Tests; +use PHPUnit\Framework\MockObject\MockObject; + /** * Makes Drupal's test API forward compatible with multiple versions of PHPUnit. */ @@ -107,7 +109,7 @@ public function getMock($originalClassName, $methods = [], array $arguments = [] * * @return \PHPUnit_Framework_MockObject_MockObject */ - public function createMock($originalClassName) { + public function createMock($originalClassName): MockObject { if ($this->supports('createMock')) { return parent::createMock($originalClassName); } diff --git a/core/tests/Drupal/Tests/TestRequirementsTrait.php b/core/tests/Drupal/Tests/TestRequirementsTrait.php index 84937ad69c..4c18dbed6a 100644 --- a/core/tests/Drupal/Tests/TestRequirementsTrait.php +++ b/core/tests/Drupal/Tests/TestRequirementsTrait.php @@ -33,7 +33,18 @@ protected static function getDrupalRoot() { * skipped. Callers should not catch this exception. */ protected function checkRequirements() { - parent::checkRequirements(); + if (!$this->name || !\method_exists($this, $this->name)) { + return; + } + + $missingRequirements = \PHPUnit\Util\Test::getMissingRequirements( + \get_class($this), + $this->name + ); + + if (!empty($missingRequirements)) { + $this->markTestSkipped(\implode(PHP_EOL, $missingRequirements)); + } $root = static::getDrupalRoot(); diff --git a/core/tests/Drupal/Tests/UnitTestCase.php b/core/tests/Drupal/Tests/UnitTestCase.php index bd183c7961..d37a1d4ee0 100644 --- a/core/tests/Drupal/Tests/UnitTestCase.php +++ b/core/tests/Drupal/Tests/UnitTestCase.php @@ -87,7 +87,7 @@ protected function getRandomGenerator() { * @param array $actual * @param string $message */ - protected function assertArrayEquals(array $expected, array $actual, $message = NULL) { + protected function assertArrayEquals(array $expected, array $actual, $message = '') { ksort($expected); ksort($actual); $this->assertEquals($expected, $actual, $message);