public function testProcOpenFail()
 {
     $this->skipIfNotUnix();
     $this->setExpectedException('ptlis\\ShellCommand\\Exceptions\\CommandExecutionException', 'Call to proc_terminate with signal "' . ProcessInterface::SIGTERM . '" failed for unknown reason.');
     $command = './tests/commands/unix/test_binary';
     $process = new Process(new UnixEnvironment(), $command, getcwd());
     $process->stop();
 }
 public function testCalled()
 {
     $this->skipIfNotUnix();
     $command = './tests/commands/unix/test_binary';
     $mockLogger = new MockPsrLogger();
     $process = new Process(new UnixEnvironment(), $command, getcwd(), -1, 1000, new AllLogger($mockLogger));
     $process->wait();
     $this->assertLogsMatch(array(array('level' => LogLevel::DEBUG, 'message' => 'Process created', 'context' => array('command' => './tests/commands/unix/test_binary')), array('level' => LogLevel::DEBUG, 'message' => 'Read from stdout', 'context' => array('stdout' => 'Test command' . PHP_EOL . PHP_EOL)), array('level' => LogLevel::DEBUG, 'message' => 'Process exited', 'context' => array('exit_code' => 0))), $mockLogger->getLogs());
 }
 public function testSendSignal()
 {
     $this->skipIfNotUnix();
     $command = './tests/commands/unix/sleep_binary';
     $mockLogger = new MockPsrLogger();
     $process = new Process(new UnixEnvironment(), $command, getcwd(), -1, 1000, new ErrorLogger($mockLogger));
     $process->stop();
     $this->assertLogsMatch(array(array('level' => LogLevel::ERROR, 'message' => 'Process exited', 'context' => array('exit_code' => -1))), $mockLogger->getLogs());
 }
 public function testErrorGetPidNotRunning()
 {
     $this->skipIfNotWindows();
     $this->setExpectedException('RuntimeException', 'Cannot get the process id of a process that has already exited.');
     $command = 'tests\\commands\\windows\\test.bat';
     $process = new Process(new WindowsEnvironment(), $command, getcwd());
     $process->wait();
     $process->getPid();
 }
 public function testAggregateLogger()
 {
     $this->skipIfNotUnix();
     $command = './tests/commands/unix/long_sleep_binary';
     $mockLogger = new MockPsrLogger();
     $allLogger = new AllLogger($mockLogger);
     $process = new Process(new UnixEnvironment(), $command, getcwd(), -1, 1000, new AggregateLogger(array($allLogger, new NullProcessObserver())));
     $process->sendSignal(Process::SIGTERM);
     $process->wait();
     $this->assertLogsMatch(array(array('level' => LogLevel::DEBUG, 'message' => 'Process created', 'context' => array('command' => './tests/commands/unix/long_sleep_binary')), array('level' => LogLevel::DEBUG, 'message' => 'Signal sent', 'context' => array('signal' => 'SIGTERM')), array('level' => LogLevel::DEBUG, 'message' => 'Process exited', 'context' => array('exit_code' => -1))), $mockLogger->getLogs());
 }
 /**
  * {@inheritDoc}
  */
 public function sendSignal($signal)
 {
     // Only send signal when not sigterm.
     if (Process::SIGTERM !== $signal) {
         parent::sendSignal($signal);
     }
 }
Example #7
0
 public function testSendInvalidSignal()
 {
     $this->skipIfNotUnix();
     $this->setExpectedException('\\ptlis\\ShellCommand\\Exceptions\\CommandExecutionException', 'Unknown signal "wibble" provided');
     $command = './tests/commands/unix/long_sleep_binary';
     $process = new Process(new UnixEnvironment(), $command, getcwd(), 500000, 1000, new NullProcessObserver());
     $process->sendSignal('wibble');
 }