[PhpUnitBridge] Search for other SYMFONY_* env vars in phpunit.xml then phpunit.xml.dist
This commit is contained in:
parent
209898ed35
commit
3b1c5820d3
@ -4,8 +4,8 @@ CHANGELOG
|
||||
4.1.0
|
||||
-----
|
||||
|
||||
* Search for `SYMFONY_PHPUNIT_REMOVE` env var in `phpunit.xml` then
|
||||
`phpunit.xml.dist`
|
||||
* Search for `SYMFONY_PHPUNIT_VERSION`, `SYMFONY_PHPUNIT_REMOVE`,
|
||||
`SYMFONY_PHPUNIT_DIR` env var in `phpunit.xml` then in `phpunit.xml.dist`
|
||||
|
||||
4.0.0
|
||||
-----
|
||||
|
@ -15,12 +15,41 @@
|
||||
|
||||
error_reporting(-1);
|
||||
|
||||
function getEnvVar($name, $default = false) {
|
||||
if (false !== $value = getenv($name)) {
|
||||
return $value;
|
||||
}
|
||||
|
||||
static $phpunitConfig = null;
|
||||
if (null === $phpunitConfig) {
|
||||
if (file_exists('phpunit.xml')) {
|
||||
$phpunitConfigFilename = 'phpunit.xml';
|
||||
} elseif (file_exists('phpunit.xml.dist')) {
|
||||
$phpunitConfigFilename = 'phpunit.xml.dist';
|
||||
}
|
||||
if ($phpunitConfigFilename) {
|
||||
$phpunitConfig = new DomDocument();
|
||||
$phpunitConfig->load($phpunitConfigFilename);
|
||||
} else {
|
||||
$phpunitConfig = false;
|
||||
}
|
||||
}
|
||||
if (false !== $phpunitConfig) {
|
||||
$var = (new DOMXpath($phpunitConfig))->query('//php/env[@name="'.$name.'"]')[0];
|
||||
if ($var) {
|
||||
return $var->getAttribute('value');
|
||||
}
|
||||
}
|
||||
|
||||
return $default;
|
||||
}
|
||||
|
||||
if (PHP_VERSION_ID >= 70200) {
|
||||
// PHPUnit 6 is required for PHP 7.2+
|
||||
$PHPUNIT_VERSION = getenv('SYMFONY_PHPUNIT_VERSION') ?: '6.5';
|
||||
$PHPUNIT_VERSION = getEnvVar('SYMFONY_PHPUNIT_VERSION', '6.5');
|
||||
} elseif (PHP_VERSION_ID >= 50600) {
|
||||
// PHPUnit 4 does not support PHP 7
|
||||
$PHPUNIT_VERSION = getenv('SYMFONY_PHPUNIT_VERSION') ?: '5.7';
|
||||
$PHPUNIT_VERSION = getEnvVar('SYMFONY_PHPUNIT_VERSION', '5.7');
|
||||
} else {
|
||||
// PHPUnit 5.1 requires PHP 5.6+
|
||||
$PHPUNIT_VERSION = '4.8';
|
||||
@ -40,7 +69,7 @@ while (!file_exists($root.'/'.$COMPOSER_JSON) || file_exists($root.'/Deprecation
|
||||
}
|
||||
|
||||
$oldPwd = getcwd();
|
||||
$PHPUNIT_DIR = getenv('SYMFONY_PHPUNIT_DIR') ?: ($root.'/vendor/bin/.phpunit');
|
||||
$PHPUNIT_DIR = getEnvVar('SYMFONY_PHPUNIT_DIR', $root.'/vendor/bin/.phpunit');
|
||||
$PHP = defined('PHP_BINARY') ? PHP_BINARY : 'php';
|
||||
$PHP = escapeshellarg($PHP);
|
||||
if ('phpdbg' === PHP_SAPI) {
|
||||
@ -51,24 +80,8 @@ $COMPOSER = file_exists($COMPOSER = $oldPwd.'/composer.phar') || ($COMPOSER = rt
|
||||
? $PHP.' '.escapeshellarg($COMPOSER)
|
||||
: 'composer';
|
||||
|
||||
if (false === $SYMFONY_PHPUNIT_REMOVE = getenv('SYMFONY_PHPUNIT_REMOVE')) {
|
||||
$SYMFONY_PHPUNIT_REMOVE = 'phpspec/prophecy symfony/yaml';
|
||||
|
||||
$phpunitConfigFilename = null;
|
||||
if (file_exists('phpunit.xml')) {
|
||||
$phpunitConfigFilename = 'phpunit.xml';
|
||||
} elseif (file_exists('phpunit.xml.dist')) {
|
||||
$phpunitConfigFilename = 'phpunit.xml.dist';
|
||||
}
|
||||
if ($phpunitConfigFilename) {
|
||||
$xml = new DomDocument();
|
||||
$xml->load($phpunitConfigFilename);
|
||||
$var = (new DOMXpath($xml))->query('//php/env[@name="SYMFONY_PHPUNIT_REMOVE"]')[0];
|
||||
if ($var) {
|
||||
$SYMFONY_PHPUNIT_REMOVE = $var->getAttribute('value');
|
||||
}
|
||||
}
|
||||
}
|
||||
$SYMFONY_PHPUNIT_REMOVE = getEnvVar('SYMFONY_PHPUNIT_REMOVE', 'phpspec/prophecy symfony/yaml');
|
||||
|
||||
if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__FILE__)."\n".$SYMFONY_PHPUNIT_REMOVE !== @file_get_contents("$PHPUNIT_DIR/.$PHPUNIT_VERSION.md5")) {
|
||||
// Build a standalone phpunit without symfony/yaml nor prophecy by default
|
||||
@ -157,7 +170,7 @@ if (isset($argv[1]) && 'symfony' === $argv[1] && !file_exists('symfony') && file
|
||||
$argv[1] = 'src/Symfony';
|
||||
}
|
||||
if (isset($argv[1]) && is_dir($argv[1]) && !file_exists($argv[1].'/phpunit.xml.dist')) {
|
||||
// Find Symfony components in plain php for Windows portability
|
||||
// Find Symfony components in plain PHP for Windows portability
|
||||
|
||||
$finder = new RecursiveDirectoryIterator($argv[1], FilesystemIterator::KEY_AS_FILENAME | FilesystemIterator::UNIX_PATHS);
|
||||
$finder = new RecursiveIteratorIterator($finder);
|
||||
|
Reference in New Issue
Block a user