Skip to content

Commit bb4b6b1

Browse files
committed
test: fix development.php to also return if we run a test as a separate process
1 parent f8e3fbb commit bb4b6b1

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

development.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,15 @@
44
*
55
* @package ThemeIsle
66
*/
7-
if ( defined( 'PHPUNIT_COMPOSER_INSTALL' ) ) {
7+
8+
// This condition tries to detect if we're running PHPUnit. This is complex because the file is loaded via the
9+
// composer autoloader. You can detect that 99% of the time because PHPUnit uses the constant
10+
// PHPUNIT_COMPOSER_INSTALL to load the autoloader. That said, if you run a test in a separate process, it won't
11+
// run that code again and the constant doesn't exist. As a fallback, we use the PHPUNIT_RUNNING environment variable
12+
// defined in the phpunit.xml to detect if we're in a PHPUnit process. We can't always use the environment variable
13+
// because by default PHPUnit loads the composer autoloader before it assigns those environment variables. That's
14+
// why both conditions are needed.
15+
if ( defined( 'PHPUNIT_COMPOSER_INSTALL' ) || getenv( 'PHPUNIT_RUNNING' ) ) {
816
return;
917
}
1018

phpunit.xml

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
convertNoticesToExceptions="true"
77
convertWarningsToExceptions="true"
88
>
9+
<php>
10+
<env name="PHPUNIT_RUNNING" value="1"/>
11+
</php>
12+
913
<testsuites>
1014
<testsuite name="General Unit tests ( Requires PHP 5.4) " >
1115
<directory phpVersion="5.4.0" phpVersionOperator=">=" prefix="test-" suffix=".php">./tests/</directory>

0 commit comments

Comments
 (0)