diff --git a/core/modules/content_moderation/tests/src/Unit/ContentPreprocessTest.php b/core/modules/content_moderation/tests/src/Unit/ContentPreprocessTest.php index 6213934..8084716 100644 --- a/core/modules/content_moderation/tests/src/Unit/ContentPreprocessTest.php +++ b/core/modules/content_moderation/tests/src/Unit/ContentPreprocessTest.php @@ -5,14 +5,14 @@ use Drupal\content_moderation\ContentPreprocess; use Drupal\Core\Routing\CurrentRouteMatch; use Drupal\node\Entity\Node; -use PHPUnit\Framework\TestCase; +use Drupal\Tests\UnitTestCase; /** * @coversDefaultClass \Drupal\content_moderation\ContentPreprocess * * @group content_moderation */ -class ContentPreprocessTest extends TestCase { +class ContentPreprocessTest extends UnitTestCase { /** * @covers ::isLatestVersionPage diff --git a/core/modules/content_moderation/tests/src/Unit/LatestRevisionCheckTest.php b/core/modules/content_moderation/tests/src/Unit/LatestRevisionCheckTest.php index 145d367..412a0ea 100644 --- a/core/modules/content_moderation/tests/src/Unit/LatestRevisionCheckTest.php +++ b/core/modules/content_moderation/tests/src/Unit/LatestRevisionCheckTest.php @@ -9,14 +9,14 @@ use Drupal\node\Entity\Node; use Drupal\content_moderation\Access\LatestRevisionCheck; use Drupal\content_moderation\ModerationInformation; -use PHPUnit\Framework\TestCase; +use Drupal\Tests\UnitTestCase; use Symfony\Component\Routing\Route; /** * @coversDefaultClass \Drupal\content_moderation\Access\LatestRevisionCheck * @group content_moderation */ -class LatestRevisionCheckTest extends TestCase { +class LatestRevisionCheckTest extends UnitTestCase { /** * Test the access check of the LatestRevisionCheck service. diff --git a/core/modules/content_moderation/tests/src/Unit/ModerationInformationTest.php b/core/modules/content_moderation/tests/src/Unit/ModerationInformationTest.php index 2a888ad..57fe761 100644 --- a/core/modules/content_moderation/tests/src/Unit/ModerationInformationTest.php +++ b/core/modules/content_moderation/tests/src/Unit/ModerationInformationTest.php @@ -10,14 +10,14 @@ use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\Core\Session\AccountInterface; use Drupal\content_moderation\ModerationInformation; +use Drupal\Tests\UnitTestCase; use Drupal\workflows\WorkflowInterface; -use PHPUnit\Framework\TestCase; /** * @coversDefaultClass \Drupal\content_moderation\ModerationInformation * @group content_moderation */ -class ModerationInformationTest extends TestCase { +class ModerationInformationTest extends UnitTestCase { /** * Builds a mock user. diff --git a/core/modules/content_moderation/tests/src/Unit/StateTransitionValidationTest.php b/core/modules/content_moderation/tests/src/Unit/StateTransitionValidationTest.php index 85a6e86..b7c3942 100644 --- a/core/modules/content_moderation/tests/src/Unit/StateTransitionValidationTest.php +++ b/core/modules/content_moderation/tests/src/Unit/StateTransitionValidationTest.php @@ -7,17 +7,17 @@ use Drupal\Core\Entity\ContentEntityInterface; use Drupal\Core\Session\AccountInterface; use Drupal\content_moderation\StateTransitionValidation; +use Drupal\Tests\UnitTestCase; use Drupal\workflows\Entity\Workflow; use Drupal\workflows\WorkflowTypeInterface; use Drupal\workflows\WorkflowTypeManager; -use PHPUnit\Framework\TestCase; use Prophecy\Argument; /** * @coversDefaultClass \Drupal\content_moderation\StateTransitionValidation * @group content_moderation */ -class StateTransitionValidationTest extends TestCase { +class StateTransitionValidationTest extends UnitTestCase { /** * Verifies user-aware transition validation. diff --git a/core/modules/migrate/tests/src/Unit/Event/EventBaseTest.php b/core/modules/migrate/tests/src/Unit/Event/EventBaseTest.php index 6457029..b712d31 100644 --- a/core/modules/migrate/tests/src/Unit/Event/EventBaseTest.php +++ b/core/modules/migrate/tests/src/Unit/Event/EventBaseTest.php @@ -3,13 +3,13 @@ namespace Drupal\Tests\migrate\Unit\Event; use Drupal\migrate\Event\EventBase; -use PHPUnit\Framework\TestCase; +use Drupal\Tests\UnitTestCase; /** * @coversDefaultClass \Drupal\migrate\Event\EventBase * @group migrate */ -class EventBaseTest extends TestCase { +class EventBaseTest extends UnitTestCase { /** * Test getMigration method. diff --git a/core/modules/migrate/tests/src/Unit/Event/MigrateImportEventTest.php b/core/modules/migrate/tests/src/Unit/Event/MigrateImportEventTest.php index 3dc4411..d281433 100644 --- a/core/modules/migrate/tests/src/Unit/Event/MigrateImportEventTest.php +++ b/core/modules/migrate/tests/src/Unit/Event/MigrateImportEventTest.php @@ -3,13 +3,13 @@ namespace Drupal\Tests\migrate\Unit\Event; use Drupal\migrate\Event\MigrateImportEvent; -use PHPUnit\Framework\TestCase; +use Drupal\Tests\UnitTestCase; /** * @coversDefaultClass \Drupal\migrate\Event\MigrateImportEvent * @group migrate */ -class MigrateImportEventTest extends TestCase { +class MigrateImportEventTest extends UnitTestCase { /** * Test getMigration method. diff --git a/core/modules/serialization/src/Tests/RegisterSerializationClassesCompilerPassTest.php b/core/modules/serialization/src/Tests/RegisterSerializationClassesCompilerPassTest.php index 982c1a9..6d2b598 100644 --- a/core/modules/serialization/src/Tests/RegisterSerializationClassesCompilerPassTest.php +++ b/core/modules/serialization/src/Tests/RegisterSerializationClassesCompilerPassTest.php @@ -4,7 +4,7 @@ use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\serialization\RegisterSerializationClassesCompilerPass; -use PHPUnit\Framework\TestCase; +use Drupal\Tests\UnitTestCase; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\Serializer\Serializer; @@ -12,7 +12,7 @@ * @coversDefaultClass \Drupal\serialization\RegisterSerializationClassesCompilerPass * @group serialization */ -class RegisterSerializationClassesCompilerPassTest extends TestCase { +class RegisterSerializationClassesCompilerPassTest extends UnitTestCase { /** * @covers ::process diff --git a/core/modules/simpletest/simpletest.install b/core/modules/simpletest/simpletest.install index d1d3604..5302288 100644 --- a/core/modules/simpletest/simpletest.install +++ b/core/modules/simpletest/simpletest.install @@ -6,6 +6,7 @@ */ use Drupal\Component\Utility\Environment; +use PHPUnit\Framework\TestCase; /** * Minimum value of PHP memory_limit for SimpleTest. @@ -18,7 +19,7 @@ function simpletest_requirements($phase) { $requirements = []; - $has_phpunit = class_exists('\PHPUnit\Framework\TestCase'); + $has_phpunit = class_exists(TestCase::class); $has_curl = function_exists('curl_init'); $open_basedir = ini_get('open_basedir'); diff --git a/core/modules/simpletest/simpletest.module b/core/modules/simpletest/simpletest.module index 433f5a1..8b1cc23 100644 --- a/core/modules/simpletest/simpletest.module +++ b/core/modules/simpletest/simpletest.module @@ -13,6 +13,7 @@ use Drupal\Core\Test\TestDatabase; use Drupal\simpletest\TestDiscovery; use Drupal\Tests\Listeners\SimpletestUiPrinter; +use PHPUnit\Framework\TestCase; use Symfony\Component\Process\PhpExecutableFinder; use Drupal\Core\Test\TestStatus; @@ -412,7 +413,7 @@ function _simpletest_batch_operation($test_list_init, $test_id, &$context) { // Perform the next test. $test_class = array_shift($test_list); - if (is_subclass_of($test_class, '\PHPUnit\Framework\TestCase')) { + if (is_subclass_of($test_class, TestCase::class)) { $phpunit_results = simpletest_run_phpunit_tests($test_id, [$test_class]); simpletest_process_phpunit_results($phpunit_results); $test_results[$test_class] = simpletest_summarize_phpunit_result($phpunit_results)[$test_class]; diff --git a/core/modules/simpletest/tests/fixtures/simpletest_phpunit_run_command_test.php b/core/modules/simpletest/tests/fixtures/simpletest_phpunit_run_command_test.php index 9105177..42dadfd 100644 --- a/core/modules/simpletest/tests/fixtures/simpletest_phpunit_run_command_test.php +++ b/core/modules/simpletest/tests/fixtures/simpletest_phpunit_run_command_test.php @@ -2,7 +2,7 @@ namespace Drupal\Tests\simpletest\Unit; -use PHPUnit\Framework\TestCase; +use Drupal\Tests\UnitTestCase; /** * This test crashes PHP. @@ -13,7 +13,7 @@ * * @see \Drupal\Tests\simpletest\Unit\SimpletestPhpunitRunCommandTest::testSimpletestPhpUnitRunCommand() */ -class SimpletestPhpunitRunCommandTestWillDie extends TestCase { +class SimpletestPhpunitRunCommandTestWillDie extends UnitTestCase { /** * Performs the status specified by SimpletestPhpunitRunCommandTestWillDie. diff --git a/core/modules/simpletest/tests/src/Unit/SimpletestPhpunitRunCommandTest.php b/core/modules/simpletest/tests/src/Unit/SimpletestPhpunitRunCommandTest.php index 4e7ad75..63fe1bb 100644 --- a/core/modules/simpletest/tests/src/Unit/SimpletestPhpunitRunCommandTest.php +++ b/core/modules/simpletest/tests/src/Unit/SimpletestPhpunitRunCommandTest.php @@ -9,6 +9,9 @@ /** * Tests simpletest_run_phpunit_tests() handles PHPunit fatals correctly. * + * We don't extend Drupal\Tests\UnitTestCase here because its $root property is + * not static and we need it to be static here. + * * @group simpletest * * @runTestsInSeparateProcesses diff --git a/core/scripts/run-tests.sh b/core/scripts/run-tests.sh index 0c79cb3..714cf3c 100755 --- a/core/scripts/run-tests.sh +++ b/core/scripts/run-tests.sh @@ -17,6 +17,7 @@ use Drupal\simpletest\Form\SimpletestResultsForm; use Drupal\simpletest\TestBase; use Drupal\simpletest\TestDiscovery; +use PHPUnit\Framework\TestCase; use Symfony\Component\HttpFoundation\Request; $autoloader = require_once __DIR__ . '/../../autoload.php'; @@ -36,7 +37,7 @@ const SIMPLETEST_SCRIPT_EXIT_FAILURE = 1; const SIMPLETEST_SCRIPT_EXIT_EXCEPTION = 2; -if (!class_exists('\PHPUnit\Framework\TestCase')) { +if (!class_exists(TestCase::class)) { echo "\nrun-tests.sh requires the PHPUnit testing framework. Please use 'composer install --dev' to ensure that it is present.\n\n"; exit(SIMPLETEST_SCRIPT_EXIT_FAILURE); } @@ -783,7 +784,7 @@ function simpletest_script_run_one_test($test_id, $test_class) { $methods = array(); } $test = new $class_name($test_id); - if (is_subclass_of($test_class, '\PHPUnit\Framework\TestCase')) { + if (is_subclass_of($test_class, TestCase::class)) { $status = simpletest_script_run_phpunit($test_id, $test_class); } else { @@ -865,7 +866,7 @@ function simpletest_script_command($test_id, $test_class) { * @see simpletest_script_run_one_test() */ function simpletest_script_cleanup($test_id, $test_class, $exitcode) { - if (is_subclass_of($test_class, '\PHPUnit\Framework\TestCase')) { + if (is_subclass_of($test_class, TestCase::class)) { // PHPUnit test, move on. return; } @@ -1020,7 +1021,7 @@ function simpletest_script_get_test_list() { else { foreach ($matches[1] as $class_name) { $namespace_class = $namespace . '\\' . $class_name; - if (is_subclass_of($namespace_class, '\Drupal\simpletest\TestBase') || is_subclass_of($namespace_class, '\PHPUnit\Framework\TestCase')) { + if (is_subclass_of($namespace_class, '\Drupal\simpletest\TestBase') || is_subclass_of($namespace_class, TestCase::class)) { $test_list[] = $namespace_class; } } @@ -1074,7 +1075,7 @@ function simpletest_script_get_test_list() { else { foreach ($matches[1] as $class_name) { $namespace_class = $namespace . '\\' . $class_name; - if (is_subclass_of($namespace_class, '\Drupal\simpletest\TestBase') || is_subclass_of($namespace_class, '\PHPUnit\Framework\TestCase')) { + if (is_subclass_of($namespace_class, '\Drupal\simpletest\TestBase') || is_subclass_of($namespace_class, TestCase::class)) { $test_list[] = $namespace_class; } } diff --git a/core/tests/Drupal/Tests/Core/Cache/Context/SessionCacheContextTest.php b/core/tests/Drupal/Tests/Core/Cache/Context/SessionCacheContextTest.php index 7c73eff..9538bd2 100644 --- a/core/tests/Drupal/Tests/Core/Cache/Context/SessionCacheContextTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/Context/SessionCacheContextTest.php @@ -3,7 +3,7 @@ namespace Drupal\Tests\Core\Cache\Context; use Drupal\Core\Cache\Context\SessionCacheContext; -use PHPUnit\Framework\TestCase; +use Drupal\Tests\UnitTestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\RequestStack; @@ -11,7 +11,7 @@ * @coversDefaultClass \Drupal\Core\Cache\Context\SessionCacheContext * @group Cache */ -class SessionCacheContextTest extends TestCase { +class SessionCacheContextTest extends UnitTestCase { /** * The request stack. diff --git a/core/tests/Drupal/Tests/Core/Config/ConfigFactoryOverrideBaseTest.php b/core/tests/Drupal/Tests/Core/Config/ConfigFactoryOverrideBaseTest.php index 21db5e1..f81352f 100644 --- a/core/tests/Drupal/Tests/Core/Config/ConfigFactoryOverrideBaseTest.php +++ b/core/tests/Drupal/Tests/Core/Config/ConfigFactoryOverrideBaseTest.php @@ -6,13 +6,13 @@ use Drupal\Core\Config\ConfigCrudEvent; use Drupal\Core\Config\ConfigFactoryOverrideBase; use Drupal\Core\Config\ConfigRenameEvent; -use PHPUnit\Framework\TestCase; +use Drupal\Tests\UnitTestCase; /** * @coversDefaultClass \Drupal\Core\Config\ConfigFactoryOverrideBase * @group config */ -class ConfigFactoryOverrideBaseTest extends TestCase { +class ConfigFactoryOverrideBaseTest extends UnitTestCase { /** * @dataProvider providerTestFilterNestedArray diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/AuthenticationProviderPassTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/AuthenticationProviderPassTest.php index b9c6432..9fe058a 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/AuthenticationProviderPassTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/Compiler/AuthenticationProviderPassTest.php @@ -4,7 +4,7 @@ use Drupal\Core\DependencyInjection\Compiler\AuthenticationProviderPass; use Drupal\Core\DependencyInjection\ContainerBuilder; -use PHPUnit\Framework\TestCase; +use Drupal\Tests\UnitTestCase; use Symfony\Component\DependencyInjection\Definition; use Symfony\Component\Serializer\Serializer; @@ -12,7 +12,7 @@ * @coversDefaultClass \Drupal\Core\DependencyInjection\Compiler\AuthenticationProviderPass * @group DependencyInjection */ -class AuthenticationProviderPassTest extends TestCase { +class AuthenticationProviderPassTest extends UnitTestCase { /** * @covers ::process diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/YamlFileLoaderTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/YamlFileLoaderTest.php index 9e19cdd..97b2c94 100644 --- a/core/tests/Drupal/Tests/Core/DependencyInjection/YamlFileLoaderTest.php +++ b/core/tests/Drupal/Tests/Core/DependencyInjection/YamlFileLoaderTest.php @@ -5,14 +5,14 @@ use Drupal\Component\FileCache\FileCacheFactory; use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DependencyInjection\YamlFileLoader; +use Drupal\Tests\UnitTestCase; use org\bovigo\vfs\vfsStream; -use PHPUnit\Framework\TestCase; /** * @coversDefaultClass \Drupal\Core\DependencyInjection\YamlFileLoader * @group DependencyInjection */ -class YamlFileLoaderTest extends TestCase { +class YamlFileLoaderTest extends UnitTestCase { /** * {@inheritdoc} diff --git a/core/tests/Drupal/Tests/Core/EventSubscriber/OptionsRequestSubscriberTest.php b/core/tests/Drupal/Tests/Core/EventSubscriber/OptionsRequestSubscriberTest.php index f2d603c..e995616 100644 --- a/core/tests/Drupal/Tests/Core/EventSubscriber/OptionsRequestSubscriberTest.php +++ b/core/tests/Drupal/Tests/Core/EventSubscriber/OptionsRequestSubscriberTest.php @@ -3,7 +3,7 @@ namespace Drupal\Tests\Core\EventSubscriber; use Drupal\Core\EventSubscriber\OptionsRequestSubscriber; -use PHPUnit\Framework\TestCase; +use Drupal\Tests\UnitTestCase; use Symfony\Cmf\Component\Routing\RouteProviderInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\Event\GetResponseEvent; @@ -15,7 +15,7 @@ * @coversDefaultClass \Drupal\Core\EventSubscriber\OptionsRequestSubscriber * @group EventSubscriber */ -class OptionsRequestSubscriberTest extends TestCase { +class OptionsRequestSubscriberTest extends UnitTestCase { /** * @covers ::onRequest diff --git a/core/tests/Drupal/Tests/Core/Routing/MethodFilterTest.php b/core/tests/Drupal/Tests/Core/Routing/MethodFilterTest.php index 9a24550..8a7554d 100644 --- a/core/tests/Drupal/Tests/Core/Routing/MethodFilterTest.php +++ b/core/tests/Drupal/Tests/Core/Routing/MethodFilterTest.php @@ -3,7 +3,7 @@ namespace Drupal\Tests\Core\Routing; use Drupal\Core\Routing\MethodFilter; -use PHPUnit\Framework\TestCase; +use Drupal\Tests\UnitTestCase; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Exception\MethodNotAllowedException; use Symfony\Component\Routing\Route; @@ -13,7 +13,7 @@ * @coversDefaultClass \Drupal\Core\Routing\MethodFilter * @group Routing */ -class MethodFilterTest extends TestCase { +class MethodFilterTest extends UnitTestCase { /** * @covers ::applies