Skip to content

Commit 9a2b133

Browse files
committed
Run both PHPUnit bootstrap files
1 parent 5447030 commit 9a2b133

File tree

3 files changed

+39
-12
lines changed

3 files changed

+39
-12
lines changed

bin/run-php-unit-tests

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
#!/bin/sh
22

33
# Run the unit tests, if they exist
4-
if [ -f "phpunit.xml" ] || [ -f "phpunit.xml.dist" ]
4+
if [ -f "phpunit.xml" ] || [ -f "phpunit.xml.dist" ] || [ -f ".phpunit.xml" ] || [ -f ".phpunit.xml.dist" ]
55
then
6-
vendor/bin/phpunit --color=always "$@"
6+
if [ -f "./vendor/wp-cli/wp-cli-tests/tests/bootstrap.php" ]; then
7+
vendor/bin/phpunit --color=always "$@" --bootstrap ./vendor/wp-cli/wp-cli-tests/tests/bootstrap.php
8+
else
9+
vendor/bin/phpunit --color=always "$@"
10+
fi
711
fi

bin/run-phpcs-tests

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/sh
22

33
# Run the unit tests, if they exist
4-
if [ -f "phpcs.xml" ] || [ -f "phpcs.xml.dist" ]
4+
if [ -f "phpcs.xml" ] || [ -f "phpcs.xml.dist" ] || [ -f ".phpcs.xml" ] || [ -f ".phpcs.xml.dist" ]
55
then
66
vendor/bin/phpcs "$@"
77
fi

tests/bootstrap.php

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
<?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 . '/..' );
410

511
/**
612
* Compatibility with PHPUnit 6+
@@ -9,12 +15,29 @@
915
require_once __DIR__ . '/phpunit6-compat.php';
1016
}
1117

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';
1919
require_once WP_CLI_ROOT . '/php/utils.php';
2020

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

Comments
 (0)