forked from wp-cli/wp-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-process.php
More file actions
29 lines (23 loc) · 1.05 KB
/
test-process.php
File metadata and controls
29 lines (23 loc) · 1.05 KB
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
<?php
use WP_CLI\Process;
use WP_CLI\Utils;
class ProcessTests extends PHPUnit_Framework_TestCase {
/**
* @dataProvider data_process_env
*/
function test_process_env( $cmd_prefix, $env, $expected_env_vars, $expected_out ) {
$code = vsprintf( str_repeat( 'echo getenv( \'%s\' );', count( $expected_env_vars ) ), $expected_env_vars );
$cmd = $cmd_prefix . ' ' . escapeshellarg( Utils\get_php_binary() ) . ' -r ' . escapeshellarg( $code );
$process_run = Process::create( $cmd, null /*cwd*/, $env )->run();
$this->assertSame( $process_run->stdout, $expected_out );
}
function data_process_env() {
return array(
array( '', array(), array(), '' ),
array( 'ENV=blah', array(), array( 'ENV' ), 'blah' ),
array( 'ENV="blah blah"', array(), array( 'ENV' ), 'blah blah' ),
array( 'ENV_1="blah1 blah1" ENV_2="blah2" ENV_3=blah3', array( 'ENV' => 'in' ), array( 'ENV', 'ENV_1', 'ENV_2', 'ENV_3' ), 'inblah1 blah1blah2blah3' ),
array( 'ENV=blah', array( 'ENV_1' => 'in1', 'ENV_2' => 'in2' ), array( 'ENV_1', 'ENV_2', 'ENV' ), 'in1in2blah' ),
);
}
}