public getCommandByIdentifier ( string $commandIdentifier ) : |
||
$commandIdentifier | string | command identifier in the format foo:bar:baz |
return |
public function getCommandByIdentifier($commandIdentifier)
{
$commandIdentifier = strtolower(trim($commandIdentifier));
if ($commandIdentifier === 'help') {
$commandIdentifier = 'neos.flow:help:help';
}
if ($commandIdentifier === 'sys') {
$commandIdentifier = 'neos.flow:cache:sys';
}
$matchedCommands = $this->getCommandsByIdentifier($commandIdentifier);
if (count($matchedCommands) === 0) {
throw new NoSuchCommandException('No command could be found that matches the command identifier "' . $commandIdentifier . '".', 1310556663);
}
if (count($matchedCommands) > 1) {
throw new AmbiguousCommandIdentifierException('More than one command matches the command identifier "' . $commandIdentifier . '"', 1310557169, null, $matchedCommands);
}
return current($matchedCommands);
}
/** * @test */ public function ifCommandCantBeResolvedTheHelpScreenIsShown() { // The following call is only made to satisfy PHPUnit. For some weird reason PHPUnit complains that the // mocked method ("getObjectNameByClassName") does not exist _if the mock object is not used_. $this->mockObjectManager->getObjectNameByClassName('Acme\\Test\\Command\\DefaultCommandController'); $this->mockCommandManager->getCommandByIdentifier('acme.test:default:list'); $mockCommandManager = $this->createMock(Cli\CommandManager::class); $mockCommandManager->expects($this->any())->method('getCommandByIdentifier')->with('test:default:list')->will($this->throwException(new NoSuchCommandException())); $this->requestBuilder->injectCommandManager($mockCommandManager); $request = $this->requestBuilder->build('test:default:list'); $this->assertSame(HelpCommandController::class, $request->getControllerObjectName()); }