expectException(ChildException::class); try { set_error_handler(ChildException::handleError(...)); trigger_error('Oh no!'); } finally { restore_error_handler(); } } public function test(): void { $command = new Command('echo'); $this->assertEquals( 'echo', $command->getProgram(), ); $this->assertNull($command->getCurrentDir()); $command->currentDir('/tmp'); $this->assertEquals( '/tmp', $command->getCurrentDir(), ); $command->arg('foo')->args(['bar', 'baz']); $this->assertEquals( ['foo', 'bar', 'baz'], $command->getArgs(), ); $command->env('FOO', 'foo'); $this->assertEquals( ['FOO' => 'foo'], $command->getEnvs(), ); $command->envs([ 'BAR' => 'bar', 'BAZ' => 'baz', ]); $this->assertEquals( [ 'FOO' => 'foo', 'BAR' => 'bar', 'BAZ' => 'baz', ], $command->getEnvs(), ); $command->envRemove('BAR'); $this->assertEquals( [ 'FOO' => 'foo', 'BAR' => null, 'BAZ' => 'baz', ], $command->getEnvs(), ); $command->envClear(); $this->assertEquals( [], $command->getEnvs(), ); } public function testStdioFromStream(): void { // Only verifies its okay to pass valid stream resources. $this->expectNotToPerformAssertions(); new Command('echo') ->stdin(STDIN) ->stdout(STDOUT) ->stderr(STDERR); } public function testThrowsOnEmptyProgram(): void { $this->expectException(ValueError::class); new Command(''); } public function testToString(): void { $this->assertEquals( "'ls' '*' 'foo bar'", (string) new Command('ls')->arg('*')->arg('foo bar'), ); } }