19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
36 protected function setUp()
38 $this->commandManager = $this->getAccessibleMock(\
TYPO3\CMS\
Extbase\Mvc\Cli\CommandManager::class, [
'getAvailableCommands']);
39 $this->mockObjectManager = $this->createMock(\
TYPO3\CMS\
Extbase\Object\ObjectManagerInterface::class);
40 $this->commandManager->_set(
'objectManager', $this->mockObjectManager);
51 $GLOBALS[
'TYPO3_CONF_VARS'][
'SC_OPTIONS'][
'extbase'][
'commandControllers'] = [
52 \TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Cli\Fixture\Command\MockACommandController::class,
53 \TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Cli\Fixture\Command\MockBCommandController::class
55 $mockCommand1 = $this->createMock(\
TYPO3\CMS\
Extbase\Mvc\Cli\Command::class);
56 $mockCommand2 = $this->createMock(\
TYPO3\CMS\
Extbase\Mvc\Cli\Command::class);
57 $mockCommand3 = $this->createMock(\
TYPO3\CMS\
Extbase\Mvc\Cli\Command::class);
58 $this->mockObjectManager->expects($this->at(0))->method(
'get')->with(\
TYPO3\CMS\
Extbase\Mvc\Cli\Command::class, \
TYPO3\CMS\
Extbase\Tests\UnitDeprecated\Mvc\Cli\Fixture\
Command\MockACommandController::class,
'foo')->will($this->returnValue($mockCommand1));
59 $this->mockObjectManager->expects($this->at(1))->method(
'get')->with(\
TYPO3\CMS\
Extbase\Mvc\Cli\Command::class, \
TYPO3\CMS\
Extbase\Tests\UnitDeprecated\Mvc\Cli\Fixture\
Command\MockACommandController::class,
'bar')->will($this->returnValue($mockCommand2));
60 $this->mockObjectManager->expects($this->at(2))->method(
'get')->with(\
TYPO3\CMS\
Extbase\Mvc\Cli\Command::class, \
TYPO3\CMS\
Extbase\Tests\UnitDeprecated\Mvc\Cli\Fixture\
Command\MockBCommandController::class,
'baz')->will($this->returnValue($mockCommand3));
62 $this->assertEquals(3, count($commands));
63 $this->assertSame($mockCommand1, $commands[0]);
64 $this->assertSame($mockCommand2, $commands[1]);
65 $this->assertSame($mockCommand3, $commands[2]);
73 $mockCommand = $this->createMock(\
TYPO3\CMS\
Extbase\Mvc\Cli\Command::class);
74 $mockCommand->expects($this->once())->method(
'getCommandIdentifier')->will($this->returnValue(
'extensionkey:controller:command'));
75 $mockCommands = [$mockCommand];
76 $this->commandManager->expects($this->once())->method(
'getAvailableCommands')->will($this->returnValue($mockCommands));
77 $this->assertSame($mockCommand, $this->commandManager->getCommandByIdentifier(
'extensionkey:controller:command'));
85 $mockCommand = $this->createMock(\
TYPO3\CMS\
Extbase\Mvc\Cli\Command::class);
86 $mockCommand->expects($this->once())->method(
'getCommandIdentifier')->will($this->returnValue(
'extensionkey:controller:command'));
87 $mockCommands = [$mockCommand];
88 $this->commandManager->expects($this->once())->method(
'getAvailableCommands')->will($this->returnValue($mockCommands));
89 $this->assertSame($mockCommand, $this->commandManager->getCommandByIdentifier(
' ExtensionKey:conTroLler:Command '));
97 $this->expectException(NoSuchCommandException::class);
98 $this->expectExceptionCode(1310556663);
99 $mockCommand = $this->createMock(\
TYPO3\CMS\
Extbase\Mvc\Cli\Command::class);
100 $mockCommand->expects($this->once())->method(
'getCommandIdentifier')->will($this->returnValue(
'extensionkey:controller:command'));
101 $mockCommands = [$mockCommand];
102 $this->commandManager->expects($this->once())->method(
'getAvailableCommands')->will($this->returnValue($mockCommands));
103 $this->commandManager->getCommandByIdentifier(
'extensionkey:controller:someothercommand');
111 $this->expectException(AmbiguousCommandIdentifierException::class);
112 $this->expectExceptionCode(1310557169);
113 $mockCommand1 = $this->createMock(\
TYPO3\CMS\
Extbase\Mvc\Cli\Command::class);
114 $mockCommand1->expects($this->once())->method(
'getCommandIdentifier')->will($this->returnValue(
'extensionkey:controller:command'));
115 $mockCommand2 = $this->createMock(\
TYPO3\CMS\
Extbase\Mvc\Cli\Command::class);
116 $mockCommand2->expects($this->once())->method(
'getCommandIdentifier')->will($this->returnValue(
'otherextensionkey:controller:command'));
117 $mockCommands = [$mockCommand1, $mockCommand2];
118 $this->commandManager->expects($this->once())->method(
'getAvailableCommands')->will($this->returnValue($mockCommands));
119 $this->commandManager->getCommandByIdentifier(
'controller:command');