/** * Tests running a background process. * * @covers Cocur\BackgroundProcess\BackgroundProcess::__construct() * @covers Cocur\BackgroundProcess\BackgroundProcess::run() * @covers Cocur\BackgroundProcess\BackgroundProcess::isRunning() * @covers Cocur\BackgroundProcess\BackgroundProcess::getPid() * @covers Cocur\BackgroundProcess\BackgroundProcess::stop() */ public function testRun() { $process = new BackgroundProcess('sleep 5'); $this->assertFalse($process->isRunning(), 'process should not run'); $process->run(); $this->assertNotNull($process->getPid(), 'process should have a pid'); $this->assertTrue($process->isRunning(), 'process should run'); $this->assertTrue($process->stop(), 'stop process'); $this->assertFalse($process->isRunning(), 'processes should not run anymore'); $this->assertFalse($process->stop(), 'cannot stop process that is not running'); }
/** * @test * @covers Cocur\BackgroundProcess\BackgroundProcess::getPid() * @expectedException \RuntimeException */ public function getPidShouldThrowExceptionIfWindows() { if (!preg_match('/^WIN/', PHP_OS)) { $this->markTestSkipped('Cocur\\BackgroundProcess\\BackgroundProcess::getPid() is supported on *nix systems ' . 'and does not need to throw an exception.'); return; } $process = new BackgroundProcess('sleep 1'); $process->getPid(); }