From 33bbcaa01e9018fd2183f4b263210bf7eafaa720 Mon Sep 17 00:00:00 2001 From: jurgenhaas <juergen.haas@lakedrops.com> Date: Tue, 25 Jun 2024 10:19:20 +0200 Subject: [PATCH] Remove deprecated testsuite classes and replace them in default config with testsuites from Drupal core --- src/TestSuite/Base.php | 62 -------------------------- src/TestSuite/Functional.php | 35 --------------- src/TestSuite/FunctionalJavascript.php | 35 --------------- src/TestSuite/Kernel.php | 35 --------------- src/TestSuite/Unit.php | 35 --------------- templates/tests/phpunit.xml.dist | 11 +++-- 6 files changed, 7 insertions(+), 206 deletions(-) delete mode 100644 src/TestSuite/Base.php delete mode 100644 src/TestSuite/Functional.php delete mode 100644 src/TestSuite/FunctionalJavascript.php delete mode 100644 src/TestSuite/Kernel.php delete mode 100644 src/TestSuite/Unit.php diff --git a/src/TestSuite/Base.php b/src/TestSuite/Base.php deleted file mode 100644 index a4e4176..0000000 --- a/src/TestSuite/Base.php +++ /dev/null @@ -1,62 +0,0 @@ -<?php - -namespace LakeDrops\DrupalDevelopmentEnvironment\TestSuite; - -require_once 'web/core/tests/TestSuites/TestSuiteBase.php'; - -use Drupal\Core\Test\TestDiscovery; -use Drupal\Tests\TestSuites\TestSuiteBase; - -/** - * Base class for Drupal test suites. - */ -abstract class Base extends TestSuiteBase { - - /** - * Unused variable to allow for otherwise useless __construct overrides. - * - * @var string - */ - protected string $internalTestType; - - /** - * Finds extensions in a Drupal installation. - * - * An extension is defined as a directory with an *.info.yml file in it. - * - * @param string $root - * Path to the root of the Drupal installation. - * - * @return string[] - * Associative array of extension paths, with extension name as keys. - */ - protected function findExtensionDirectories($root): array { - $paths = [ - $root . '/modules/custom', - $root . '/profiles/custom', - $root . '/themes/custom', - ]; - $extension_roots = array_filter($paths, 'file_exists'); - - $extension_directories = array_map('drupal_phpunit_find_extension_directories', $extension_roots); - return array_reduce($extension_directories, 'array_merge', []); - } - - /** - * Find and add tests to the suite for core and any extensions. - * - * @param string $root - * Path to the root of the Drupal installation. - * @param string $suite_namespace - * SubNamespace used to separate test suite. Examples: Unit, Functional. - */ - protected function addTestsBySuiteNamespace($root, $suite_namespace): void { - foreach ($this->findExtensionDirectories($root) as $extension_name => $dir) { - $test_path = "$dir/tests/src/$suite_namespace"; - if (is_dir($test_path)) { - $this->addTestFiles(TestDiscovery::scanDirectory("Drupal\\Tests\\$extension_name\\$suite_namespace\\", $test_path)); - } - } - } - -} diff --git a/src/TestSuite/Functional.php b/src/TestSuite/Functional.php deleted file mode 100644 index a717897..0000000 --- a/src/TestSuite/Functional.php +++ /dev/null @@ -1,35 +0,0 @@ -<?php - -namespace LakeDrops\DrupalDevelopmentEnvironment\TestSuite; - -require_once __DIR__ . '/Base.php'; - -/** - * Discovers tests for the functional test suite. - */ -class Functional extends Base { - - /** - * {@inheritdoc} - */ - final public function __construct($theClass = '', string $name = '') { - parent::__construct($theClass, $name); - $this->internalTestType = 'functional'; - } - - /** - * Factory method which loads up a suite with all functional tests. - * - * @return static - * The test suite. - */ - public static function suite(): static { - $root = dirname(__DIR__, 5) . '/web'; - - $suite = new static('functional'); - $suite->addTestsBySuiteNamespace($root, 'Functional'); - - return $suite; - } - -} diff --git a/src/TestSuite/FunctionalJavascript.php b/src/TestSuite/FunctionalJavascript.php deleted file mode 100644 index 9d7fdf8..0000000 --- a/src/TestSuite/FunctionalJavascript.php +++ /dev/null @@ -1,35 +0,0 @@ -<?php - -namespace LakeDrops\DrupalDevelopmentEnvironment\TestSuite; - -require_once __DIR__ . '/Base.php'; - -/** - * Discovers tests for the functional test suite. - */ -class FunctionalJavascript extends Base { - - /** - * {@inheritdoc} - */ - final public function __construct($theClass = '', string $name = '') { - parent::__construct($theClass, $name); - $this->internalTestType = 'functional javascript'; - } - - /** - * Factory method which loads up a suite with all functional tests. - * - * @return static - * The test suite. - */ - public static function suite(): static { - $root = dirname(__DIR__, 5) . '/web'; - - $suite = new static('functional-javascript'); - $suite->addTestsBySuiteNamespace($root, 'FunctionalJavascript'); - - return $suite; - } - -} diff --git a/src/TestSuite/Kernel.php b/src/TestSuite/Kernel.php deleted file mode 100644 index 457bdfc..0000000 --- a/src/TestSuite/Kernel.php +++ /dev/null @@ -1,35 +0,0 @@ -<?php - -namespace LakeDrops\DrupalDevelopmentEnvironment\TestSuite; - -require_once __DIR__ . '/Base.php'; - -/** - * Discovers tests for the unit test suite. - */ -class Kernel extends Base { - - /** - * {@inheritdoc} - */ - final public function __construct($theClass = '', string $name = '') { - parent::__construct($theClass, $name); - $this->internalTestType = 'kernel'; - } - - /** - * Factory method which loads up a suite with all unit tests. - * - * @return static - * The test suite. - */ - public static function suite(): static { - $root = dirname(__DIR__, 5) . '/web'; - - $suite = new static('kernel'); - $suite->addTestsBySuiteNamespace($root, 'Kernel'); - - return $suite; - } - -} diff --git a/src/TestSuite/Unit.php b/src/TestSuite/Unit.php deleted file mode 100644 index 4a0d09a..0000000 --- a/src/TestSuite/Unit.php +++ /dev/null @@ -1,35 +0,0 @@ -<?php - -namespace LakeDrops\DrupalDevelopmentEnvironment\TestSuite; - -require_once __DIR__ . '/Base.php'; - -/** - * Discovers tests for the unit test suite. - */ -class Unit extends Base { - - /** - * {@inheritdoc} - */ - final public function __construct($theClass = '', string $name = '') { - parent::__construct($theClass, $name); - $this->internalTestType = 'unit'; - } - - /** - * Factory method which loads up a suite with all unit tests. - * - * @return static - * The test suite. - */ - public static function suite(): static { - $root = dirname(__DIR__, 5) . '/web'; - - $suite = new static('unit'); - $suite->addTestsBySuiteNamespace($root, 'Unit'); - - return $suite; - } - -} diff --git a/templates/tests/phpunit.xml.dist b/templates/tests/phpunit.xml.dist index 529acec..ee2050f 100644 --- a/templates/tests/phpunit.xml.dist +++ b/templates/tests/phpunit.xml.dist @@ -35,16 +35,19 @@ </php> <testsuites> <testsuite name="unit"> - <file>../vendor/lakedrops/drupal-development-environment/src/TestSuite/Unit.php</file> + <file>./tests/TestSuites/UnitTestSuite.php</file> </testsuite> <testsuite name="kernel"> - <file>../vendor/lakedrops/drupal-development-environment/src/TestSuite/Kernel.php</file> + <file>./tests/TestSuites/KernelTestSuite.php</file> </testsuite> <testsuite name="functional"> - <file>../vendor/lakedrops/drupal-development-environment/src/TestSuite/Functional.php</file> + <file>./tests/TestSuites/FunctionalTestSuite.php</file> </testsuite> <testsuite name="functional-javascript"> - <file>../vendor/lakedrops/drupal-development-environment/src/TestSuite/FunctionalJavascript.php</file> + <file>./tests/TestSuites/FunctionalJavascriptTestSuite.php</file> + </testsuite> + <testsuite name="build"> + <file>./tests/TestSuites/BuildTestSuite.php</file> </testsuite> </testsuites> <listeners> -- GitLab