Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DQA-7713: Add support to phpunit/phpunit 10 #698

Merged
merged 4 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
/runner.yml
/phpunit.xml
/docker-compose.*.yml
.phpunit.result.cache
/.phpunit.result.cache
/.phpunit.cache/
*.sql
phpda.*
.phpdoc*
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
17 changes: 8 additions & 9 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
backupGlobals = "true"
backupStaticAttributes = "false"
colors = "true"
convertErrorsToExceptions = "true"
convertNoticesToExceptions = "true"
convertWarningsToExceptions = "true"
processIsolation = "true"
stopOnFailure = "false"
bootstrap = "vendor/autoload.php">
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">
<php>
<env name="CI" value="true"/>
<env name="QA_WEBSITE_URL" value="http://web:8080" force="true"/>
<env name="TOOLKIT_MOCK_BRANCH" value="0.0.2"/>
<env name="TOOLKIT_DEBUG_EXPECTATIONS" value="false"/>
<env name="DRUPAL_DATABASE_NAME" value="drupal"/>
<env name="DRUPAL_DATABASE_USERNAME" value="root"/>
<env name="DRUPAL_DATABASE_HOST" value="mysql"/>
Expand Down
60 changes: 26 additions & 34 deletions tests/AbstractTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,36 +156,41 @@ 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
* Array with expectations.
*/
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;
}

/**
Expand Down Expand Up @@ -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';
}
Expand All @@ -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;
}

/**
Expand All @@ -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)));
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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();
}

/**
Expand All @@ -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';
}

}
6 changes: 3 additions & 3 deletions tests/Features/Commands/BlackfireCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions tests/Features/Commands/BuildCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions tests/Features/Commands/ComponentCheckCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions tests/Features/Commands/ConfigurationCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand Down Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions tests/Features/Commands/DockerCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand All @@ -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');
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/Features/Commands/DocumentationCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand All @@ -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);
Expand Down
10 changes: 5 additions & 5 deletions tests/Features/Commands/DrupalCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand All @@ -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');
}

/**
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions tests/Features/Commands/DumpCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand All @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions tests/Features/Commands/GitHooksCommandsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
Loading