diff --git a/core/lib/Drupal/Core/Test/TestDiscovery.php b/core/lib/Drupal/Core/Test/TestDiscovery.php index a8374f92a225c1746db95445fe9a22230712a289..7bb08ac4a316d197a8bdd3538cf8207dfc006aa4 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 PHPUnit_Util_Test; +use PHPUnit\Util\Test; /** * Discovers available tests. @@ -418,14 +418,14 @@ public static function parseTestClassSummary($doc_comment) { * - module: A list of Drupal module dependencies that are required to * exist. * - * @see PHPUnit_Util_Test::parseTestMethodAnnotations() + * @see \PHPUnit\Util\Test::parseTestMethodAnnotations() * @see http://phpunit.de/manual/current/en/incomplete-and-skipped-tests.html#incomplete-and-skipped-tests.skipping-tests-using-requires */ public static function parseTestClassAnnotations(\ReflectionClass $class) { - $annotations = PHPUnit_Util_Test::parseTestMethodAnnotations($class->getName())['class']; + $annotations = Test::parseTestMethodAnnotations($class->getName())['class']; // @todo Enhance PHPUnit upstream to allow for custom @requires identifiers. - // @see PHPUnit_Util_Test::getRequirements() + // @see \PHPUnit\Util\Test::getRequirements() // @todo Add support for 'PHP', 'OS', 'function', 'extension'. // @see https://www.drupal.org/node/1273478 if (isset($annotations['requires'])) { diff --git a/core/modules/aggregator/tests/src/Unit/Plugin/AggregatorPluginSettingsBaseTest.php b/core/modules/aggregator/tests/src/Unit/Plugin/AggregatorPluginSettingsBaseTest.php index 51525b9814fc56f064d5632f5be063f540325bfc..a6918a2127ff09543c16edac47711840ee887a8d 100644 --- a/core/modules/aggregator/tests/src/Unit/Plugin/AggregatorPluginSettingsBaseTest.php +++ b/core/modules/aggregator/tests/src/Unit/Plugin/AggregatorPluginSettingsBaseTest.php @@ -24,7 +24,7 @@ class AggregatorPluginSettingsBaseTest extends UnitTestCase { /** * The stubbed config factory object. * - * @var \PHPUnit_Framework_MockObject_MockBuilder + * @var \PHPUnit\Framework\MockObject\MockBuilder */ protected $configFactory; @@ -56,7 +56,7 @@ protected function setUp() { ->will($this->returnValue(['aggregator_test' => ['title' => '', 'description' => '']])); } - /** @var \Drupal\Core\Messenger\MessengerInterface|\PHPUnit_Framework_MockObject_MockBuilder $messenger */ + /** @var \Drupal\Core\Messenger\MessengerInterface|\PHPUnit\Framework\MockObject\MockBuilder $messenger */ $messenger = $this->createMock(MessengerInterface::class); $messenger->expects($this->any())->method('addMessage'); diff --git a/core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php b/core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php index 7c1ca1ef9b7bcf138c7435a763345145aee93bc7..03fc213e9d4a59a569567de94e5a05f41f9f4463 100644 --- a/core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php +++ b/core/modules/datetime/tests/src/Kernel/DateTimeItemTest.php @@ -10,6 +10,7 @@ use Drupal\field\Entity\FieldConfig; use Drupal\Tests\field\Kernel\FieldKernelTestBase; use Drupal\field\Entity\FieldStorageConfig; +use PHPUnit\Framework\AssertionFailedError; /** * Tests the new entity API for the date field type. @@ -255,7 +256,7 @@ public function testSetValueProperty() { * @dataProvider datetimeValidationProvider */ public function testDatetimeValidation($value) { - $this->expectException(\PHPUnit_Framework_AssertionFailedError::class); + $this->expectException(AssertionFailedError::class); $this->fieldStorage->setSetting('datetime_type', DateTimeItem::DATETIME_TYPE_DATETIME); $this->fieldStorage->save(); @@ -315,7 +316,7 @@ public function datetimeValidationProvider() { * @dataProvider dateonlyValidationProvider */ public function testDateonlyValidation($value) { - $this->expectException(\PHPUnit_Framework_AssertionFailedError::class); + $this->expectException(AssertionFailedError::class); $this->fieldStorage->setSetting('datetime_type', DateTimeItem::DATETIME_TYPE_DATE); $this->fieldStorage->save(); diff --git a/core/modules/image/tests/src/Kernel/ImageItemTest.php b/core/modules/image/tests/src/Kernel/ImageItemTest.php index bd2c53460d9394ef346860bd5c6a71188f528fe0..5f095bb8a818b4eccc36896d4b33469b559fb457 100644 --- a/core/modules/image/tests/src/Kernel/ImageItemTest.php +++ b/core/modules/image/tests/src/Kernel/ImageItemTest.php @@ -12,6 +12,7 @@ use Drupal\field\Entity\FieldStorageConfig; use Drupal\file\Entity\File; use Drupal\user\Entity\Role; +use PHPUnit\Framework\Error\Warning; /** * Tests using entity fields of the image field type. @@ -153,7 +154,7 @@ public function testImageItemMalformed() { $this->fail('Exception did not fail'); } catch (EntityStorageException $exception) { - $this->assertInstanceOf(\PHPUnit_Framework_Error_Warning::class, $exception->getPrevious()); + $this->assertInstanceOf(Warning::class, $exception->getPrevious()); $this->assertEquals($exception->getMessage(), 'Missing file with ID 9999.'); $this->assertEmpty($entity->image_test->width); $this->assertEmpty($entity->image_test->height); diff --git a/core/modules/locale/tests/src/Unit/LocaleLookupTest.php b/core/modules/locale/tests/src/Unit/LocaleLookupTest.php index e386de3a48c4dfba9471a524dbf9e76714f4eb7b..639e812bd3b82e0b4acac8fb269d2e2236deed26 100644 --- a/core/modules/locale/tests/src/Unit/LocaleLookupTest.php +++ b/core/modules/locale/tests/src/Unit/LocaleLookupTest.php @@ -46,7 +46,7 @@ class LocaleLookupTest extends UnitTestCase { /** * A mocked config factory built with UnitTestCase::getConfigFactoryStub(). * - * @var \Drupal\Core\Config\ConfigFactory|\PHPUnit_Framework_MockObject_MockBuilder + * @var \Drupal\Core\Config\ConfigFactory|\PHPUnit\Framework\MockObject\MockBuilder */ protected $configFactory; diff --git a/core/modules/simpletest/tests/fixtures/phpunit_error.xml b/core/modules/simpletest/tests/fixtures/phpunit_error.xml index 82386aea74c13821acc8f1be813ea564ffb37a54..6a6a1cbc20f204066c515f66325955196b171aeb 100644 --- a/core/modules/simpletest/tests/fixtures/phpunit_error.xml +++ b/core/modules/simpletest/tests/fixtures/phpunit_error.xml @@ -7,7 +7,7 @@ <testsuite name="Drupal\Tests\Core\Cache\NullBackendTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Core/Cache/NullBackendTest.php" namespace="Drupal\Tests\Core\Cache" fullPackage="Drupal.Tests.Core.Cache" tests="0" assertions="0" failures="0" errors="0" time="0.000000"/> <testsuite name="Drupal\Tests\Core\Extension\ModuleHandlerUnitTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerUnitTest.php" namespace="Drupal\Tests\Core\Extension" fullPackage="Drupal.Tests.Core.Extension" tests="1" assertions="0" failures="0" errors="1" time="0.002680"> <testcase name="testloadInclude" class="Drupal\Tests\Core\Extension\ModuleHandlerUnitTest" file="/home/chx/www/system/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerUnitTest.php" line="37" assertions="0" time="0.002680"> - <error type="PHPUnit_Framework_Error_Notice">Drupal\Tests\Core\Extension\ModuleHandlerUnitTest::testloadInclude + <error type="PHPUnit\Framework\Error\Notice">Drupal\Tests\Core\Extension\ModuleHandlerUnitTest::testloadInclude Undefined index: foo /home/chx/www/system/core/lib/Drupal/Core/Extension/ModuleHandler.php:219 @@ -20,19 +20,19 @@ Undefined index: foo <testsuite name="Drupal\Tests\Core\Route\RoleAccessCheckTest" file="/var/www/d8/core/tests/Drupal/Tests/Core/Route/RoleAccessCheckTestkTest.php" namespace="Drupal\Tests\Core\Route" fullPackage="Drupal.Tests.Core.Route" tests="3" assertions="3" failures="3" errors="0" time="0.009176"> <testsuite name="Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess" tests="3" assertions="3" failures="3" errors="0" time="0.009176"> <testcase name="testRoleAccess with data set #0" assertions="1" time="0.004519"> - <failure type="PHPUnit_Framework_ExpectationFailedException">Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess with data set #0 ('role_test_1', array(Drupal\user\Entity\User, Drupal\user\Entity\User)) + <failure type="PHPUnit\Framework\ExpectationFailedException">Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess with data set #0 ('role_test_1', array(Drupal\user\Entity\User, Drupal\user\Entity\User)) Access granted for user with the roles role_test_1 on path: role_test_1 Failed asserting that false is true. </failure> </testcase> <testcase name="testRoleAccess with data set #1" assertions="1" time="0.002354"> - <failure type="PHPUnit_Framework_ExpectationFailedException">Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess with data set #1 ('role_test_2', array(Drupal\user\Entity\User, Drupal\user\Entity\User)) + <failure type="PHPUnit\Framework\ExpectationFailedException">Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess with data set #1 ('role_test_2', array(Drupal\user\Entity\User, Drupal\user\Entity\User)) Access granted for user with the roles role_test_2 on path: role_test_2 Failed asserting that false is true. </failure> </testcase> <testcase name="testRoleAccess with data set #2" assertions="1" time="0.002303"> - <failure type="PHPUnit_Framework_ExpectationFailedException">Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess with data set #2 ('role_test_3', array(Drupal\user\Entity\User)) + <failure type="PHPUnit\Framework\ExpectationFailedException">Drupal\Tests\Core\Route\RoleAccessCheckTest::testRoleAccess with data set #2 ('role_test_3', array(Drupal\user\Entity\User)) Access granted for user with the roles role_test_1, role_test_2 on path: role_test_3 Failed asserting that false is true. </failure> diff --git a/core/modules/system/tests/src/Functional/Menu/BreadcrumbTest.php b/core/modules/system/tests/src/Functional/Menu/BreadcrumbTest.php index 329a5f9c2d33c96e70e634299f58a8dabd782992..5c873477925a19f3cbfb0b95d6dd16b2c9c7898e 100644 --- a/core/modules/system/tests/src/Functional/Menu/BreadcrumbTest.php +++ b/core/modules/system/tests/src/Functional/Menu/BreadcrumbTest.php @@ -7,6 +7,7 @@ use Drupal\node\Entity\NodeType; use Drupal\Tests\BrowserTestBase; use Drupal\user\RoleInterface; +use PHPUnit\Framework\ExpectationFailedException; /** * Tests breadcrumbs functionality. @@ -399,7 +400,7 @@ public function testAssertBreadcrumbTrait() { $this->assertBreadcrumb('menu-test/breadcrumb1', []); $this->fail($message); } - catch (\PHPUnit_Framework_ExpectationFailedException $e) { + catch (ExpectationFailedException $e) { $this->assertTrue(TRUE, $message); } @@ -409,7 +410,7 @@ public function testAssertBreadcrumbTrait() { $this->assertBreadcrumb('menu-test/breadcrumb1', $home); $this->fail($message); } - catch (\PHPUnit_Framework_ExpectationFailedException $e) { + catch (ExpectationFailedException $e) { $this->assertTrue(TRUE, $message); } @@ -426,7 +427,7 @@ public function testAssertBreadcrumbTrait() { $this->assertBreadcrumb('menu-test/breadcrumb1', $trail); $this->fail($message); } - catch (\PHPUnit_Framework_ExpectationFailedException $e) { + catch (ExpectationFailedException $e) { $this->assertTrue(TRUE, $message); } } diff --git a/core/modules/views/tests/src/Kernel/ViewExecutableTest.php b/core/modules/views/tests/src/Kernel/ViewExecutableTest.php index d120856c0fdb4939f91f0cce018ffd2a3ea3c2d6..e59dc8defedbb01cb9e9c3923e42c42539f75a06 100644 --- a/core/modules/views/tests/src/Kernel/ViewExecutableTest.php +++ b/core/modules/views/tests/src/Kernel/ViewExecutableTest.php @@ -20,6 +20,7 @@ use Drupal\views\Plugin\views\pager\PagerPluginBase; use Drupal\views\Plugin\views\query\QueryPluginBase; use Drupal\views_test_data\Plugin\views\display\DisplayTest; +use PHPUnit\Framework\Error\Warning; use Symfony\Component\HttpFoundation\Response; /** @@ -201,7 +202,7 @@ public function testSetDisplayWithInvalidDisplay() { $view->setDisplay('invalid'); $this->fail('Expected error, when setDisplay() called with invalid display ID'); } - catch (\PHPUnit_Framework_Error_Warning $e) { + catch (Warning $e) { $this->assertEquals('setDisplay() called with invalid display ID "invalid".', $e->getMessage()); } diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh index a3e94a42582b1b414dc66ed4603437ec02bab036..26763c3adbe0da0bdb5584d7355749f8d16f14ef 100755 --- a/core/scripts/run-tests.sh +++ b/core/scripts/run-tests.sh @@ -20,7 +20,6 @@ use Drupal\simpletest\Form\SimpletestResultsForm; use Drupal\Core\Test\TestDiscovery; use PHPUnit\Framework\TestCase; -use PHPUnit\Runner\Version; use Symfony\Component\HttpFoundation\Request; // Define some colors for display. @@ -144,14 +143,6 @@ exit(SIMPLETEST_SCRIPT_EXIT_SUCCESS); } -// Ensure we have the correct PHPUnit version for the version of PHP. -if (class_exists('\PHPUnit_Runner_Version')) { - $phpunit_version = \PHPUnit_Runner_Version::id(); -} -else { - $phpunit_version = Version::id(); -} - $test_list = simpletest_script_get_test_list(); // Try to allocate unlimited time to run the tests. diff --git a/core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php b/core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php index 4532880f59d030ab958c2e60775f457b4624d390..76454f741c7698c01ee861f17206123b4e46601d 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/BrowserWithJavascriptTest.php @@ -3,6 +3,7 @@ namespace Drupal\FunctionalJavascriptTests; use Behat\Mink\Driver\GoutteDriver; +use PHPUnit\Framework\AssertionFailedError; /** * Tests if we can execute JavaScript in the browser. @@ -56,7 +57,7 @@ public function testAssertJsCondition() { // We expected the following assertion to fail because the window has been // re-sized to have a width of 500 not 400. - $this->expectException(\PHPUnit_Framework_AssertionFailedError::class); + $this->expectException(AssertionFailedError::class); $this->assertJsCondition($javascript, 100); } diff --git a/core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php b/core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php index 38167417ae69b934cb778d0517077f9e41791998..d677aa8e2d64e54f70eb2b05b7f8ea5c5d8946bb 100644 --- a/core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php +++ b/core/tests/Drupal/FunctionalJavascriptTests/WebDriverTestBase.php @@ -168,7 +168,7 @@ protected function assertElementNotVisible($css_selector, $message = '') { * (optional) A message to display with the assertion. If left blank, a * default message will be displayed. * - * @throws \PHPUnit_Framework_AssertionFailedError + * @throws \PHPUnit\Framework\AssertionFailedError * * @see \Behat\Mink\Driver\DriverInterface::evaluateScript() */ diff --git a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php index f562d4d94092832e7f7aa557331f3fedfc4611b7..3a94bddd76e64f687f4e49108a42bd316de69377 100644 --- a/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php +++ b/core/tests/Drupal/FunctionalTests/BrowserTestBaseTest.php @@ -8,6 +8,7 @@ use Drupal\Core\Url; use Drupal\Tests\BrowserTestBase; use Drupal\Tests\Traits\Core\CronRunTrait; +use PHPUnit\Framework\ExpectationFailedException; /** * Tests BrowserTestBase functionality. @@ -263,7 +264,7 @@ public function testXpathAsserts() { $this->assertFieldByXPath("//input[@id = 'notexisting']"); $this->fail('The "notexisting" field was found.'); } - catch (\PHPUnit_Framework_ExpectationFailedException $e) { + catch (ExpectationFailedException $e) { $this->pass('assertFieldByXPath correctly failed. The "notexisting" field was not found.'); } @@ -279,7 +280,7 @@ public function testXpathAsserts() { $this->assertFieldsByValue($this->xpath("//input[@id = 'edit-name']"), 'not the value'); $this->fail('The "edit-name" field is found with the value "not the value".'); } - catch (\PHPUnit_Framework_ExpectationFailedException $e) { + catch (ExpectationFailedException $e) { $this->pass('The "edit-name" field is not found with the value "not the value".'); } } @@ -320,7 +321,7 @@ public function testFieldAssertsForTextfields() { $this->assertField('invalid_name_and_id'); $this->fail('The "invalid_name_and_id" field was found.'); } - catch (\PHPUnit_Framework_ExpectationFailedException $e) { + catch (ExpectationFailedException $e) { $this->pass('assertField correctly failed. The "invalid_name_and_id" field was not found.'); } @@ -359,7 +360,7 @@ public function testFieldAssertsForTextfields() { $this->assertFieldById('edit-name'); $this->fail('The "edit-name" field with no value was found.'); } - catch (\PHPUnit_Framework_ExpectationFailedException $e) { + catch (ExpectationFailedException $e) { $this->pass('The "edit-name" field with no value was not found.'); } @@ -368,7 +369,7 @@ public function testFieldAssertsForTextfields() { $this->assertFieldById('edit-name', 'not the value'); $this->fail('The "name" field was found, using the wrong value.'); } - catch (\PHPUnit_Framework_ExpectationFailedException $e) { + catch (ExpectationFailedException $e) { $this->pass('The "name" field was not found, using the wrong value.'); } @@ -409,7 +410,7 @@ public function testFieldAssertsForTextfields() { $this->assertFieldByName('non-existing-name'); $this->fail('The "non-existing-name" field was found.'); } - catch (\PHPUnit_Framework_ExpectationFailedException $e) { + catch (ExpectationFailedException $e) { $this->pass('The "non-existing-name" field was not found'); } @@ -418,7 +419,7 @@ public function testFieldAssertsForTextfields() { $this->assertFieldByName('name', 'not the value'); $this->fail('The "name" field with incorrect value was found.'); } - catch (\PHPUnit_Framework_ExpectationFailedException $e) { + catch (ExpectationFailedException $e) { $this->pass('assertFieldByName correctly failed. The "name" field with incorrect value was not found.'); } @@ -473,7 +474,7 @@ public function testFieldAssertsForOptions() { $this->assertOptionSelected('options', 1); $this->fail('The select option "1" was selected.'); } - catch (\PHPUnit_Framework_ExpectationFailedException $e) { + catch (ExpectationFailedException $e) { $this->pass($e->getMessage()); } @@ -492,7 +493,7 @@ public function testFieldAssertsForButton() { $this->assertFieldById('Save', NULL); $this->fail('The field with id of "Save" was found.'); } - catch (\PHPUnit_Framework_ExpectationFailedException $e) { + catch (ExpectationFailedException $e) { $this->pass($e->getMessage()); } diff --git a/core/tests/Drupal/KernelTests/Core/Config/ConfigInstallTest.php b/core/tests/Drupal/KernelTests/Core/Config/ConfigInstallTest.php index a8d0f660183054658d3321563978772e3fc89f32..c5cee57203618d67ff63ad092af3e1ec27df9c44 100644 --- a/core/tests/Drupal/KernelTests/Core/Config/ConfigInstallTest.php +++ b/core/tests/Drupal/KernelTests/Core/Config/ConfigInstallTest.php @@ -6,6 +6,7 @@ use Drupal\Core\Config\PreExistingConfigException; use Drupal\Core\Config\UnmetDependenciesException; use Drupal\KernelTests\KernelTestBase; +use PHPUnit\Framework\Error\Warning; /** * Tests installation of configuration objects in installation functionality. @@ -257,7 +258,7 @@ public function testLanguage() { * Tests installing configuration where the filename and ID do not match. */ public function testIdMisMatch() { - $this->expectException(\PHPUnit_Framework_Error_Warning::class); + $this->expectException(Warning::class); $this->expectExceptionMessage('The configuration name "config_test.dynamic.no_id_match" does not match the ID "does_not_match"'); $this->installModules(['config_test_id_mismatch']); } diff --git a/core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php b/core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php index c93069c8e404d27a8677018c9fcaebb544fb25c7..83631e5df37261beb55ebabd4c6a181623d0d3f0 100644 --- a/core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php +++ b/core/tests/Drupal/KernelTests/Core/Test/BrowserTestBaseTest.php @@ -5,6 +5,7 @@ use Drupal\FunctionalTests\BrowserMissingDependentModuleMethodTest; use Drupal\FunctionalTests\BrowserMissingDependentModuleTest; use Drupal\KernelTests\KernelTestBase; +use PHPUnit\Framework\SkippedTestError; /** * @group Test @@ -36,7 +37,7 @@ public function testMethodRequiresModule() { $stub_test->publicCheckRequirements(); $this->fail('Missing required module throws skipped test exception.'); } - catch (\PHPUnit_Framework_SkippedTestError $e) { + catch (SkippedTestError $e) { $this->assertEqual('Required modules: module_does_not_exist', $e->getMessage()); } } @@ -63,7 +64,7 @@ public function testRequiresModule() { $stub_test->publicCheckRequirements(); $this->fail('Missing required module throws skipped test exception.'); } - catch (\PHPUnit_Framework_SkippedTestError $e) { + catch (SkippedTestError $e) { $this->assertEqual('Required modules: module_does_not_exist', $e->getMessage()); } } diff --git a/core/tests/Drupal/KernelTests/KernelTestBase.php b/core/tests/Drupal/KernelTests/KernelTestBase.php index f89aa4d9b00ec5bc57db56806809c6101f84eeb2..e2d1c17f3bf71366c083e91fdfc81c01dd504ce8 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBase.php +++ b/core/tests/Drupal/KernelTests/KernelTestBase.php @@ -22,6 +22,7 @@ use Drupal\Tests\PhpunitCompatibilityTrait; use Drupal\Tests\RandomGeneratorTrait; use Drupal\Tests\TestRequirementsTrait; +use PHPUnit\Framework\Exception; use PHPUnit\Framework\TestCase; use Symfony\Component\DependencyInjection\Reference; use Symfony\Component\HttpFoundation\Request; @@ -477,7 +478,7 @@ protected function initFileCache() { * @return \Drupal\Core\Extension\Extension[] * Extension objects for $modules, keyed by module name. * - * @throws \PHPUnit_Framework_Exception + * @throws \PHPUnit\Framework\Exception * If a module is not available. * * @see \Drupal\Tests\KernelTestBase::enableModules() @@ -490,7 +491,7 @@ private function getExtensionsForModules(array $modules) { $list = $discovery->scan('module'); foreach ($modules as $name) { if (!isset($list[$name])) { - throw new \PHPUnit_Framework_Exception("Unavailable module: '$name'. If this module needs to be downloaded separately, annotate the test class with '@requires module $name'."); + throw new Exception("Unavailable module: '$name'. If this module needs to be downloaded separately, annotate the test class with '@requires module $name'."); } $extensions[$name] = $list[$name]; } diff --git a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php index 05037bb208ad3643b31b1f4e07d4e11376d772de..426fa8bb2701a2b29ec2af545413bd00042407c2 100644 --- a/core/tests/Drupal/KernelTests/KernelTestBaseTest.php +++ b/core/tests/Drupal/KernelTests/KernelTestBaseTest.php @@ -6,6 +6,7 @@ use Drupal\Core\Database\Database; use org\bovigo\vfs\vfsStream; use org\bovigo\vfs\visitor\vfsStreamStructureVisitor; +use PHPUnit\Framework\SkippedTestError; /** * @coversDefaultClass \Drupal\KernelTests\KernelTestBase @@ -249,7 +250,7 @@ public function testMethodRequiresModule() { $stub_test->publicCheckRequirements(); $this->fail('Missing required module throws skipped test exception.'); } - catch (\PHPUnit_Framework_SkippedTestError $e) { + catch (SkippedTestError $e) { $this->assertEqual('Required modules: module_does_not_exist', $e->getMessage()); } } @@ -276,7 +277,7 @@ public function testRequiresModule() { $stub_test->publicCheckRequirements(); $this->fail('Missing required module throws skipped test exception.'); } - catch (\PHPUnit_Framework_SkippedTestError $e) { + catch (SkippedTestError $e) { $this->assertEqual('Required modules: module_does_not_exist', $e->getMessage()); } } diff --git a/core/tests/Drupal/Tests/Component/Diff/Engine/DiffOpTest.php b/core/tests/Drupal/Tests/Component/Diff/Engine/DiffOpTest.php index f7f17f39c6fad1411b56497e9496a3bf8d5ab7ea..be2054811ea93b3d25e0b0c8c71333c6c8c4b582 100644 --- a/core/tests/Drupal/Tests/Component/Diff/Engine/DiffOpTest.php +++ b/core/tests/Drupal/Tests/Component/Diff/Engine/DiffOpTest.php @@ -25,12 +25,7 @@ class DiffOpTest extends TestCase { * @covers ::reverse */ public function testReverse() { - if (method_exists($this, 'expectException')) { - $this->expectException(Error::class); - } - else { - $this->expectException(\PHPUnit_Framework_Error::class); - } + $this->expectException(Error::class); $op = new DiffOp(); $result = $op->reverse(); } diff --git a/core/tests/Drupal/Tests/Component/DrupalComponentTest.php b/core/tests/Drupal/Tests/Component/DrupalComponentTest.php index 6b08cd94eb49eabdce57c54e8043a64e835a58d2..6f9d149a9b442957c547ab632a34a61d7f7467b9 100644 --- a/core/tests/Drupal/Tests/Component/DrupalComponentTest.php +++ b/core/tests/Drupal/Tests/Component/DrupalComponentTest.php @@ -3,6 +3,7 @@ namespace Drupal\Tests\Component; use org\bovigo\vfs\vfsStream; +use PHPUnit\Framework\AssertionFailedError; use PHPUnit\Framework\TestCase; /** @@ -144,7 +145,7 @@ public function testAssertNoCoreUseage($expected_pass, $file_data) { $pass = TRUE; $this->assertNoCoreUsage($file_uri); } - catch (\PHPUnit_Framework_AssertionFailedError $e) { + catch (AssertionFailedError $e) { $pass = FALSE; } $this->assertEquals($expected_pass, $pass, $expected_pass ? diff --git a/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php b/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php index 357f4e05f4ea0dc46076433deda051eccac1bbb6..891a1dcceb9a7346a780cdb7e7faa726df8aa25d 100644 --- a/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php +++ b/core/tests/Drupal/Tests/Component/PhpStorage/FileStorageTest.php @@ -99,14 +99,8 @@ public function testCreateDirectoryFailWarning() { 'bin' => 'test', ]); $code = "<?php\n echo 'here';"; - if (method_exists($this, 'expectException')) { - $this->expectException(Warning::class); - $this->expectExceptionMessage('mkdir(): Permission Denied'); - } - else { - $this->expectException(\PHPUnit_Framework_Error_Warning::class); - $this->expectExceptionMessage('mkdir(): Permission Denied'); - } + $this->expectException(Warning::class); + $this->expectExceptionMessage('mkdir(): Permission Denied'); $storage->save('subdirectory/foo.php', $code); } diff --git a/core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php b/core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php index ec01d4e26f961b3b9ac60e062e015f6cda389f32..b8656528099482b117786a106e36974012884c96 100644 --- a/core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php +++ b/core/tests/Drupal/Tests/Core/Assert/AssertLegacyTraitTest.php @@ -9,7 +9,7 @@ use Drupal\FunctionalTests\AssertLegacyTrait; use Drupal\Tests\UnitTestCase; use Drupal\Tests\WebAssert; -use PHPUnit_Framework_ExpectationFailedException; +use PHPUnit\Framework\ExpectationFailedException; /** * @coversDefaultClass \Drupal\FunctionalTests\AssertLegacyTrait @@ -66,7 +66,7 @@ public function testAssertUniqueText() { */ public function testAssertUniqueTextFail() { $this->page->getText()->willReturn('foo bar bar'); - $this->expectException(PHPUnit_Framework_ExpectationFailedException::class); + $this->expectException(ExpectationFailedException::class); $this->assertUniqueText('bar'); } @@ -75,7 +75,7 @@ public function testAssertUniqueTextFail() { */ public function testAssertUniqueTextUnknown() { $this->page->getText()->willReturn('foo bar bar'); - $this->expectException(PHPUnit_Framework_ExpectationFailedException::class); + $this->expectException(ExpectationFailedException::class); $this->assertUniqueText('alice'); } @@ -102,7 +102,7 @@ public function testAssertNoUniqueText() { */ public function testAssertNoUniqueTextFail() { $this->page->getText()->willReturn('foo bar bar'); - $this->expectException(PHPUnit_Framework_ExpectationFailedException::class); + $this->expectException(ExpectationFailedException::class); $this->assertNoUniqueText('foo'); } @@ -111,7 +111,7 @@ public function testAssertNoUniqueTextFail() { */ public function testAssertNoUniqueTextUnknown() { $this->page->getText()->willReturn('foo bar bar'); - $this->expectException(PHPUnit_Framework_ExpectationFailedException::class); + $this->expectException(ExpectationFailedException::class); $this->assertNoUniqueText('alice'); } @@ -150,7 +150,7 @@ public function testAssertOptionSelectedFail() { ->optionExists('myselect', 'two') ->willReturn($option_field->reveal()); - $this->expectException(PHPUnit_Framework_ExpectationFailedException::class); + $this->expectException(ExpectationFailedException::class); $this->assertOptionSelected('myselect', 'two'); } diff --git a/core/tests/Drupal/Tests/Core/Config/ConfigTest.php b/core/tests/Drupal/Tests/Core/Config/ConfigTest.php index fb620f4ade0d5b5669168f5da80fbe9628990b47..a59ebf5e76cef42d23b510cd3b7f217bf72349b4 100644 --- a/core/tests/Drupal/Tests/Core/Config/ConfigTest.php +++ b/core/tests/Drupal/Tests/Core/Config/ConfigTest.php @@ -7,6 +7,7 @@ use Drupal\Tests\UnitTestCase; use Drupal\Core\Config\Config; use Drupal\Core\Config\ConfigValueException; +use PHPUnit\Framework\Error\Warning; /** * Tests the Config. @@ -269,7 +270,7 @@ public function testSetIllegalOffsetValue() { $this->config->set('testData', 1); // Attempt to treat the single value as a nested item. - $this->expectException(\PHPUnit_Framework_Error_Warning::class); + $this->expectException(Warning::class); $this->config->set('testData.illegalOffset', 1); } diff --git a/core/tests/Drupal/Tests/Core/Database/ConditionTest.php b/core/tests/Drupal/Tests/Core/Database/ConditionTest.php index 29a5aabfa85a74e3ad92a7a1785baacbbe61dfcd..c38261b86626ab0a3539a5b12746cd6c59d897c5 100644 --- a/core/tests/Drupal/Tests/Core/Database/ConditionTest.php +++ b/core/tests/Drupal/Tests/Core/Database/ConditionTest.php @@ -7,6 +7,7 @@ use Drupal\Core\Database\Query\PlaceholderInterface; use Drupal\Tests\UnitTestCase; use Prophecy\Argument; +use PHPUnit\Framework\Error\Error; /** * @coversDefaultClass \Drupal\Core\Database\Query\Condition @@ -161,7 +162,7 @@ public function testCompileWithSqlInjectionForOperator($operator) { $condition = new Condition('AND'); $condition->condition('name', 'value', $operator); - $this->expectException(\PHPUnit_Framework_Error::class); + $this->expectException(Error::class); $condition->compile($connection, $query_placeholder); } diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php index 2c582d0c123ad477710ea96a7d747ac25ef4e435..ac06bbf266fa7ade31ca6a71a3778a1da7f25758 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/RedirectResponseSubscriberTest.php @@ -6,6 +6,7 @@ use Drupal\Core\Routing\TrustedRedirectResponse; use Drupal\Core\Utility\UnroutedUrlAssemblerInterface; use Drupal\Tests\UnitTestCase; +use PHPUnit\Framework\Error\Error; use Symfony\Component\DependencyInjection\Container; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -123,7 +124,7 @@ public function testDestinationRedirectToExternalUrl($request, $expected) { $listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext); $dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'checkRedirectUrl']); $event = new FilterResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response); - $this->expectException(\PHPUnit_Framework_Error::class); + $this->expectException(Error::class); $dispatcher->dispatch(KernelEvents::RESPONSE, $event); } @@ -171,7 +172,7 @@ public function testDestinationRedirectWithInvalidUrl(Request $request) { $listener = new RedirectResponseSubscriber($this->urlAssembler, $this->requestContext); $dispatcher->addListener(KernelEvents::RESPONSE, [$listener, 'checkRedirectUrl']); $event = new FilterResponseEvent($kernel, $request, HttpKernelInterface::SUB_REQUEST, $response); - $this->expectException(\PHPUnit_Framework_Error::class); + $this->expectException(Error::class); $dispatcher->dispatch(KernelEvents::RESPONSE, $event); } diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php index aee20d08b3fa09244de2d04595b118e5463eed7f..0aa466bddc48893db289ac8727b489c816f80f63 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/SpecialAttributesRouteSubscriberTest.php @@ -5,6 +5,7 @@ use Drupal\Core\EventSubscriber\SpecialAttributesRouteSubscriber; use Drupal\Core\Routing\RouteBuildEvent; use Drupal\Tests\UnitTestCase; +use PHPUnit\Framework\Error\Warning; use Symfony\Cmf\Component\Routing\RouteObjectInterface; use Symfony\Component\Routing\Route; use Symfony\Component\Routing\RouteCollection; @@ -98,7 +99,7 @@ public function testOnRouteBuildingInvalidVariables(Route $route) { $event = new RouteBuildEvent($route_collection, 'test'); $subscriber = new SpecialAttributesRouteSubscriber(); - $this->expectException(\PHPUnit_Framework_Error_Warning::class); + $this->expectException(Warning::class); $this->expectExceptionMessage('uses reserved variable names'); $subscriber->onAlterRoutes($event); } diff --git a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php index bb5e98ee90741886a1931dd9550c2dcef5ac578f..c146c04c4f9d58ba466fc44f845498fca45e054b 100644 --- a/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php +++ b/core/tests/Drupal/Tests/Core/Menu/ContextualLinkManagerTest.php @@ -7,6 +7,7 @@ use Drupal\Core\Language\Language; use Drupal\Core\Menu\ContextualLinkDefault; use Drupal\Tests\UnitTestCase; +use PHPUnit\Framework\Constraint\Count; use Symfony\Component\HttpFoundation\RequestStack; /** @@ -286,7 +287,7 @@ public function testGetContextualLinksArrayByGroup() { $this->moduleHandler->expects($this->at(1)) ->method('alter') - ->with($this->equalTo('contextual_links'), new \PHPUnit_Framework_Constraint_Count(2), $this->equalTo('group1'), $this->equalTo(['key' => 'value'])); + ->with($this->equalTo('contextual_links'), new Count(2), $this->equalTo('group1'), $this->equalTo(['key' => 'value'])); $result = $this->contextualLinkManager->getContextualLinksArrayByGroup('group1', ['key' => 'value']); $this->assertCount(2, $result); diff --git a/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php index 0aa2de7b64bc2842a719655e9ba26f5fb9225444..ce401b125576fb9928a2c4a2269f6b3b4ad0ed3e 100644 --- a/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php +++ b/core/tests/Drupal/Tests/Core/PathProcessor/PathProcessorTest.php @@ -31,7 +31,7 @@ class PathProcessorTest extends UnitTestCase { /** * The language manager stub used to construct a PathProcessorLanguage object. * - * @var \Drupal\language\ConfigurableLanguageManagerInterface|\PHPUnit_Framework_MockObject_MockBuilder + * @var \Drupal\language\ConfigurableLanguageManagerInterface|\PHPUnit\Framework\MockObject\MockBuilder */ protected $languageManager; diff --git a/core/tests/Drupal/Tests/Core/Plugin/DefaultSingleLazyPluginCollectionTest.php b/core/tests/Drupal/Tests/Core/Plugin/DefaultSingleLazyPluginCollectionTest.php index cd8b384614b51b0c36a7bbdd096369b20ddaf735..807c33ed74d1361ee95918f2c5a36fcbf2573744 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/DefaultSingleLazyPluginCollectionTest.php +++ b/core/tests/Drupal/Tests/Core/Plugin/DefaultSingleLazyPluginCollectionTest.php @@ -5,6 +5,7 @@ use Drupal\Component\Plugin\ConfigurableInterface; use Drupal\Component\Plugin\PluginBase; use Drupal\Core\Plugin\DefaultSingleLazyPluginCollection; +use PHPUnit\Framework\MockObject\Matcher\InvokedRecorder; /** * @coversDefaultClass \Drupal\Core\Plugin\DefaultSingleLazyPluginCollection @@ -15,7 +16,7 @@ class DefaultSingleLazyPluginCollectionTest extends LazyPluginCollectionTestBase /** * {@inheritdoc} */ - protected function setupPluginCollection(\PHPUnit_Framework_MockObject_Matcher_InvokedRecorder $create_count = NULL) { + protected function setupPluginCollection(InvokedRecorder $create_count = NULL) { $definitions = $this->getPluginDefinitions(); $this->pluginInstances['apple'] = new ConfigurablePlugin(['id' => 'apple', 'key' => 'value'], 'apple', $definitions['apple']); $this->pluginInstances['banana'] = new ConfigurablePlugin(['id' => 'banana', 'key' => 'other_value'], 'banana', $definitions['banana']); diff --git a/core/tests/Drupal/Tests/Core/Plugin/LazyPluginCollectionTestBase.php b/core/tests/Drupal/Tests/Core/Plugin/LazyPluginCollectionTestBase.php index 0e103688b41758465fbbd14e29aea6309e6d2d1f..5337468da1c2c53a9807883b05bdd6f41c74e689 100644 --- a/core/tests/Drupal/Tests/Core/Plugin/LazyPluginCollectionTestBase.php +++ b/core/tests/Drupal/Tests/Core/Plugin/LazyPluginCollectionTestBase.php @@ -4,6 +4,7 @@ use Drupal\Core\Plugin\DefaultLazyPluginCollection; use Drupal\Tests\UnitTestCase; +use PHPUnit\Framework\MockObject\Matcher\InvokedRecorder; /** * Provides a base class for plugin collection tests. @@ -53,12 +54,12 @@ protected function setUp() { /** * Sets up the default plugin collection. * - * @param \PHPUnit_Framework_MockObject_Matcher_InvokedRecorder|null $create_count + * @param \PHPUnit\Framework\MockObject\Matcher\InvokedRecorder|null $create_count * (optional) The number of times that createInstance() is expected to be * called. For example, $this->any(), $this->once(), $this->exactly(6). * Defaults to $this->never(). */ - protected function setupPluginCollection(\PHPUnit_Framework_MockObject_Matcher_InvokedRecorder $create_count = NULL) { + protected function setupPluginCollection(InvokedRecorder $create_count = NULL) { $this->pluginInstances = []; $map = []; foreach ($this->getPluginDefinitions() as $plugin_id => $definition) { diff --git a/core/tests/Drupal/Tests/Core/Render/ElementTest.php b/core/tests/Drupal/Tests/Core/Render/ElementTest.php index 9d4342d1d731d1deb81ec5b5baca0ff1e7ac0006..f12dfcf1dd655dcc9aae0eb929cab8e21ab36868 100644 --- a/core/tests/Drupal/Tests/Core/Render/ElementTest.php +++ b/core/tests/Drupal/Tests/Core/Render/ElementTest.php @@ -5,6 +5,7 @@ use Drupal\Core\Access\AccessResult; use Drupal\Tests\UnitTestCase; use Drupal\Core\Render\Element; +use PHPUnit\Framework\Error\Error; /** * @coversDefaultClass \Drupal\Core\Render\Element @@ -106,7 +107,7 @@ public function testInvalidChildren() { $element = [ 'foo' => 'bar', ]; - $this->expectException(\PHPUnit_Framework_Error::class); + $this->expectException(Error::class); $this->expectExceptionMessage('"foo" is an invalid render array key'); Element::children($element); } diff --git a/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php b/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php index 77a2024dddfa58a4e0740e72c34f4c2795bfb936..6e56588f25d7061086b7482dc75cbee9753b327f 100644 --- a/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php +++ b/core/tests/Drupal/Tests/Core/Render/RendererPlaceholdersTest.php @@ -1118,7 +1118,7 @@ protected function generatePlaceholdersWithChildrenTestElement(array $args_1, ar } /** - * @return \Drupal\Core\Theme\ThemeManagerInterface|\PHPUnit_Framework_MockObject_Builder_InvocationMocker + * @return \Drupal\Core\Theme\ThemeManagerInterface|\PHPUnit\Framework\MockObject\Builder\InvocationMocker */ protected function setupThemeManagerForDetails() { return $this->themeManager->expects($this->any()) diff --git a/core/tests/Drupal/Tests/Core/StringTranslation/StringTranslationTraitTest.php b/core/tests/Drupal/Tests/Core/StringTranslation/StringTranslationTraitTest.php index 560675eed883be7b6fcf010796b1f7a425be0a24..5e16fa88e6d5db29f356e6728866941aabc25549 100644 --- a/core/tests/Drupal/Tests/Core/StringTranslation/StringTranslationTraitTest.php +++ b/core/tests/Drupal/Tests/Core/StringTranslation/StringTranslationTraitTest.php @@ -25,7 +25,7 @@ class StringTranslationTraitTest extends UnitTestCase { * The mock under test that uses StringTranslationTrait. * * @var object - * @see PHPUnit_Framework_MockObject_Generator::getObjectForTrait() + * @see \PHPUnit\Framework\MockObject\Generator::getObjectForTrait() */ protected $translation; diff --git a/core/tests/Drupal/Tests/Core/UrlTest.php b/core/tests/Drupal/Tests/Core/UrlTest.php index dcdee870a1e022c84527fee6083476c6c728ce9a..58dbdbd8332d254fe72eb5a0331bfbca4058ede2 100644 --- a/core/tests/Drupal/Tests/Core/UrlTest.php +++ b/core/tests/Drupal/Tests/Core/UrlTest.php @@ -160,7 +160,7 @@ public function testUrlFromRequest() { * @param string $path * The path. * - * @return \PHPUnit_Framework_Constraint_Callback + * @return \PHPUnit\Framework\Constraint\Callback * The constraint checks whether a Request object has the right path. */ protected function getRequestConstraint($path) { diff --git a/core/tests/Drupal/Tests/Listeners/AfterSymfonyListener.php b/core/tests/Drupal/Tests/Listeners/AfterSymfonyListener.php index 121d0d2db24677474ba0059defc56f6a5ed61382..8806decd1cd0ae7b081a98c2e92ab95d4687ad68 100644 --- a/core/tests/Drupal/Tests/Listeners/AfterSymfonyListener.php +++ b/core/tests/Drupal/Tests/Listeners/AfterSymfonyListener.php @@ -6,28 +6,19 @@ use PHPUnit\Framework\TestListener; use PHPUnit\Framework\TestListenerDefaultImplementation; -if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) { - class_alias('Drupal\Tests\Listeners\Legacy\AfterSymfonyListener', 'Drupal\Tests\Listeners\AfterSymfonyListener'); - // Using an early return instead of an else does not work when using the - // PHPUnit phar due to some weird PHP behavior (the class gets defined without - // executing the code before it and so the definition is not properly - // conditional). -} -else { +/** + * Listens to PHPUnit test runs. + * + * @internal + */ +class AfterSymfonyListener implements TestListener { + use TestListenerDefaultImplementation; + /** - * Listens to PHPUnit test runs. - * - * @internal + * {@inheritdoc} */ - class AfterSymfonyListener implements TestListener { - use TestListenerDefaultImplementation; - - /** - * {@inheritdoc} - */ - public function endTest(Test $test, $time) { - restore_error_handler(); - } - + public function endTest(Test $test, $time) { + restore_error_handler(); } + } diff --git a/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php index f26d333cfc06306cc556a4fe661a9d849ac3a58c..3c76756bd5fb0f415f56ac3a5336b2d208f54a66 100644 --- a/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php +++ b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php @@ -4,6 +4,7 @@ use Drupal\Tests\Traits\ExpectDeprecationTrait; use PHPUnit\Framework\TestCase; +use PHPUnit\Util\Test; /** * Removes deprecations that we are yet to fix. @@ -24,7 +25,7 @@ trait DeprecationListenerTrait { private $previousHandler; protected function deprecationStartTest($test) { - if ($test instanceof \PHPUnit_Framework_TestCase || $test instanceof TestCase) { + if ($test instanceof TestCase) { if ('disabled' !== getenv('SYMFONY_DEPRECATIONS_HELPER')) { $this->registerErrorHandler($test); } @@ -37,7 +38,7 @@ protected function deprecationStartTest($test) { /** * Reacts to the end of a test. * - * @param \PHPUnit\Framework\Test|\PHPUnit_Framework_Test $test + * @param \PHPUnit\Framework\Test $test * The test object that has ended its test run. * @param float $time * The time the test took. @@ -52,13 +53,12 @@ protected function deprecationEndTest($test, $time) { } } if ($file = getenv('SYMFONY_DEPRECATIONS_SERIALIZE')) { - $util_test_class = class_exists('PHPUnit_Util_Test') ? 'PHPUnit_Util_Test' : 'PHPUnit\Util\Test'; $method = $test->getName(FALSE); if (strpos($method, 'testLegacy') === 0 || strpos($method, 'provideLegacy') === 0 || strpos($method, 'getLegacy') === 0 || strpos(get_class($test), '\Legacy') - || in_array('legacy', $util_test_class::getGroups(get_class($test), $method), TRUE)) { + || in_array('legacy', Test::getGroups(get_class($test), $method), TRUE)) { // This is a legacy test don't skip deprecations. return; } @@ -83,7 +83,7 @@ protected function deprecationEndTest($test, $time) { /** * Determines if a test is isolated. * - * @param \PHPUnit_Framework_TestCase|\PHPUnit\Framework\TestCase $test + * @param \PHPUnit\Framework\TestCase $test * The test to check. * * @return bool diff --git a/core/tests/Drupal/Tests/Listeners/DrupalComponentTestListenerTrait.php b/core/tests/Drupal/Tests/Listeners/DrupalComponentTestListenerTrait.php index 105d1333c34502fdd40506a09654b1a7e2ece38f..6428bae39c0e6225d71324b7a6d4ab5566aecc17 100644 --- a/core/tests/Drupal/Tests/Listeners/DrupalComponentTestListenerTrait.php +++ b/core/tests/Drupal/Tests/Listeners/DrupalComponentTestListenerTrait.php @@ -17,7 +17,7 @@ trait DrupalComponentTestListenerTrait { /** * Reacts to the end of a test. * - * @param \PHPUnit\Framework\Test|\PHPUnit_Framework_Test $test + * @param \PHPUnit\Framework\Test $test * The test object that has ended its test run. * @param float $time * The time the test took. diff --git a/core/tests/Drupal/Tests/Listeners/DrupalListener.php b/core/tests/Drupal/Tests/Listeners/DrupalListener.php index 3d410ce5585ef42c0fac94c81177754680c6a02d..8b7966a26d658bb74a0ba4af53fd0c021cce8d3c 100644 --- a/core/tests/Drupal/Tests/Listeners/DrupalListener.php +++ b/core/tests/Drupal/Tests/Listeners/DrupalListener.php @@ -6,40 +6,31 @@ use PHPUnit\Framework\TestListener; use PHPUnit\Framework\TestListenerDefaultImplementation; -if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) { - class_alias('Drupal\Tests\Listeners\Legacy\DrupalListener', 'Drupal\Tests\Listeners\DrupalListener'); - // Using an early return instead of a else does not work when using the - // PHPUnit phar due to some weird PHP behavior (the class gets defined without - // executing the code before it and so the definition is not properly - // conditional). -} -else { +/** + * Listens to PHPUnit test runs. + * + * @internal + */ +class DrupalListener implements TestListener { + use TestListenerDefaultImplementation; + use DeprecationListenerTrait; + use DrupalComponentTestListenerTrait; + use DrupalStandardsListenerTrait; + /** - * Listens to PHPUnit test runs. - * - * @internal + * {@inheritdoc} */ - class DrupalListener implements TestListener { - use TestListenerDefaultImplementation; - use DeprecationListenerTrait; - use DrupalComponentTestListenerTrait; - use DrupalStandardsListenerTrait; - - /** - * {@inheritdoc} - */ - public function startTest(Test $test) { - $this->deprecationStartTest($test); - } - - /** - * {@inheritdoc} - */ - public function endTest(Test $test, $time) { - $this->deprecationEndTest($test, $time); - $this->componentEndTest($test, $time); - $this->standardsEndTest($test, $time); - } + public function startTest(Test $test) { + $this->deprecationStartTest($test); + } + /** + * {@inheritdoc} + */ + public function endTest(Test $test, $time) { + $this->deprecationEndTest($test, $time); + $this->componentEndTest($test, $time); + $this->standardsEndTest($test, $time); } + } diff --git a/core/tests/Drupal/Tests/Listeners/DrupalStandardsListenerTrait.php b/core/tests/Drupal/Tests/Listeners/DrupalStandardsListenerTrait.php index 84eaaced06df730e99342c1dc9ba73243c8a7b09..9b633d48332237a48eaf4cd878634416d9674c40 100644 --- a/core/tests/Drupal/Tests/Listeners/DrupalStandardsListenerTrait.php +++ b/core/tests/Drupal/Tests/Listeners/DrupalStandardsListenerTrait.php @@ -5,6 +5,7 @@ use PHPUnit\Framework\AssertionFailedError; use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestSuite; +use PHPUnit\Util\ErrorHandler; /** * Listens for PHPUnit tests and fails those with invalid coverage annotations. @@ -167,8 +168,7 @@ public static function errorHandler($type, $msg, $file, $line, $context = []) { if ($type === E_USER_DEPRECATED) { return; } - $error_handler = class_exists('PHPUnit_Util_ErrorHandler') ? 'PHPUnit_Util_ErrorHandler' : 'PHPUnit\Util\ErrorHandler'; - return $error_handler::handleError($type, $msg, $file, $line, $context); + return ErrorHandler::handleError($type, $msg, $file, $line, $context); } /** @@ -182,7 +182,7 @@ public static function errorHandler($type, $msg, $file, $line, $context = []) { * * @group legacy * - * @param \PHPUnit\Framework\Test|\PHPUnit_Framework_Test $test + * @param \PHPUnit\Framework\Test $test * The test object that has ended its test run. * @param float $time * The time the test took. @@ -190,7 +190,7 @@ public static function errorHandler($type, $msg, $file, $line, $context = []) { * @see http://symfony.com/doc/current/components/phpunit_bridge.html#mark-tests-as-legacy */ private function doEndTest($test, $time) { - // \PHPUnit_Framework_Test does not have any useful methods of its own for + // \PHPUnit\Framework\Test does not have any useful methods of its own for // our purpose, so we have to distinguish between the different known // subclasses. if ($test instanceof TestCase) { @@ -212,16 +212,13 @@ private function doEndTest($test, $time) { /** * Determine if a test object is a test suite regardless of PHPUnit version. * - * @param \PHPUnit\Framework\Test|\PHPUnit_Framework_Test $test + * @param \PHPUnit\Framework\Test $test * The test object to test if it is a test suite. * * @return bool * TRUE if it is a test suite, FALSE if not. */ private function isTestSuite($test) { - if (class_exists('\PHPUnit_Framework_TestSuite') && $test instanceof \PHPUnit_Framework_TestSuite) { - return TRUE; - } if (class_exists('PHPUnit\Framework\TestSuite') && $test instanceof TestSuite) { return TRUE; } @@ -231,7 +228,7 @@ private function isTestSuite($test) { /** * Reacts to the end of a test. * - * @param \PHPUnit\Framework\Test|\PHPUnit_Framework_Test $test + * @param \PHPUnit\Framework\Test $test * The test object that has ended its test run. * @param float $time * The time the test took. diff --git a/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php b/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php index 49618b8172b648bae8ec92df4abf00ea65c86194..b29b11d19df3ae9d5902807e9d48d54f7c0b59a6 100644 --- a/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php +++ b/core/tests/Drupal/Tests/Listeners/HtmlOutputPrinter.php @@ -5,39 +5,30 @@ use PHPUnit\Framework\TestResult; use PHPUnit\TextUI\ResultPrinter; -if (class_exists('PHPUnit_Runner_Version') && version_compare(\PHPUnit_Runner_Version::id(), '6.0.0', '<')) { - class_alias('Drupal\Tests\Listeners\Legacy\HtmlOutputPrinter', 'Drupal\Tests\Listeners\HtmlOutputPrinter'); - // Using an early return instead of a else does not work when using the - // PHPUnit phar due to some weird PHP behavior (the class gets defined without - // executing the code before it and so the definition is not properly - // conditional). -} -else { +/** + * Defines a class for providing html output results for functional tests. + * + * @internal + */ +class HtmlOutputPrinter extends ResultPrinter { + use HtmlOutputPrinterTrait; + /** - * Defines a class for providing html output results for functional tests. - * - * @internal + * {@inheritdoc} */ - class HtmlOutputPrinter extends ResultPrinter { - use HtmlOutputPrinterTrait; - - /** - * {@inheritdoc} - */ - public function __construct($out = NULL, $verbose = FALSE, $colors = self::COLOR_DEFAULT, $debug = FALSE, $numberOfColumns = 80, $reverse = FALSE) { - parent::__construct($out, $verbose, $colors, $debug, $numberOfColumns, $reverse); - - $this->setUpHtmlOutput(); - } + public function __construct($out = NULL, $verbose = FALSE, $colors = self::COLOR_DEFAULT, $debug = FALSE, $numberOfColumns = 80, $reverse = FALSE) { + parent::__construct($out, $verbose, $colors, $debug, $numberOfColumns, $reverse); - /** - * {@inheritdoc} - */ - public function printResult(TestResult $result) { - parent::printResult($result); + $this->setUpHtmlOutput(); + } - $this->printHtmlOutput(); - } + /** + * {@inheritdoc} + */ + public function printResult(TestResult $result) { + parent::printResult($result); + $this->printHtmlOutput(); } + } diff --git a/core/tests/Drupal/Tests/Listeners/Legacy/AfterSymfonyListener.php b/core/tests/Drupal/Tests/Listeners/Legacy/AfterSymfonyListener.php deleted file mode 100644 index fec2d78264d609993a3e7445bec623e0c9ce2660..0000000000000000000000000000000000000000 --- a/core/tests/Drupal/Tests/Listeners/Legacy/AfterSymfonyListener.php +++ /dev/null @@ -1,19 +0,0 @@ -<?php - -namespace Drupal\Tests\Listeners\Legacy; - -/** - * Listens to PHPUnit test runs. - * - * @internal - */ -class AfterSymfonyListener extends \PHPUnit_Framework_BaseTestListener { - - /** - * {@inheritdoc} - */ - public function endTest(\PHPUnit_Framework_Test $test, $time) { - restore_error_handler(); - } - -} diff --git a/core/tests/Drupal/Tests/Listeners/Legacy/DrupalListener.php b/core/tests/Drupal/Tests/Listeners/Legacy/DrupalListener.php deleted file mode 100644 index 1fc603a6f4f17be006350bd807cad1896f1a5760..0000000000000000000000000000000000000000 --- a/core/tests/Drupal/Tests/Listeners/Legacy/DrupalListener.php +++ /dev/null @@ -1,36 +0,0 @@ -<?php - -namespace Drupal\Tests\Listeners\Legacy; - -use Drupal\Tests\Listeners\DeprecationListenerTrait; -use Drupal\Tests\Listeners\DrupalComponentTestListenerTrait; -use Drupal\Tests\Listeners\DrupalStandardsListenerTrait; - -/** - * Listens to PHPUnit test runs. - * - * @internal - * This class is not public Drupal API. - */ -class DrupalListener extends \PHPUnit_Framework_BaseTestListener { - use DeprecationListenerTrait; - use DrupalComponentTestListenerTrait; - use DrupalStandardsListenerTrait; - - /** - * {@inheritdoc} - */ - public function startTest(\PHPUnit_Framework_Test $test) { - $this->deprecationStartTest($test); - } - - /** - * {@inheritdoc} - */ - public function endTest(\PHPUnit_Framework_Test $test, $time) { - $this->deprecationEndTest($test, $time); - $this->componentEndTest($test, $time); - $this->standardsEndTest($test, $time); - } - -} diff --git a/core/tests/Drupal/Tests/Listeners/Legacy/HtmlOutputPrinter.php b/core/tests/Drupal/Tests/Listeners/Legacy/HtmlOutputPrinter.php deleted file mode 100644 index 7a332bc2de0b80b0ccea202256cccf4585ec48ef..0000000000000000000000000000000000000000 --- a/core/tests/Drupal/Tests/Listeners/Legacy/HtmlOutputPrinter.php +++ /dev/null @@ -1,33 +0,0 @@ -<?php - -namespace Drupal\Tests\Listeners\Legacy; - -use Drupal\Tests\Listeners\HtmlOutputPrinterTrait; - -/** - * Defines a class for providing html output results for functional tests. - * - * @internal - */ -class HtmlOutputPrinter extends \PHPUnit_TextUI_ResultPrinter { - use HtmlOutputPrinterTrait; - - /** - * {@inheritdoc} - */ - public function __construct($out = NULL, $verbose = FALSE, $colors = self::COLOR_DEFAULT, $debug = FALSE, $numberOfColumns = 80) { - parent::__construct($out, $verbose, $colors, $debug, $numberOfColumns); - - $this->setUpHtmlOutput(); - } - - /** - * {@inheritdoc} - */ - public function printResult(\PHPUnit_Framework_TestResult $result) { - parent::printResult($result); - - $this->printHtmlOutput(); - } - -} diff --git a/core/tests/Drupal/Tests/Phpunit4CompatibilityTest.php b/core/tests/Drupal/Tests/Phpunit4CompatibilityTest.php new file mode 100644 index 0000000000000000000000000000000000000000..639e6fa35f3e8ae7b24ed6cbb8717bede81866bf --- /dev/null +++ b/core/tests/Drupal/Tests/Phpunit4CompatibilityTest.php @@ -0,0 +1,89 @@ +<?php + +namespace Drupal\Tests; + +/** + * Tests existence of the PHPUnit4 backward compatibility classes. + * + * @group Tests + */ +class Phpunit4CompatibilityTest extends UnitTestCase { + + /** + * Tests existence of \PHPUnit_Framework_AssertionFailedError. + */ + public function testFrameworkAssertionFailedError() { + $this->assertTrue(class_exists('\PHPUnit_Framework_AssertionFailedError')); + } + + /** + * Tests existence of \PHPUnit_Framework_Constraint_Count. + */ + public function testFrameworkConstraintCount() { + $this->assertTrue(class_exists('\PHPUnit_Framework_Constraint_Count')); + } + + /** + * Tests existence of \PHPUnit_Framework_Error. + */ + public function testFrameworkError() { + $this->assertTrue(class_exists('\PHPUnit_Framework_Error')); + } + + /** + * Tests existence of \PHPUnit_Framework_Error_Warning. + */ + public function FrameworkErrorWarning() { + $this->assertTrue(class_exists('\PHPUnit_Framework_Error_Warning')); + } + + /** + * Tests existence of \PHPUnit_Framework_Exception. + */ + public function testFrameworkException() { + $this->assertTrue(class_exists('\PHPUnit_Framework_Exception')); + } + + /** + * Tests existence of \PHPUnit_Framework_ExpectationFailedException. + */ + public function testFrameworkExpectationFailedException() { + $this->assertTrue(class_exists('\PHPUnit_Framework_ExpectationFailedException')); + } + + /** + * Tests existence of \PHPUnit_Framework_MockObject_Matcher_InvokedRecorder. + */ + public function testFrameworkMockObjectMatcherInvokedRecorder() { + $this->assertTrue(class_exists('\PHPUnit_Framework_MockObject_Matcher_InvokedRecorder')); + } + + /** + * Tests existence of \PHPUnit_Framework_SkippedTestError. + */ + public function testFrameworkSkippedTestError() { + $this->assertTrue(class_exists('\PHPUnit_Framework_SkippedTestError')); + } + + /** + * Tests existence of \PHPUnit_Framework_TestCase. + */ + public function testFrameworkTestCase() { + $this->assertTrue(class_exists('\PHPUnit_Framework_TestCase')); + } + + /** + * Tests existence of \PHPUnit_Util_Test. + */ + public function testUtilTest() { + $this->assertTrue(class_exists('\PHPUnit_Util_Test')); + } + + /** + * Tests existence of \PHPUnit_Util_XML. + */ + public function testUtilXml() { + $this->assertTrue(class_exists('\PHPUnit_Util_XML')); + } + +} diff --git a/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php b/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php index f7972e1d39b77867e01250c573d72877db102188..4ff7ef00847ad496cbfd0357f81daa9723e84f0f 100644 --- a/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php +++ b/core/tests/Drupal/Tests/PhpunitCompatibilityTrait.php @@ -38,7 +38,6 @@ trait PhpunitCompatibilityTrait { * @param object $proxyTarget * Sets the proxy target. * - * @see \PHPUnit_Framework_TestCase::getMock * @see https://github.com/sebastianbergmann/phpunit/wiki/Release-Announcement-for-PHPUnit-5.4.0 * * @return \PHPUnit_Framework_MockObject_MockObject diff --git a/core/tests/Drupal/Tests/TestRequirementsTrait.php b/core/tests/Drupal/Tests/TestRequirementsTrait.php index 84937ad69c8d67acd76dfe2e420d4c8c495d6dc5..2c320dfaaf61017094d7543bf41edec12aa829ea 100644 --- a/core/tests/Drupal/Tests/TestRequirementsTrait.php +++ b/core/tests/Drupal/Tests/TestRequirementsTrait.php @@ -3,12 +3,13 @@ namespace Drupal\Tests; use Drupal\Core\Extension\ExtensionDiscovery; +use PHPUnit\Framework\SkippedTestError; /** * Allows test classes to require Drupal modules as dependencies. * - * This trait is assumed to be on a subclass of \PHPUnit_Framework_TestCase, and - * overrides \PHPUnit_Framework_TestCase::checkRequirements(). This allows the + * This trait is assumed to be on a subclass of \PHPUnit\Framework\TestCase, and + * overrides \PHPUnit\Framework\TestCase::checkRequirements(). This allows the * test to be marked as skipped before any kernel boot processes have happened. */ trait TestRequirementsTrait { @@ -26,9 +27,9 @@ protected static function getDrupalRoot() { * Check module requirements for the Drupal use case. * * This method is assumed to override - * \PHPUnit_Framework_TestCase::checkRequirements(). + * \PHPUnit\Framework\TestCase::checkRequirements(). * - * @throws \PHPUnit_Framework_SkippedTestError + * @throws \PHPUnit\Framework\SkippedTestError * Thrown when the requirements are not met, and this test should be * skipped. Callers should not catch this exception. */ @@ -59,7 +60,7 @@ protected function checkRequirements() { * @param string[] $annotations * A list of requires annotations from either a method or class annotation. * - * @throws \PHPUnit_Framework_SkippedTestError + * @throws \PHPUnit\Framework\SkippedTestError * Thrown when the requirements are not met, and this test should be * skipped. Callers should not catch this exception. */ @@ -83,7 +84,7 @@ private function checkModuleRequirements($root, array $annotations) { $list = array_keys($discovery->scan('module')); $not_available = array_diff($required_modules, $list); if (!empty($not_available)) { - throw new \PHPUnit_Framework_SkippedTestError('Required modules: ' . implode(', ', $not_available)); + throw new SkippedTestError('Required modules: ' . implode(', ', $not_available)); } } } diff --git a/core/tests/Drupal/Tests/Traits/ExpectDeprecationTrait.php b/core/tests/Drupal/Tests/Traits/ExpectDeprecationTrait.php index 4e47f77fe59866ea45328f79afc5f1347dcb72ca..91452522093c6196114855a3180f36324a76cea8 100644 --- a/core/tests/Drupal/Tests/Traits/ExpectDeprecationTrait.php +++ b/core/tests/Drupal/Tests/Traits/ExpectDeprecationTrait.php @@ -4,7 +4,9 @@ use Symfony\Bridge\PhpUnit\Legacy\SymfonyTestsListener as LegacySymfonyTestsListener; use Symfony\Bridge\PhpUnit\SymfonyTestsListener; +use PHPUnit\Framework\AssertionFailedError; use PHPUnit\Framework\TestCase; +use PHPUnit\Util\Test; /** * Adds the ability to dynamically set expected deprecation messages in tests. @@ -34,19 +36,11 @@ protected function expectDeprecation($message) { * The expected deprecation messages. */ public function expectedDeprecations(array $messages) { - if (class_exists('PHPUnit_Util_Test', FALSE)) { - $test_util = 'PHPUnit_Util_Test'; - $assertion_failed_error = 'PHPUnit_Framework_AssertionFailedError'; - } - else { - $test_util = 'PHPUnit\Util\Test'; - $assertion_failed_error = 'PHPUnit\Framework\AssertionFailedError'; - } - if ($this instanceof \PHPUnit_Framework_TestCase || $this instanceof TestCase) { + if ($this instanceof TestCase) { // Ensure the class or method is in the legacy group. - $groups = $test_util::getGroups(get_class($this), $this->getName(FALSE)); + $groups = Test::getGroups(get_class($this), $this->getName(FALSE)); if (!in_array('legacy', $groups, TRUE)) { - throw new $assertion_failed_error('Only tests with the `@group legacy` annotation can call `setExpectedDeprecation()`.'); + throw new AssertionFailedError('Only tests with the `@group legacy` annotation can call `setExpectedDeprecation()`.'); } // If setting an expected deprecation there is no need to be strict about @@ -89,7 +83,7 @@ public function expectedDeprecations(array $messages) { return; } - throw new $assertion_failed_error('Can not set an expected deprecation message because the Symfony\Bridge\PhpUnit\SymfonyTestsListener is not registered as a PHPUnit test listener.'); + throw new AssertionFailedError('Can not set an expected deprecation message because the Symfony\Bridge\PhpUnit\SymfonyTestsListener is not registered as a PHPUnit test listener.'); } /** diff --git a/core/tests/Drupal/Tests/UnitTestCase.php b/core/tests/Drupal/Tests/UnitTestCase.php index bd183c7961746a48a0a2ee75f0602875683a7e14..b8e75799898ddf2edff264201c7132cfbcfab995 100644 --- a/core/tests/Drupal/Tests/UnitTestCase.php +++ b/core/tests/Drupal/Tests/UnitTestCase.php @@ -104,7 +104,7 @@ protected function assertArrayEquals(array $expected, array $actual, $message = * configuration object names and whose values are key => value arrays for * the configuration object in question. Defaults to an empty array. * - * @return \PHPUnit_Framework_MockObject_MockBuilder + * @return \PHPUnit\Framework\MockObject\MockBuilder * A MockBuilder object for the ConfigFactory with the desired return * values. */ diff --git a/core/tests/bootstrap.php b/core/tests/bootstrap.php index 7a707472730b2fd876529db67506ef8616942b93..3ea857115efb5557fc7d90fa9ec701de3fe78cbb 100644 --- a/core/tests/bootstrap.php +++ b/core/tests/bootstrap.php @@ -8,7 +8,17 @@ */ use Drupal\Component\Assertion\Handle; -use PHPUnit\Runner\Version; +use PHPUnit\Framework\AssertionFailedError; +use PHPUnit\Framework\Constraint\Count; +use PHPUnit\Framework\Error\Error; +use PHPUnit\Framework\Error\Warning; +use PHPUnit\Framework\ExpectationFailedException; +use PHPUnit\Framework\Exception; +use PHPUnit\Framework\MockObject\Matcher\InvokedRecorder; +use PHPUnit\Framework\SkippedTestError; +use PHPUnit\Framework\TestCase; +use PHPUnit\Util\Test; +use PHPUnit\Util\Xml; /** * Finds all valid extension directories recursively within a given directory. @@ -151,14 +161,6 @@ function drupal_phpunit_populate_class_loader() { // Do class loader population. drupal_phpunit_populate_class_loader(); -// Ensure we have the correct PHPUnit version for the version of PHP. -if (class_exists('\PHPUnit_Runner_Version')) { - $phpunit_version = \PHPUnit_Runner_Version::id(); -} -else { - $phpunit_version = Version::id(); -} - // Set sane locale settings, to ensure consistent string, dates, times and // numbers handling. // @see \Drupal\Core\DrupalKernel::bootEnvironment() @@ -183,16 +185,15 @@ function drupal_phpunit_populate_class_loader() { // 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', '>=')) { - class_alias('\PHPUnit\Framework\AssertionFailedError', '\PHPUnit_Framework_AssertionFailedError'); - class_alias('\PHPUnit\Framework\Constraint\Count', '\PHPUnit_Framework_Constraint_Count'); - class_alias('\PHPUnit\Framework\Error\Error', '\PHPUnit_Framework_Error'); - class_alias('\PHPUnit\Framework\Error\Warning', '\PHPUnit_Framework_Error_Warning'); - class_alias('\PHPUnit\Framework\ExpectationFailedException', '\PHPUnit_Framework_ExpectationFailedException'); - class_alias('\PHPUnit\Framework\Exception', '\PHPUnit_Framework_Exception'); - class_alias('\PHPUnit\Framework\MockObject\Matcher\InvokedRecorder', '\PHPUnit_Framework_MockObject_Matcher_InvokedRecorder'); - class_alias('\PHPUnit\Framework\SkippedTestError', '\PHPUnit_Framework_SkippedTestError'); - class_alias('\PHPUnit\Framework\TestCase', '\PHPUnit_Framework_TestCase'); - class_alias('\PHPUnit\Util\Test', '\PHPUnit_Util_Test'); - class_alias('\PHPUnit\Util\Xml', '\PHPUnit_Util_XML'); -} +// @todo provided for BC; remove in Drupal 9. +class_alias(AssertionFailedError::class, '\PHPUnit_Framework_AssertionFailedError'); +class_alias(Count::class, '\PHPUnit_Framework_Constraint_Count'); +class_alias(Error::class, '\PHPUnit_Framework_Error'); +class_alias(Warning::class, '\PHPUnit_Framework_Error_Warning'); +class_alias(ExpectationFailedException::class, '\PHPUnit_Framework_ExpectationFailedException'); +class_alias(Exception::class, '\PHPUnit_Framework_Exception'); +class_alias(InvokedRecorder::class, '\PHPUnit_Framework_MockObject_Matcher_InvokedRecorder'); +class_alias(SkippedTestError::class, '\PHPUnit_Framework_SkippedTestError'); +class_alias(TestCase::class, '\PHPUnit_Framework_TestCase'); +class_alias(Test::class, '\PHPUnit_Util_Test'); +class_alias(Xml::class, '\PHPUnit_Util_XML');