Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f738013

Browse files
committed
feature #26811 [PhpUnitBridge] Search for other SYMFONY_* env vars in phpunit.xml then phpunit.xml.dist (lyrixx)
This PR was merged into the 4.1-dev branch. Discussion ---------- [PhpUnitBridge] Search for other SYMFONY_* env vars in phpunit.xml then phpunit.xml.dist | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #26800 (comment) | License | MIT | Doc PR | Commits ------- 3b1c582 [PhpUnitBridge] Search for other SYMFONY_* env vars in phpunit.xml then phpunit.xml.dist
2 parents 209898e + 3b1c582 commit f738013

File tree

2 files changed

+36
-23
lines changed

2 files changed

+36
-23
lines changed

src/Symfony/Bridge/PhpUnit/CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ CHANGELOG
44
4.1.0
55
-----
66

7-
* Search for `SYMFONY_PHPUNIT_REMOVE` env var in `phpunit.xml` then
8-
`phpunit.xml.dist`
7+
* Search for `SYMFONY_PHPUNIT_VERSION`, `SYMFONY_PHPUNIT_REMOVE`,
8+
`SYMFONY_PHPUNIT_DIR` env var in `phpunit.xml` then in `phpunit.xml.dist`
99

1010
4.0.0
1111
-----

src/Symfony/Bridge/PhpUnit/bin/simple-phpunit

Lines changed: 34 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,41 @@
1515

1616
error_reporting(-1);
1717

18+
function getEnvVar($name, $default = false) {
19+
if (false !== $value = getenv($name)) {
20+
return $value;
21+
}
22+
23+
static $phpunitConfig = null;
24+
if (null === $phpunitConfig) {
25+
if (file_exists('phpunit.xml')) {
26+
$phpunitConfigFilename = 'phpunit.xml';
27+
} elseif (file_exists('phpunit.xml.dist')) {
28+
$phpunitConfigFilename = 'phpunit.xml.dist';
29+
}
30+
if ($phpunitConfigFilename) {
31+
$phpunitConfig = new DomDocument();
32+
$phpunitConfig->load($phpunitConfigFilename);
33+
} else {
34+
$phpunitConfig = false;
35+
}
36+
}
37+
if (false !== $phpunitConfig) {
38+
$var = (new DOMXpath($phpunitConfig))->query('//php/env[@name="'.$name.'"]')[0];
39+
if ($var) {
40+
return $var->getAttribute('value');
41+
}
42+
}
43+
44+
return $default;
45+
}
46+
1847
if (PHP_VERSION_ID >= 70200) {
1948
// PHPUnit 6 is required for PHP 7.2+
20-
$PHPUNIT_VERSION = getenv('SYMFONY_PHPUNIT_VERSION') ?: '6.5';
49+
$PHPUNIT_VERSION = getEnvVar('SYMFONY_PHPUNIT_VERSION', '6.5');
2150
} elseif (PHP_VERSION_ID >= 50600) {
2251
// PHPUnit 4 does not support PHP 7
23-
$PHPUNIT_VERSION = getenv('SYMFONY_PHPUNIT_VERSION') ?: '5.7';
52+
$PHPUNIT_VERSION = getEnvVar('SYMFONY_PHPUNIT_VERSION', '5.7');
2453
} else {
2554
// PHPUnit 5.1 requires PHP 5.6+
2655
$PHPUNIT_VERSION = '4.8';
@@ -40,7 +69,7 @@ while (!file_exists($root.'/'.$COMPOSER_JSON) || file_exists($root.'/Deprecation
4069
}
4170

4271
$oldPwd = getcwd();
43-
$PHPUNIT_DIR = getenv('SYMFONY_PHPUNIT_DIR') ?: ($root.'/vendor/bin/.phpunit');
72+
$PHPUNIT_DIR = getEnvVar('SYMFONY_PHPUNIT_DIR', $root.'/vendor/bin/.phpunit');
4473
$PHP = defined('PHP_BINARY') ? PHP_BINARY : 'php';
4574
$PHP = escapeshellarg($PHP);
4675
if ('phpdbg' === PHP_SAPI) {
@@ -51,24 +80,8 @@ $COMPOSER = file_exists($COMPOSER = $oldPwd.'/composer.phar') || ($COMPOSER = rt
5180
? $PHP.' '.escapeshellarg($COMPOSER)
5281
: 'composer';
5382

54-
if (false === $SYMFONY_PHPUNIT_REMOVE = getenv('SYMFONY_PHPUNIT_REMOVE')) {
55-
$SYMFONY_PHPUNIT_REMOVE = 'phpspec/prophecy symfony/yaml';
5683

57-
$phpunitConfigFilename = null;
58-
if (file_exists('phpunit.xml')) {
59-
$phpunitConfigFilename = 'phpunit.xml';
60-
} elseif (file_exists('phpunit.xml.dist')) {
61-
$phpunitConfigFilename = 'phpunit.xml.dist';
62-
}
63-
if ($phpunitConfigFilename) {
64-
$xml = new DomDocument();
65-
$xml->load($phpunitConfigFilename);
66-
$var = (new DOMXpath($xml))->query('//php/env[@name="SYMFONY_PHPUNIT_REMOVE"]')[0];
67-
if ($var) {
68-
$SYMFONY_PHPUNIT_REMOVE = $var->getAttribute('value');
69-
}
70-
}
71-
}
84+
$SYMFONY_PHPUNIT_REMOVE = getEnvVar('SYMFONY_PHPUNIT_REMOVE', 'phpspec/prophecy symfony/yaml');
7285

7386
if (!file_exists("$PHPUNIT_DIR/phpunit-$PHPUNIT_VERSION/phpunit") || md5_file(__FILE__)."\n".$SYMFONY_PHPUNIT_REMOVE !== @file_get_contents("$PHPUNIT_DIR/.$PHPUNIT_VERSION.md5")) {
7487
// 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
157170
$argv[1] = 'src/Symfony';
158171
}
159172
if (isset($argv[1]) && is_dir($argv[1]) && !file_exists($argv[1].'/phpunit.xml.dist')) {
160-
// Find Symfony components in plain php for Windows portability
173+
// Find Symfony components in plain PHP for Windows portability
161174

162175
$finder = new RecursiveDirectoryIterator($argv[1], FilesystemIterator::KEY_AS_FILENAME | FilesystemIterator::UNIX_PATHS);
163176
$finder = new RecursiveIteratorIterator($finder);

0 commit comments

Comments
 (0)