Neos\Flow\Cli\CommandManager::getAvailableCommands PHP Method

getAvailableCommands() public method

Returns an array of all commands
public getAvailableCommands ( ) : array
return array
    public function getAvailableCommands()
    {
        if ($this->availableCommands === null) {
            $this->availableCommands = [];
            foreach (static::getCommandControllerMethodArguments($this->objectManager) as $className => $methods) {
                foreach (array_keys($methods) as $methodName) {
                    $this->availableCommands[] = new Command($className, substr($methodName, 0, -7));
                }
            }
        }
        return $this->availableCommands;
    }

Usage Example

 /**
  * @test
  */
 public function getAvailableCommandsReturnsAllAvailableCommands()
 {
     $commandManager = new CommandManager();
     $mockCommandControllerClassNames = array(Fixtures\Command\MockACommandController::class, Fixtures\Command\MockBCommandController::class);
     $this->mockReflectionService->expects($this->once())->method('getAllSubClassNamesForClass')->with(Cli\CommandController::class)->will($this->returnValue($mockCommandControllerClassNames));
     $mockObjectManager = $this->createMock(ObjectManagerInterface::class);
     $mockObjectManager->expects($this->any())->method('get')->with(ReflectionService::class)->willReturn($this->mockReflectionService);
     $commandManager->injectObjectManager($mockObjectManager);
     $commands = $commandManager->getAvailableCommands();
     $this->assertEquals(3, count($commands));
     $this->assertEquals('neos.flow.tests.unit.cli.fixtures:mocka:foo', $commands[0]->getCommandIdentifier());
     $this->assertEquals('neos.flow.tests.unit.cli.fixtures:mocka:bar', $commands[1]->getCommandIdentifier());
     $this->assertEquals('neos.flow.tests.unit.cli.fixtures:mockb:baz', $commands[2]->getCommandIdentifier());
 }