public function onGet() { parent::onGet(); $commandClass = $this->getParameter('command'); if (!empty($commandClass)) { $command = $this->commandFactory->getCommand($commandClass, new Context()); $parameters = $command->getParameters(); $data = array(); foreach ($parameters as $parameter) { $data[] = new Record('parameter', ['name' => $parameter->getName(), 'description' => $parameter->getDescription(), 'type' => $parameter->getType()]); } $this->setBody(array('command' => $commandClass, 'description' => $parameters->getDescription(), 'parameters' => $data)); } else { $this->setBody(array('commands' => (object) $this->executor->getAliases())); } }
public function testAlias() { $command = new TestCommand(function (Parameters $parameters) { }); $factory = $this->getMockBuilder('PSX\\Dispatch\\CommandFactoryInterface')->setMethods(array('getCommand'))->getMock(); $factory->expects($this->once())->method('getCommand')->with($this->identicalTo('Foo\\Bar'))->will($this->returnValue($command)); $executor = new Executor($factory, new Void(), Environment::getService('event_dispatcher')); $executor->addAlias('foo', 'Foo\\Bar'); $executor->run(new Map('foo', array('r' => 'foo'))); $this->assertEquals('bar', $executor->getClassName('bar')); $this->assertEquals('Foo\\Bar', $executor->getClassName('foo')); $this->assertEquals(array('foo' => 'Foo\\Bar'), $executor->getAliases()); }