public function testExecuteCommand() { foreach ($this->argList as $arg => $value) { $this->input->shouldReceive("getArgument")->withArgs([$arg])->once()->andReturn($value); } $this->runnerFactory->shouldReceive("createRunner")->withArgs([$this->argList["type"], "", $this->argList["maxRunCount"]])->once(); $this->runner->shouldReceive("execute")->withArgs([$this->argList["threadCommand"]])->once(); $command = new ThreadCommand("thread:command", $this->runnerFactory); $command->execute($this->input, $this->output); }
public function testDestruct() { $instances = 3; $serviceConfig = ["command" => ["instances" => $instances, "command" => "command", "type" => "console"]]; // set up # test runs $this->input->shouldReceive("hasOption")->andReturn(true); $this->input->shouldReceive("getOption")->andReturn($instances); // run the command $command = new PoolCommand("pool:command", "thread:command", "pool.pid", $this->pidFactory, $this->runnerFactory, $serviceConfig, 50000); $command->execute($this->input, $this->output); $this->runner->shouldReceive("finish")->times(3); $command->__destruct(); }
public function testRestart() { $poolCommand = "pool:command"; // running two tests, both should execute the command $this->runner->shouldReceive("execute")->withArgs([$poolCommand, false])->twice(); $this->input->shouldReceive("getArgument")->andReturn("restart"); // test when pool is running // setup process to kill $timeout = 50000; $pidFilePath = "test.pid"; $startTime = $this->startChildProcess($timeout, $pidFilePath); // create command $command = new PoolControlCommand($this->runnerFactory, $this->pidFactory, $this->getPath($pidFilePath), $poolCommand); // run the stop command $command->execute($this->input, $this->output); // check the timing. duration should be less than the process timeout $duration = microtime(true) - $startTime; $timeout /= 1000000; $this->assertLessThan($timeout, $duration, "duration, {$duration}, was greater than timeout, {$timeout}"); // test when pool is stopped vfsStreamWrapper::getRoot()->removeChild($pidFilePath); $command->execute($this->input, $this->output); }
public function __destruct() { if ($this->runner instanceof RunnerInterface) { $this->runner->finish(); } }