diff --git a/.gitignore b/.gitignore index bd03a951d..dc2fab1cd 100644 --- a/.gitignore +++ b/.gitignore @@ -7,7 +7,8 @@ /runner.yml /phpunit.xml /docker-compose.*.yml -.phpunit.result.cache +/.phpunit.result.cache +/.phpunit.cache/ *.sql phpda.* .phpdoc* diff --git a/composer.json b/composer.json index e7e9ef491..d36f28e07 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ "phpmd/phpmd": "^2.12", "phpstan/phpstan": "^1.10", "phpstan/phpstan-deprecation-rules": "^1.0", - "phpunit/phpunit": "^9.5", + "phpunit/phpunit": "^9.5 || ^10.0", "squizlabs/php_codesniffer": "^3.7" }, "suggest": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index e5f212a60..019ec5874 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,18 +1,17 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" + backupGlobals="true" + colors="true" + processIsolation="true" + stopOnFailure="false" + bootstrap="vendor/autoload.php"> + diff --git a/tests/AbstractTest.php b/tests/AbstractTest.php index 801df0240..2ecbb0f45 100644 --- a/tests/AbstractTest.php +++ b/tests/AbstractTest.php @@ -156,6 +156,8 @@ public function runCommand(string $command, bool $simulate = true, bool $output /** * Helper function to debug the expectations and the content before assert. * + * To debug, set the variable TOOLKIT_DEBUG_EXPECTATIONS to true in the phpunit.xml file. + * * @param string $content * Content to test. * @param array $expectations @@ -163,29 +165,32 @@ public function runCommand(string $command, bool $simulate = true, bool $output */ protected function debugExpectations(string $content, array $expectations) { - $debug = "\n-- Content --\n$content\n-- End Content --\n"; + if (!getenv('TOOLKIT_DEBUG_EXPECTATIONS')) { + return; + } + $output = "\n-- Content --\n$content\n-- End Content --\n"; foreach ($expectations as $expectation) { if (!empty($expectation['contains'])) { - $debug .= "-- Contains --\n{$expectation['contains']}\n-- End Contains --\n"; + $output .= "-- Contains --\n{$expectation['contains']}\n-- End Contains --\n"; } if (!empty($expectation['not_contains'])) { - $debug .= "-- NotContains --\n{$expectation['not_contains']}\n-- End NotContains --\n"; + $output .= "-- NotContains --\n{$expectation['not_contains']}\n-- End NotContains --\n"; } if (!empty($expectation['string_contains'])) { - $debug .= "-- String --\n{$expectation['string_contains']}\n-- End String --\n"; + $output .= "-- String --\n{$expectation['string_contains']}\n-- End String --\n"; } if (!empty($expectation['not_string_contains'])) { - $debug .= "-- NotString --\n{$expectation['not_string_contains']}\n-- End NotString --\n"; + $output .= "-- NotString --\n{$expectation['not_string_contains']}\n-- End NotString --\n"; } if (!empty($expectation['file_expected']) && !empty($expectation['file_actual'])) { - $debug .= "-- Files equal - expected --\n"; - $debug .= file_get_contents($expectation['file_expected']); - $debug .= "\n-- END expected --\n-- Files equal - actual --\n"; - $debug .= file_get_contents($expectation['file_actual']); - $debug .= "\n-- END actual --\n"; + $output .= "-- Files equal - expected --\n"; + $output .= file_get_contents($expectation['file_expected']); + $output .= "\n-- END expected --\n-- Files equal - actual --\n"; + $output .= file_get_contents($expectation['file_actual']); + $output .= "\n-- END actual --\n"; } } - echo $debug; + echo $output; } /** @@ -219,7 +224,7 @@ protected function getClassLoader() * @return string * The filepath of fixtures. */ - protected function getFixtureRoot(): string + protected static function getFixtureRoot(): string { return __DIR__ . '/fixtures'; } @@ -233,9 +238,9 @@ protected function getFixtureRoot(): string * @return string * The filepath of the sandbox file. */ - protected function getFixtureFilepath(string $name): string + protected static function getFixtureFilepath(string $name): string { - return $this->getFixtureRoot() . '/' . $name; + return self::getFixtureRoot() . '/' . $name; } /** @@ -247,9 +252,9 @@ protected function getFixtureFilepath(string $name): string * @return mixed|string * A set of test data. */ - protected function getFixtureContent(string $filepath) + protected static function getFixtureContent(string $filepath) { - return Yaml::parse(file_get_contents($this->getFixtureFilepath($filepath))); + return Yaml::parse(file_get_contents(self::getFixtureFilepath($filepath))); } /** @@ -261,9 +266,9 @@ protected function getFixtureContent(string $filepath) * @return string * The filepath of the sandbox file. */ - protected function getSandboxFilepath(string $name): string + protected static function getSandboxFilepath(string $name): string { - return $this->getSandboxRoot() . '/' . $name; + return self::getSandboxRoot() . '/' . $name; } /** @@ -272,9 +277,9 @@ protected function getSandboxFilepath(string $name): string * @return string * The filepath of sandbox. */ - protected function getSandboxRoot(): string + protected static function getSandboxRoot(): string { - return __DIR__ . '/sandbox/' . $this->getClassName(); + return __DIR__ . '/sandbox/' . self::getClassName(); } /** @@ -283,23 +288,10 @@ protected function getSandboxRoot(): string * @return string * The class name. */ - protected function getClassName(): string + protected static function getClassName(): string { $class = explode('\\', static::class); return (string) end($class); } - /** - * Return the mock base url. - * - * @return string - * The mock base url, defaults to web:8080. - */ - public static function getMockBaseUrl(): string - { - return !empty(getenv('VIRTUAL_HOST')) - ? (string) getenv('VIRTUAL_HOST') - : 'web:8080'; - } - } diff --git a/tests/Features/Commands/BlackfireCommandsTest.php b/tests/Features/Commands/BlackfireCommandsTest.php index 056cab0c9..7925f8276 100644 --- a/tests/Features/Commands/BlackfireCommandsTest.php +++ b/tests/Features/Commands/BlackfireCommandsTest.php @@ -21,9 +21,9 @@ class BlackfireCommandsTest extends AbstractTest * @return array * An array of test data arrays with assertions. */ - public function dataProvider() + public static function dataProvider() { - return $this->getFixtureContent('commands/blackfire.yml'); + return self::getFixtureContent('commands/blackfire.yml'); } /** @@ -55,7 +55,7 @@ public function testBlackfire(string $command, array $config = [], array $resour // Run command. $result = $this->runCommand($command); -// $this->debugExpectations($result['output'], $expectations); + $this->debugExpectations($result['output'], $expectations); // Assert expectations. foreach ($expectations as $expectation) { $this->assertDynamic($result['output'], $expectation); diff --git a/tests/Features/Commands/BuildCommandsTest.php b/tests/Features/Commands/BuildCommandsTest.php index 989569740..43f0891bf 100644 --- a/tests/Features/Commands/BuildCommandsTest.php +++ b/tests/Features/Commands/BuildCommandsTest.php @@ -22,9 +22,9 @@ class BuildCommandsTest extends AbstractTest * @return array * An array of test data arrays with assertions. */ - public function dataProvider() + public static function dataProvider() { - return $this->getFixtureContent('commands/build.yml'); + return self::getFixtureContent('commands/build.yml'); } /** @@ -51,7 +51,7 @@ public function testBuild(string $command, array $config = [], array $resources // Run command. $result = $this->runCommand($command); -// $this->debugExpectations($result['output'], $expectations); + $this->debugExpectations($result['output'], $expectations); // Assert expectations. foreach ($expectations as $expectation) { $this->assertDynamic($result['output'], $expectation); diff --git a/tests/Features/Commands/ComponentCheckCommandsTest.php b/tests/Features/Commands/ComponentCheckCommandsTest.php index 8ff228f11..04692a589 100644 --- a/tests/Features/Commands/ComponentCheckCommandsTest.php +++ b/tests/Features/Commands/ComponentCheckCommandsTest.php @@ -22,9 +22,9 @@ class ComponentCheckCommandsTest extends AbstractTest * @return array * An array of test data arrays with assertions. */ - public function dataProvider() + public static function dataProvider() { - return $this->getFixtureContent('commands/component-check.yml'); + return self::getFixtureContent('commands/component-check.yml'); } /** @@ -58,7 +58,7 @@ public function testComponentCheck(string $command, array $config = [], string $ // Run command. $result = $this->runCommand($command); -// $this->debugExpectations($result['output'], $expectations); + $this->debugExpectations($result['output'], $expectations); // Assert expectations. foreach ($expectations as $expectation) { $this->assertDynamic($result['output'], $expectation); diff --git a/tests/Features/Commands/ConfigurationCommandsTest.php b/tests/Features/Commands/ConfigurationCommandsTest.php index 29ae18076..0e9795465 100644 --- a/tests/Features/Commands/ConfigurationCommandsTest.php +++ b/tests/Features/Commands/ConfigurationCommandsTest.php @@ -24,9 +24,9 @@ class ConfigurationCommandsTest extends AbstractTest * @return array * An array of test data arrays with assertions. */ - public function dataProvider() + public static function dataProvider() { - return $this->getFixtureContent('commands/configuration.yml'); + return self::getFixtureContent('commands/configuration.yml'); } /** @@ -55,7 +55,7 @@ public function testConfiguration(string $command, array $config = [], array $re // Run command. $result = $this->runCommand($command, false); -// $this->debugExpectations($result['output'], $expectations); + $this->debugExpectations($result['output'], $expectations); // Assert expectations. foreach ($expectations as $expectation) { $this->assertDynamic($result['output'], $expectation); diff --git a/tests/Features/Commands/DockerCommandsTest.php b/tests/Features/Commands/DockerCommandsTest.php index a033ca886..cd4d5e295 100644 --- a/tests/Features/Commands/DockerCommandsTest.php +++ b/tests/Features/Commands/DockerCommandsTest.php @@ -22,9 +22,9 @@ class DockerCommandsTest extends AbstractTest * @return array * An array of test data arrays with assertions. */ - public function dataProvider(): array + public static function dataProvider(): array { - return $this->getFixtureContent('commands/docker.yml'); + return self::getFixtureContent('commands/docker.yml'); } /** @@ -33,9 +33,9 @@ public function dataProvider(): array * @return array * An array of test data arrays with assertions. */ - public function dataProviderDockerComposeContent(): array + public static function dataProviderDockerComposeContent(): array { - return $this->getFixtureContent('commands/docker-compose-content.yml'); + return self::getFixtureContent('commands/docker-compose-content.yml'); } /** diff --git a/tests/Features/Commands/DocumentationCommandsTest.php b/tests/Features/Commands/DocumentationCommandsTest.php index 772c93743..4424d7e51 100644 --- a/tests/Features/Commands/DocumentationCommandsTest.php +++ b/tests/Features/Commands/DocumentationCommandsTest.php @@ -21,9 +21,9 @@ class DocumentationCommandsTest extends AbstractTest * @return array * An array of test data arrays with assertions. */ - public function dataProvider() + public static function dataProvider() { - return $this->getFixtureContent('commands/documentation.yml'); + return self::getFixtureContent('commands/documentation.yml'); } /** @@ -44,7 +44,7 @@ public function testDocumentation(string $command, array $resources = [], array // Run command. $result = $this->runCommand($command); -// $this->debugExpectations($result['output'], $expectations); + $this->debugExpectations($result['output'], $expectations); // Assert expectations. foreach ($expectations as $expectation) { $this->assertDynamic($result['output'], $expectation); diff --git a/tests/Features/Commands/DrupalCommandsTest.php b/tests/Features/Commands/DrupalCommandsTest.php index 8d080d85b..88a357da5 100644 --- a/tests/Features/Commands/DrupalCommandsTest.php +++ b/tests/Features/Commands/DrupalCommandsTest.php @@ -22,9 +22,9 @@ class DrupalCommandsTest extends AbstractTest * @return array * An array of test data arrays with assertions. */ - public function dataProvider() + public static function dataProvider() { - return $this->getFixtureContent('commands/drupal.yml'); + return self::getFixtureContent('commands/drupal.yml'); } /** @@ -33,9 +33,9 @@ public function dataProvider() * @return array * An array of test data arrays with assertions. */ - public function dataProviderSettings() + public static function dataProviderSettings() { - return $this->getFixtureContent('commands/drupal-settings-setup.yml'); + return self::getFixtureContent('commands/drupal-settings-setup.yml'); } /** @@ -69,7 +69,7 @@ public function testDrupalCommands(string $command, array $config = [], string $ // Run command. $result = $this->runCommand($command); -// $this->debugExpectations($result['output'], $expectations); + $this->debugExpectations($result['output'], $expectations); // Assert expectations. foreach ($expectations as $expectation) { $this->assertDynamic($result['output'], $expectation); diff --git a/tests/Features/Commands/DumpCommandsTest.php b/tests/Features/Commands/DumpCommandsTest.php index 158b3c510..e32246a7a 100644 --- a/tests/Features/Commands/DumpCommandsTest.php +++ b/tests/Features/Commands/DumpCommandsTest.php @@ -22,9 +22,9 @@ class DumpCommandsTest extends AbstractTest * @return array * An array of test data arrays with assertions. */ - public function dataProvider() + public static function dataProvider() { - return $this->getFixtureContent('commands/dump.yml'); + return self::getFixtureContent('commands/dump.yml'); } /** @@ -51,7 +51,7 @@ public function testDump(string $command, array $config = [], array $resources = // Run command. $result = $this->runCommand($command); -// $this->debugExpectations($result['output'], $expectations); + $this->debugExpectations($result['output'], $expectations); // Assert expectations. foreach ($expectations as $expectation) { $this->assertDynamic($result['output'], $expectation); diff --git a/tests/Features/Commands/GitHooksCommandsTest.php b/tests/Features/Commands/GitHooksCommandsTest.php index 8b449fe4a..1fb3174db 100644 --- a/tests/Features/Commands/GitHooksCommandsTest.php +++ b/tests/Features/Commands/GitHooksCommandsTest.php @@ -22,9 +22,9 @@ class GitHooksCommandsTest extends AbstractTest * @return array * An array of test data arrays with assertions. */ - public function dataProvider() + public static function dataProvider() { - return $this->getFixtureContent('commands/git-hooks.yml'); + return self::getFixtureContent('commands/git-hooks.yml'); } protected function setUp(): void @@ -62,7 +62,7 @@ public function testGitHooks(string $command, array $config = [], array $expecta // Run command. $result = $this->runCommand($command); -// $this->debugExpectations($result['output'], $expectations); + $this->debugExpectations($result['output'], $expectations); // Assert expectations. foreach ($expectations as $expectation) { $this->assertDynamic($result['output'], $expectation); diff --git a/tests/Features/Commands/GitleaksCommandsTest.php b/tests/Features/Commands/GitleaksCommandsTest.php index 776e28ac0..fe0e82be7 100644 --- a/tests/Features/Commands/GitleaksCommandsTest.php +++ b/tests/Features/Commands/GitleaksCommandsTest.php @@ -21,9 +21,9 @@ class GitleaksCommandsTest extends AbstractTest * @return array * An array of test data arrays with assertions. */ - public function dataProvider() + public static function dataProvider() { - return $this->getFixtureContent('commands/gitleaks.yml'); + return self::getFixtureContent('commands/gitleaks.yml'); } /** @@ -40,7 +40,7 @@ public function testGitleaks(string $command, array $expectations = []) { // Run command. $result = $this->runCommand($command); -// $this->debugExpectations($result['output'], $expectations); + $this->debugExpectations($result['output'], $expectations); // Assert expectations. foreach ($expectations as $expectation) { $this->assertDynamic($result['output'], $expectation); diff --git a/tests/Features/Commands/InstallCommandsTest.php b/tests/Features/Commands/InstallCommandsTest.php index a4460c7c3..3c728402e 100644 --- a/tests/Features/Commands/InstallCommandsTest.php +++ b/tests/Features/Commands/InstallCommandsTest.php @@ -22,9 +22,9 @@ class InstallCommandsTest extends AbstractTest * @return array * An array of test data arrays with assertions. */ - public function dataProvider() + public static function dataProvider() { - return $this->getFixtureContent('commands/install.yml'); + return self::getFixtureContent('commands/install.yml'); } /** @@ -51,7 +51,7 @@ public function testInstall(string $command, array $config = [], array $resource // Run command. $result = $this->runCommand($command); -// $this->debugExpectations($result['output'], $expectations); + $this->debugExpectations($result['output'], $expectations); // Assert expectations. foreach ($expectations as $expectation) { $this->assertDynamic($result['output'], $expectation); diff --git a/tests/Features/Commands/LintCommandsTest.php b/tests/Features/Commands/LintCommandsTest.php index e5cb23b23..22a3b6ce4 100644 --- a/tests/Features/Commands/LintCommandsTest.php +++ b/tests/Features/Commands/LintCommandsTest.php @@ -22,9 +22,9 @@ class LintCommandsTest extends AbstractTest * @return array * An array of test data arrays with assertions. */ - public function dataProvider() + public static function dataProvider() { - return $this->getFixtureContent('commands/lint.yml'); + return self::getFixtureContent('commands/lint.yml'); } /** @@ -51,7 +51,7 @@ public function testLint(string $command, array $config = [], array $resources = // Run command. $result = $this->runCommand($command); -// $this->debugExpectations($result['output'], $expectations); + $this->debugExpectations($result['output'], $expectations); // Assert expectations. foreach ($expectations as $expectation) { $this->assertDynamic($result['output'], $expectation); diff --git a/tests/Features/Commands/ReleaseCommandsTest.php b/tests/Features/Commands/ReleaseCommandsTest.php index 03336f04c..11908d2a4 100644 --- a/tests/Features/Commands/ReleaseCommandsTest.php +++ b/tests/Features/Commands/ReleaseCommandsTest.php @@ -21,9 +21,9 @@ class ReleaseCommandsTest extends AbstractTest * @return array * An array of test data arrays with assertions. */ - public function dataProvider() + public static function dataProvider() { - return $this->getFixtureContent('commands/release.yml'); + return self::getFixtureContent('commands/release.yml'); } /** @@ -50,7 +50,7 @@ public function testToolkitRelease(string $command, array $config = [], array $r // Run command. $result = $this->runCommand($command); -// $this->debugExpectations($result['output'], $expectations); + $this->debugExpectations($result['output'], $expectations); // Assert expectations. foreach ($expectations as $expectation) { $this->assertDynamic($result['output'], $expectation); diff --git a/tests/Features/Commands/SymlinkProjectCommandsTest.php b/tests/Features/Commands/SymlinkProjectCommandsTest.php index ebc9e1f7e..e02a1f682 100644 --- a/tests/Features/Commands/SymlinkProjectCommandsTest.php +++ b/tests/Features/Commands/SymlinkProjectCommandsTest.php @@ -16,9 +16,9 @@ class SymlinkProjectCommandsTest extends AbstractTest * @return array * An array of test data arrays with assertions. */ - public function dataProvider() + public static function dataProvider() { - return $this->getFixtureContent('commands/drupal-symlink-project.yml'); + return self::getFixtureContent('commands/drupal-symlink-project.yml'); } /** @@ -46,7 +46,7 @@ public function testSymlinkProjectCommands(string $command, array $config = [], // Run command. $result = $this->runCommand($command); -// $this->debugExpectations($result['output'], $expectations); + $this->debugExpectations($result['output'], $expectations); // Assert expectations. foreach ($expectations as $expectation) { $this->assertDynamic($result['output'], $expectation); diff --git a/tests/Features/Commands/TestsCommandsTest.php b/tests/Features/Commands/TestsCommandsTest.php index 45ce71779..0023d019b 100644 --- a/tests/Features/Commands/TestsCommandsTest.php +++ b/tests/Features/Commands/TestsCommandsTest.php @@ -22,9 +22,9 @@ class TestsCommandsTest extends AbstractTest * @return array * An array of test data arrays with assertions. */ - public function dataProvider() + public static function dataProvider() { - return $this->getFixtureContent('commands/tests.yml'); + return self::getFixtureContent('commands/tests.yml'); } /** @@ -51,7 +51,7 @@ public function testTests(string $command, array $config = [], array $resources // Run command. $result = $this->runCommand($command); -// $this->debugExpectations($result['output'], $expectations); + $this->debugExpectations($result['output'], $expectations); // Assert expectations. foreach ($expectations as $expectation) { $this->assertDynamic($result['output'], $expectation); diff --git a/tests/Features/Commands/ToolCommandsTest.php b/tests/Features/Commands/ToolCommandsTest.php index 40db340a7..7723f6d7b 100644 --- a/tests/Features/Commands/ToolCommandsTest.php +++ b/tests/Features/Commands/ToolCommandsTest.php @@ -22,9 +22,9 @@ class ToolCommandsTest extends AbstractTest * @return array * An array of test data arrays with assertions. */ - public function dataProvider() + public static function dataProvider() { - return $this->getFixtureContent('commands/tool.yml'); + return self::getFixtureContent('commands/tool.yml'); } /** @@ -52,7 +52,7 @@ public function testTool(string $command, array $config = [], array $resources = // Run command. $result = $this->runCommand($command); -// $this->debugExpectations($result['output'], $expectations); + $this->debugExpectations($result['output'], $expectations); // Assert expectations. foreach ($expectations as $expectation) { $this->assertDynamic($result['output'], $expectation); @@ -65,9 +65,9 @@ public function testTool(string $command, array $config = [], array $resources = * @return array * An array of test data arrays with assertions. */ - public function dataProviderOptsReview() + public static function dataProviderOptsReview() { - return $this->getFixtureContent('commands/opts-review.yml'); + return self::getFixtureContent('commands/opts-review.yml'); } /** @@ -94,7 +94,7 @@ public function testOptsReview(string $command, array $config = [], array $resou // Run command. $result = $this->runCommand($command); -// $this->debugExpectations($result['output'], $expectations); + $this->debugExpectations($result['output'], $expectations); // Assert expectations. foreach ($expectations as $expectation) { $this->assertDynamic($result['output'], $expectation); diff --git a/tests/Unit/ReplaceBlockTest.php b/tests/Unit/ReplaceBlockTest.php index 68883676c..009a703f1 100644 --- a/tests/Unit/ReplaceBlockTest.php +++ b/tests/Unit/ReplaceBlockTest.php @@ -16,9 +16,9 @@ class ReplaceBlockTest extends AbstractTest * @return array * An array of test data arrays with assertions. */ - public function dataProvider() + public static function dataProvider() { - return $this->getFixtureContent('commands/replace-block.yml'); + return self::getFixtureContent('commands/replace-block.yml'); } /** diff --git a/tests/fixtures/commands/documentation.yml b/tests/fixtures/commands/documentation.yml index 24e832c41..584984fa5 100644 --- a/tests/fixtures/commands/documentation.yml +++ b/tests/fixtures/commands/documentation.yml @@ -1,8 +1,3 @@ -- command: 'toolkit:generate-documentation' - resources: [] - expectations: - - contains: "[ERROR] Fail to download the phpDocumentor.phar file." - - command: 'toolkit:generate-documentation --branch=docs' resources: - mkdir: docs