diff --git a/core/modules/big_pipe/tests/src/Unit/Render/BigPipeResponseAttachmentsProcessorTest.php b/core/modules/big_pipe/tests/src/Unit/Render/BigPipeResponseAttachmentsProcessorTest.php index ed1fc157ce..ba69bfee60 100644 --- a/core/modules/big_pipe/tests/src/Unit/Render/BigPipeResponseAttachmentsProcessorTest.php +++ b/core/modules/big_pipe/tests/src/Unit/Render/BigPipeResponseAttachmentsProcessorTest.php @@ -33,7 +33,7 @@ public function testNonHtmlResponse($response_class) { $big_pipe_response_attachments_processor = $this->createBigPipeResponseAttachmentsProcessor($this->prophesize(AttachmentsResponseProcessorInterface::class)); $non_html_response = new $response_class(); - $this->expectAssertion(); + $this->setExpectedException(\AssertionError::class); $big_pipe_response_attachments_processor->processAttachments($non_html_response); } diff --git a/core/modules/simpletest/src/TestBase.php b/core/modules/simpletest/src/TestBase.php index 5d41735e5b..dfaac2c743 100644 --- a/core/modules/simpletest/src/TestBase.php +++ b/core/modules/simpletest/src/TestBase.php @@ -1392,8 +1392,3 @@ public function getTempFilesDirectory() { } } - -// THIS LINE MUST BE REMOVED AFTER TEST RUNNERS ARE RECONFIGURED!!! -if (defined('ASSERT_EXCEPTION')) { - assert_options(ASSERT_EXCEPTION, 1); -} diff --git a/core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php b/core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php index 419810bcc8..ce5b28c91c 100644 --- a/core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php +++ b/core/tests/Drupal/KernelTests/Core/Cache/GenericCacheBackendUnitTestBase.php @@ -214,14 +214,12 @@ public function testSetGet() { $this->assertFalse($backend->get('test8')); // Calling ::set() with invalid cache tags. This should fail an assertion. - if (ini_get('zend.assertions') > 0) { - try { - $backend->set('assertion_test', 'value', Cache::PERMANENT, ['node' => [3, 5, 7]]); - $this->fail('::set() was called with invalid cache tags, runtime assertion did not fail.'); - } - catch (\AssertionError $e) { - $this->pass('::set() was called with invalid cache tags, runtime assertion failed.'); - } + try { + $backend->set('assertion_test', 'value', Cache::PERMANENT, ['node' => [3, 5, 7]]); + $this->fail('::set() was called with invalid cache tags, runtime assertion did not fail.'); + } + catch (\AssertionError $e) { + $this->pass('::set() was called with invalid cache tags, runtime assertion failed.'); } } @@ -413,22 +411,17 @@ public function testSetMultiple() { // Calling ::setMultiple() with invalid cache tags. This should fail an // assertion. - if (ini_get('zend.assertions') > 0) { - try { - $items = [ - 'exception_test_1' => ['data' => 1, 'tags' => []], - 'exception_test_2' => ['data' => 2, 'tags' => ['valid']], - 'exception_test_3' => ['data' => 3, 'tags' => ['node' => [3, 5, 7]]], - ]; - $backend->setMultiple($items); - $this->fail('::setMultiple() was called with invalid cache tags, runtime assertion did not fail.'); - } - catch (\AssertionError $e) { - $this->pass('::setMultiple() was called with invalid cache tags, runtime assertion failed.'); - } + try { + $items = [ + 'exception_test_1' => ['data' => 1, 'tags' => []], + 'exception_test_2' => ['data' => 2, 'tags' => ['valid']], + 'exception_test_3' => ['data' => 3, 'tags' => ['node' => [3, 5, 7]]], + ]; + $backend->setMultiple($items); + $this->fail('::setMultiple() was called with invalid cache tags, runtime assertion did not fail.'); } - else { - $this->markTestSkipped('Runtime assertions disabled, skipping.'); + catch (\AssertionError $e) { + $this->pass('::setMultiple() was called with invalid cache tags, runtime assertion failed.'); } } diff --git a/core/tests/Drupal/Tests/AssertHelperTrait.php b/core/tests/Drupal/Tests/AssertHelperTrait.php index 1ea613c390..ba814d9641 100644 --- a/core/tests/Drupal/Tests/AssertHelperTrait.php +++ b/core/tests/Drupal/Tests/AssertHelperTrait.php @@ -32,24 +32,4 @@ protected static function castSafeStrings($value) { return $value; } - /** - * Expect an assertion to failure. - * - * @param string $message - * Option failure message. - */ - protected function expectAssertion($message = '') { - if (ini_get('zend.assertions') != 1) { - $this->markTestSkipped( - 'Assertions are not enabled. Set zend.assertions to 1 to run this test.' - ); - } - elseif (method_exists($this, 'expectException')) { - $this->expectException(\AssertionError::class, $message); - } - else { - $this->setExpectedException(\AssertionError::class, $message); - } - } - } diff --git a/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php b/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php index 3605ab5333..a8a8af0e6c 100644 --- a/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/HtmlTest.php @@ -343,18 +343,13 @@ public function testTransformRootRelativeUrlsToAbsolute($html, $scheme_and_host, * @dataProvider providerTestTransformRootRelativeUrlsToAbsoluteAssertion */ public function testTransformRootRelativeUrlsToAbsoluteAssertion($scheme_and_host) { - if (ini_get('zend.assertions') > 0) { - if (method_exists($this, 'expectException')) { - $this->expectException(\AssertionError::class); - } - else { - $this->setExpectedException(\AssertionError::class); - } - Html::transformRootRelativeUrlsToAbsolute('', $scheme_and_host); + if (method_exists($this, 'expectException')) { + $this->expectException(\AssertionError::class); } else { - $this->markTestSkipped('Runtime assertions disabled, skipping.'); + $this->setExpectedException(\AssertionError::class); } + Html::transformRootRelativeUrlsToAbsolute('', $scheme_and_host); } /** diff --git a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php index 1761ae14bf..cbb06668c0 100644 --- a/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php +++ b/core/tests/Drupal/Tests/Core/Asset/LibraryDiscoveryParserTest.php @@ -528,7 +528,7 @@ public function testCssAssert($extension, $exception_message) { $path = substr($path, strlen($this->root) + 1); $this->libraryDiscoveryParser->setPaths('module', $extension, $path); - $this->expectAssertion($exception_message); + $this->setExpectedException(\AssertionError::class, $exception_message); $this->libraryDiscoveryParser->buildByExtension($extension); } diff --git a/core/tests/Drupal/Tests/Core/Cache/CacheTagsInvalidatorTest.php b/core/tests/Drupal/Tests/Core/Cache/CacheTagsInvalidatorTest.php index 2246fb9296..5466a098ab 100644 --- a/core/tests/Drupal/Tests/Core/Cache/CacheTagsInvalidatorTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/CacheTagsInvalidatorTest.php @@ -17,7 +17,7 @@ class CacheTagsInvalidatorTest extends UnitTestCase { */ public function testInvalidateTagsWithInvalidTags() { $cache_tags_invalidator = new CacheTagsInvalidator(); - $this->expectAssertion(); + $this->setExpectedException(\AssertionError::class); $cache_tags_invalidator->invalidateTags(['node' => [2, 3, 5, 8, 13]]); } diff --git a/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php b/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php index cd5cc0cc3d..f89e639cc7 100644 --- a/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/Context/CacheContextsManagerTest.php @@ -110,7 +110,7 @@ public function testInvalidContext() { $container = $this->getMockContainer(); $cache_contexts_manager = new CacheContextsManager($container, $this->getContextsFixture()); - $this->expectAssertion(); + $this->setExpectedException(\AssertionError::class); $cache_contexts_manager->convertTokensToKeys(["non-cache-context"]); } diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php index c057b7b93f..e8de5ecf59 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php @@ -114,7 +114,7 @@ public function testSetAlias() { */ public function testSerialize() { $container = new ContainerBuilder(); - $this->expectAssertion(); + $this->setExpectedException(\AssertionError::class); serialize($container); } diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php index 02c3149edf..46f00bd2a5 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerTest.php @@ -17,7 +17,7 @@ class ContainerTest extends UnitTestCase { */ public function testSerialize() { $container = new Container(); - $this->expectAssertion(); + $this->setExpectedException(\AssertionError::class); serialize($container); } diff --git a/core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php b/core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php index 7234c73896..776b79446d 100644 --- a/core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php +++ b/core/tests/Drupal/Tests/Core/Render/Placeholder/ChainedPlaceholderStrategyTest.php @@ -128,7 +128,7 @@ public function testProcessPlaceholdersNoStrategies() { ]; $chained_placeholder_strategy = new ChainedPlaceholderStrategy(); - $this->expectAssertion('At least one placeholder strategy must be present; by default the fallback strategy \Drupal\Core\Render\Placeholder\SingleFlushStrategy is always present.'); + $this->setExpectedException(\AssertionError::class, 'At least one placeholder strategy must be present; by default the fallback strategy \Drupal\Core\Render\Placeholder\SingleFlushStrategy is always present.'); $chained_placeholder_strategy->processPlaceholders($placeholders); } @@ -152,7 +152,7 @@ public function testProcessPlaceholdersWithRoguePlaceholderStrategy() { $chained_placeholder_strategy = new ChainedPlaceholderStrategy(); $chained_placeholder_strategy->addPlaceholderStrategy($rogue_strategy); - $this->expectAssertion('Processed placeholders must be a subset of all placeholders.'); + $this->setExpectedException(\AssertionError::class, 'Processed placeholders must be a subset of all placeholders.'); $chained_placeholder_strategy->processPlaceholders($placeholders); } diff --git a/core/tests/Drupal/Tests/UnitTestCase.php b/core/tests/Drupal/Tests/UnitTestCase.php index 248a9ed626..bd183c7961 100644 --- a/core/tests/Drupal/Tests/UnitTestCase.php +++ b/core/tests/Drupal/Tests/UnitTestCase.php @@ -19,7 +19,6 @@ abstract class UnitTestCase extends TestCase { use PhpunitCompatibilityTrait; - use AssertHelperTrait; /** * The random generator. diff --git a/core/tests/bootstrap.php b/core/tests/bootstrap.php index 7049b7c680..b74be7ea7f 100644 --- a/core/tests/bootstrap.php +++ b/core/tests/bootstrap.php @@ -175,11 +175,6 @@ function drupal_phpunit_populate_class_loader() { // reduce the fragility of the testing system in general. date_default_timezone_set('Australia/Sydney'); -// THIS LINE MUST BE REMOVED AFTER TEST RUNNERS ARE RECONFIGURED!!! -if (defined('ASSERT_EXCEPTION')) { - assert_options(ASSERT_EXCEPTION, 1); -} - // PHPUnit 4 to PHPUnit 6 bridge. Tests written for PHPUnit 4 need to work on // PHPUnit 6 with a minimum of fuss. if (version_compare($phpunit_version, '6.1', '>=')) {