-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathProcessTest.php
More file actions
32 lines (26 loc) · 1.19 KB
/
ProcessTest.php
File metadata and controls
32 lines (26 loc) · 1.19 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
30
31
32
<?php
use WP_CLI\Process;
use WP_CLI\Tests\TestCase;
use WP_CLI\Utils;
use PHPUnit\Framework\Attributes\DataProvider;
class ProcessTest extends TestCase {
/**
* @dataProvider data_process_env
*/
#[DataProvider( 'data_process_env' )] // phpcs:ignore PHPCompatibility.Attributes.NewAttributes.PHPUnitAttributeFound
public function test_process_env( $cmd_prefix, $env, $expected_env_vars, $expected_out ): void {
$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 );
}
public static function data_process_env(): array {
return [
[ '', [], [], '' ],
[ 'ENV=blah', [], [ 'ENV' ], 'blah' ],
[ 'ENV="blah blah"', [], [ 'ENV' ], 'blah blah' ],
[ 'ENV_1="blah1 blah1" ENV_2="blah2" ENV_3=blah3', [ 'ENV' => 'in' ], [ 'ENV', 'ENV_1', 'ENV_2', 'ENV_3' ], 'inblah1 blah1blah2blah3' ],
[ 'ENV=blah', [ 'ENV_1' => 'in1', 'ENV_2' => 'in2' ], [ 'ENV_1', 'ENV_2', 'ENV' ], 'in1in2blah' ],
];
}
}