public function onPost() { parent::onPost(); $commandClass = $this->getParameter('command'); $parameters = $this->getBody(); $parameters = !empty($parameters) ? $parameters : array(); if (!empty($commandClass)) { $stream = fopen('php://memory', 'r+'); $this->logger->pushHandler(new StreamHandler($stream, Logger::DEBUG)); $this->executor->run(new ParameterParser\Map($commandClass, $parameters)); $output = stream_get_contents($stream, -1, 0); $this->logger->popHandler(); $this->setBody(array('output' => $output)); } else { throw new \Exception('Command not available'); } }
public function testErrorCommand() { $command = new TestCommand(function (Parameters $parameters) { throw new \Exception('foo'); }); $factory = $this->getMockBuilder('PSX\\Dispatch\\CommandFactoryInterface')->setMethods(array('getCommand'))->getMock(); $factory->expects($this->at(0))->method('getCommand')->with($this->identicalTo('Foo\\Bar'))->will($this->returnValue($command)); $factory->expects($this->at(1))->method('getCommand')->with($this->identicalTo('PSX\\Command\\ErrorCommand'))->will($this->returnValue(Environment::getService('command_factory')->getCommand('PSX\\Command\\ErrorCommand', new Context()))); $executor = new Executor($factory, new Void(), Environment::getService('event_dispatcher')); $executor->run(new Map('Foo\\Bar', array('r' => 'foo'))); }