forked from WordPress/phpunit-test-runner
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.php
85 lines (78 loc) · 3.04 KB
/
test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* Executes the PHPUnit test suite within the WordPress testing environment.
* This script is designed to run tests either locally or on a remote server based on the environment setup.
* It dynamically constructs the command to run PHPUnit and then executes it.
*
* @link https://github.com/wordpress/phpunit-test-runner/ Original source repository
* @package WordPress
*/
require __DIR__ . '/functions.php';
/**
* Check for the presence of required environment variables.
* This function should be defined in functions.php and should throw an
* exception or exit if any required variables are missing.
*/
check_required_env();
/**
* Retrieves environment variables and sets defaults for test preparation.
* These variables are used to configure SSH connections, file paths, and
* executable commands needed for setting up the test environment.
*/
$WPT_SSH_CONNECT = trim( getenv( 'WPT_SSH_CONNECT' ) );
$WPT_TEST_DIR = trim( getenv( 'WPT_TEST_DIR' ) );
$WPT_SSH_OPTIONS = trim( getenv( 'WPT_SSH_OPTIONS' ) ) ? : '-o StrictHostKeyChecking=no';
$WPT_PHP_EXECUTABLE = trim( getenv( 'WPT_PHP_EXECUTABLE' ) ) ? : 'php';
// Uses the flavor (usually to test WordPress Multisite)
$WPT_FLAVOR_INI = trim( getenv( 'WPT_FLAVOR' ) );
switch( $WPT_FLAVOR_INI ) {
case 0:
$WPT_FLAVOR_TXT = ''; // Simple WordPress
break;
case 1:
$WPT_FLAVOR_TXT = ' -c tests/phpunit/multisite.xml'; // WordPress Multisite
break;
default:
$WPT_FLAVOR_TXT = '';
break;
}
unset( $WPT_FLAVOR_INI );
// Uses the flavor (usually to test WordPress Multisite)
$WPT_EXTRATESTS_INI = trim( getenv( 'WPT_EXTRATESTS' ) );
switch( $WPT_EXTRATESTS_INI ) {
case 0:
$WPT_EXTRATESTS_TXT = ''; // no extra tests
break;
case 1:
$WPT_EXTRATESTS_TXT = ' --group ajax'; // ajax tests
break;
case 2:
$WPT_EXTRATESTS_TXT = ' --group ms-files'; // ms-files tests
break;
case 3:
$WPT_EXTRATESTS_TXT = ' --group external-http'; // external-http tests
break;
default:
$WPT_EXTRATESTS_TXT = '';
break;
}
unset( $WPT_EXTRATESTS_INI );
/**
* Determines the PHPUnit command to execute the test suite.
* Retrieves the PHPUnit command from the environment variable 'WPT_PHPUNIT_CMD'. If the environment
* variable is not set or is empty, it constructs a default command using the PHP executable path and
* the test directory path from environment variables, appending parameters to the PHPUnit call to
* avoid reporting useless tests.
*/
$WPT_PHPUNIT_CMD = trim( getenv( 'WPT_PHPUNIT_CMD' ) );
if( empty( $WPT_PHPUNIT_CMD ) ) {
$WPT_PHPUNIT_CMD = 'cd ' . escapeshellarg( $WPT_TEST_DIR ) . ' && ' . $WPT_PHP_EXECUTABLE . ' ./vendor/phpunit/phpunit/phpunit --dont-report-useless-tests' . $WPT_FLAVOR_TXT . $WPT_EXTRATESTS_TXT;
}
// If an SSH connection string is provided, prepend the SSH command to the PHPUnit execution command.
if ( ! empty( $WPT_SSH_CONNECT ) ) {
$WPT_PHPUNIT_CMD = 'ssh ' . $WPT_SSH_OPTIONS . ' ' . escapeshellarg( $WPT_SSH_CONNECT ) . ' ' . escapeshellarg( $WPT_PHPUNIT_CMD );
}
// Execute the PHPUnit command.
perform_operations( array(
$WPT_PHPUNIT_CMD
) );