Skip to content

Commit

Permalink
Use native PHPUnit Configuration class (#496)
Browse files Browse the repository at this point in the history
* Use native PHPUnit Configuration class

* Fix composer require checker validation
  • Loading branch information
Slamdunk authored Aug 5, 2020
1 parent 436128b commit 006d5c9
Show file tree
Hide file tree
Showing 19 changed files with 162 additions and 549 deletions.
2 changes: 1 addition & 1 deletion .github/lint-xml-configuration/lint-xml-configuration.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set -ex
xmllint --noout --schema vendor/phpunit/phpunit/phpunit.xsd phpunit.xml.dist
xmllint --noout --schema vendor/squizlabs/php_codesniffer/phpcs.xsd phpcs.xml.dist
xmllint --noout --schema vendor/vimeo/psalm/config.xsd psalm.xml.dist
find test/ -name "phpunit*.xml*" -not -name "phpunit-files-dirs-mix-nested.xml" -print0 | xargs -0 xmllint --noout --schema vendor/phpunit/phpunit/phpunit.xsd
find test/ -name "phpunit*.xml*" -print0 | xargs -0 xmllint --noout --schema vendor/phpunit/phpunit/phpunit.xsd
15 changes: 8 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,23 @@
"ext-simplexml": "*",
"brianium/habitat": "^1.0",
"phpunit/php-code-coverage": "^8.0",
"phpunit/php-file-iterator": "^3.0",
"phpunit/php-timer": "^5.0",
"phpunit/phpunit": "^9.2",
"symfony/console": "^4.4 || ^5.0",
"symfony/process": "^4.4 || ^5.0"
"symfony/console": "^4.4 || ^5.1",
"symfony/process": "^4.4 || ^5.1"
},
"require-dev": {
"doctrine/coding-standard": "^8.1",
"ekino/phpstan-banned-code": "^0.3.1",
"ergebnis/phpstan-rules": "^0.15.0",
"phpstan/phpstan": "^0.12.33",
"ergebnis/phpstan-rules": "^0.15.1",
"phpstan/phpstan": "^0.12.35",
"phpstan/phpstan-deprecation-rules": "^0.12.5",
"phpstan/phpstan-phpunit": "^0.12.12",
"phpstan/phpstan-phpunit": "^0.12.15",
"phpstan/phpstan-strict-rules": "^0.12.4",
"squizlabs/php_codesniffer": "^3.5",
"squizlabs/php_codesniffer": "^3.5.5",
"thecodingmachine/phpstan-strict-rules": "^0.12.0",
"vimeo/psalm": "^3.12"
"vimeo/psalm": "^3.13.1"
},
"autoload": {
"psr-4": {
Expand Down
5 changes: 5 additions & 0 deletions psalm.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<InternalClass errorLevel="suppress" />
<InternalMethod errorLevel="suppress" />
</issueHandlers>
</psalm>
53 changes: 21 additions & 32 deletions src/Console/Testers/PHPUnit.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
namespace ParaTest\Console\Testers;

use InvalidArgumentException;
use ParaTest\Runners\PHPUnit\Configuration;
use ParaTest\Runners\PHPUnit\Options;
use ParaTest\Runners\PHPUnit\Runner;
use ParaTest\Runners\PHPUnit\RunnerInterface;
use ParaTest\Util\Str;
use PHPUnit\TextUI\Configuration\Configuration;
use PHPUnit\TextUI\Configuration\Registry;
use RuntimeException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
Expand All @@ -27,12 +28,11 @@
use function getcwd;
use function is_string;
use function is_subclass_of;
use function realpath;
use function sprintf;
use function sys_get_temp_dir;
use function tempnam;

use const DIRECTORY_SEPARATOR;

/**
* Creates the interface for PHPUnit testing
*/
Expand Down Expand Up @@ -111,16 +111,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
$bareOptions = $this->getRunnerOptions($input);
$this->requireBootstrap($this->getBootstrapFile($input, $bareOptions));

$options = new Options($bareOptions);
if (
isset($options->filtered['configuration']) &&
! file_exists($path = $options->filtered['configuration']->getPath())
) {
$output->writeln(sprintf('Could not read "%s".', $path));

return 1;
}

$options = new Options($bareOptions);
$runnerClass = $this->getRunnerClass($input);

$runner = new $runnerClass($options, $output);
Expand All @@ -147,27 +138,22 @@ private function hasPath(InputInterface $input): bool
*/
private function hasConfig(InputInterface $input): bool
{
return $this->getConfig($input) !== false;
return $this->getConfig($input) !== null;
}

/**
* @return Configuration|bool
*/
private function getConfig(InputInterface $input)
private function getConfig(InputInterface $input): ?Configuration
{
$cwd = getcwd() . DIRECTORY_SEPARATOR;

if ($input->getOption('configuration')) {
$configFilename = $input->getOption('configuration');
} elseif (file_exists($cwd . 'phpunit.xml.dist')) {
$configFilename = $cwd . 'phpunit.xml.dist';
} elseif (file_exists($cwd . 'phpunit.xml')) {
$configFilename = $cwd . 'phpunit.xml';
if (is_string($path = $input->getOption('configuration')) && file_exists($path)) {
$configFilename = $path;
} elseif (file_exists($path = 'phpunit.xml')) {
$configFilename = $path;
} elseif (file_exists($path = 'phpunit.xml.dist')) {
$configFilename = $path;
} else {
return false;
return null;
}

return new Configuration($configFilename);
return Registry::getInstance()->get(realpath($configFilename));
}

/**
Expand Down Expand Up @@ -272,14 +258,17 @@ private function getBootstrapFile(InputInterface $input, array $options): string
return $options['bootstrap'];
}

if (! $this->hasConfig($input)) {
$config = $this->getConfig($input);
if ($config === null) {
return '';
}

$config = $this->getConfig($input);
$bootstrap = $config->getBootstrap();
$phpunitConfig = $config->phpunit();
if (! $phpunitConfig->hasBootstrap()) {
return '';
}

return $bootstrap !== '' ? $config->getConfigDir() . $bootstrap : '';
return $phpunitConfig->bootstrap();
}

/**
Expand Down
12 changes: 6 additions & 6 deletions src/Runners/PHPUnit/BaseRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,17 +174,17 @@ private function overrideEnvironmentVariables(): void
return;
}

$variables = $this->options->filtered['configuration']->getEnvironmentVariables();
$variables = $this->options->filtered['configuration']->php()->envVariables();

foreach ($variables as $key => $value) {
$localEnvValue = getenv($key, true);
foreach ($variables as $variable) {
$localEnvValue = getenv($variable->name(), true);
if ($localEnvValue === false) {
$localEnvValue = $value;
$localEnvValue = $variable->value();
}

putenv(sprintf('%s=%s', $key, $localEnvValue));
putenv(sprintf('%s=%s', $variable->name(), $localEnvValue));

$_ENV[$key] = $localEnvValue;
$_ENV[$variable->name()] = $localEnvValue;
}
}

Expand Down
Loading

0 comments on commit 006d5c9

Please # to comment.