| Server IP : 104.21.73.115 / Your IP : 216.73.217.154 Web Server : Apache System : Linux vps42439 6.8.0-136-generic #136~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Jul 3 16:29:11 UTC x86_64 User : dh_7hi3h9 ( 6349477) PHP Version : 8.3.30 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /usr/local/wp/tests/ |
Upload File : |
<?php
use WP_CLI\Process;
use WP_CLI\Tests\TestCase;
use WP_CLI\Utils;
class ProcessTest extends TestCase {
/**
* @dataProvider data_process_env
*/
public 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 );
}
public static function data_process_env() {
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' ],
];
}
}