|
1 | 1 | <?php |
2 | | - |
3 | | -define( 'WP_CLI_ROOT', dirname( __DIR__ ) . '/vendor/wp-cli/wp-cli' ); |
| 2 | +define( 'WP_CLI_TESTS_ROOT', dirname( __DIR__ ) ); |
| 3 | +define( 'VENDOR_DIR', |
| 4 | + file_exists( WP_CLI_TESTS_ROOT . '/vendor/autoload.php' ) |
| 5 | + ? WP_CLI_TESTS_ROOT . '/vendor' |
| 6 | + : WP_CLI_TESTS_ROOT . '/../..' |
| 7 | +); |
| 8 | +define( 'WP_CLI_ROOT', VENDOR_DIR . '/wp-cli/wp-cli' ); |
| 9 | +define( 'PACKAGE_ROOT', VENDOR_DIR . '/..' ); |
4 | 10 |
|
5 | 11 | /** |
6 | 12 | * Compatibility with PHPUnit 6+ |
|
9 | 15 | require_once __DIR__ . '/phpunit6-compat.php'; |
10 | 16 | } |
11 | 17 |
|
12 | | -if ( file_exists( WP_CLI_ROOT . '/vendor/autoload.php' ) ) { |
13 | | - define( 'WP_CLI_VENDOR_DIR', WP_CLI_ROOT . '/vendor' ); |
14 | | -} elseif ( file_exists( dirname( dirname( WP_CLI_ROOT ) ) . '/autoload.php' ) ) { |
15 | | - define( 'WP_CLI_VENDOR_DIR', dirname( dirname( WP_CLI_ROOT ) ) ); |
16 | | -} |
17 | | - |
18 | | -require_once WP_CLI_VENDOR_DIR . '/autoload.php'; |
| 18 | +require_once VENDOR_DIR . '/autoload.php'; |
19 | 19 | require_once WP_CLI_ROOT . '/php/utils.php'; |
20 | 20 |
|
| 21 | +$config_filenames = array( |
| 22 | + 'phpunit.xml', |
| 23 | + '.phpunit.xml', |
| 24 | + 'phpunit.xml.dist', |
| 25 | + '.phpunit.xml.dist', |
| 26 | +); |
| 27 | + |
| 28 | +$config_filename = false; |
| 29 | +foreach ( $config_filenames as $filename ) { |
| 30 | + if ( file_exists( PACKAGE_ROOT . '/' . $filename ) ) { |
| 31 | + $config_filename = PACKAGE_ROOT . '/' . $filename; |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +if ( $config_filename ) { |
| 36 | + $config = file_get_contents( $config_filename ); |
| 37 | + $matches = null; |
| 38 | + $pattern = '/bootstrap="(?P<bootstrap>.*)"/'; |
| 39 | + $result = preg_match( $pattern, $config, $matches ); |
| 40 | + if ( isset( $matches['bootstrap'] ) && file_exists( $matches['bootstrap'] ) ) { |
| 41 | + include_once PACKAGE_ROOT . '/' . $matches['bootstrap']; |
| 42 | + } |
| 43 | +} |
0 commit comments