15
15
16
16
error_reporting (-1 );
17
17
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
+
18
47
if (PHP_VERSION_ID >= 70200 ) {
19
48
// 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 ' ) ;
21
50
} elseif (PHP_VERSION_ID >= 50600 ) {
22
51
// 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 ' ) ;
24
53
} else {
25
54
// PHPUnit 5.1 requires PHP 5.6+
26
55
$ PHPUNIT_VERSION = '4.8 ' ;
@@ -40,7 +69,7 @@ while (!file_exists($root.'/'.$COMPOSER_JSON) || file_exists($root.'/Deprecation
40
69
}
41
70
42
71
$ oldPwd = getcwd ();
43
- $ PHPUNIT_DIR = getenv ('SYMFONY_PHPUNIT_DIR ' ) ?: ( $ root .'/vendor/bin/.phpunit ' );
72
+ $ PHPUNIT_DIR = getEnvVar ('SYMFONY_PHPUNIT_DIR ' , $ root .'/vendor/bin/.phpunit ' );
44
73
$ PHP = defined ('PHP_BINARY ' ) ? PHP_BINARY : 'php ' ;
45
74
$ PHP = escapeshellarg ($ PHP );
46
75
if ('phpdbg ' === PHP_SAPI ) {
@@ -51,24 +80,8 @@ $COMPOSER = file_exists($COMPOSER = $oldPwd.'/composer.phar') || ($COMPOSER = rt
51
80
? $ PHP .' ' .escapeshellarg ($ COMPOSER )
52
81
: 'composer ' ;
53
82
54
- if (false === $ SYMFONY_PHPUNIT_REMOVE = getenv ('SYMFONY_PHPUNIT_REMOVE ' )) {
55
- $ SYMFONY_PHPUNIT_REMOVE = 'phpspec/prophecy symfony/yaml ' ;
56
83
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 ' );
72
85
73
86
if (!file_exists ("$ PHPUNIT_DIR /phpunit- $ PHPUNIT_VERSION /phpunit " ) || md5_file (__FILE__ )."\n" .$ SYMFONY_PHPUNIT_REMOVE !== @file_get_contents ("$ PHPUNIT_DIR /. $ PHPUNIT_VERSION .md5 " )) {
74
87
// 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
157
170
$ argv [1 ] = 'src/Symfony ' ;
158
171
}
159
172
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
161
174
162
175
$ finder = new RecursiveDirectoryIterator ($ argv [1 ], FilesystemIterator::KEY_AS_FILENAME | FilesystemIterator::UNIX_PATHS );
163
176
$ finder = new RecursiveIteratorIterator ($ finder );
0 commit comments