diff --git a/composer.json b/composer.json index 3000a86..619c170 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 --with-dependencies --no-progress", + "drupal-phpunit-upgrade": "@composer update phpunit/phpunit symfony/phpunit-bridge --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 62c26c4..7cafbfa 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.1", + "phpunit/phpunit": "^4.8.35 || ^6.1 || ^7", "phpspec/prophecy": "^1.4", "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 f3d1c22..d93e1e2 100644 --- a/core/modules/file/tests/src/Functional/FileFieldTestBase.php +++ b/core/modules/file/tests/src/Functional/FileFieldTestBase.php @@ -199,8 +199,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); } @@ -226,8 +226,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 b115a61..7c512f7 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 e0450d1..75d65d1 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 f63c4bf..a182885 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 4eeed6e..6c5fe44 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBase.php +++ b/core/tests/Drupal/KernelTests/KernelTestBase.php @@ -1100,16 +1100,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 ba814d9..6f47692 100644 --- a/core/tests/Drupal/Tests/AssertHelperTrait.php +++ b/core/tests/Drupal/Tests/AssertHelperTrait.php @@ -10,6 +10,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. * * @param string|array $value diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index 313b203..d2398cf 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -1291,18 +1291,6 @@ protected function getDrupalSettings() { } /** - * {@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. * * @return array diff --git a/core/tests/Drupal/Tests/Core/Test/TestSuiteBaseTest.php b/core/tests/Drupal/Tests/Core/Test/TestSuiteBaseTest.php index ede32eb..7ff15c6 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 cafaa22..abf0a41 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 8021989..1fb914e 100644 --- a/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php +++ b/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php @@ -32,7 +32,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 bfb91d7..4e6e692 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 e0a5f72..d4b5697 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 84937ad..2009532 100644 --- a/core/tests/Drupal/Tests/TestRequirementsTrait.php +++ b/core/tests/Drupal/Tests/TestRequirementsTrait.php @@ -32,8 +32,19 @@ protected static function getDrupalRoot() { * Thrown when the requirements are not met, and this test should be * skipped. Callers should not catch this exception. */ - protected function checkRequirements() { - parent::checkRequirements(); + private function checkRequirements() { + if (!$this->name || !\method_exists($this, $this->name)) { + return; + } + + $missingRequirements = 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 bd183c7..d37a1d4 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);