‪TYPO3CMS  9.5
CommandManagerTest.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
20 
24 class ‪CommandManagerTest extends UnitTestCase
25 {
29  protected ‪$mockObjectManager;
30 
34  protected ‪$commandManager;
35 
36  protected function ‪setUp()
37  {
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);
41  }
42 
47  {
49  ‪$commandManager = $this->getAccessibleMock(\‪TYPO3\CMS\‪Extbase\Mvc\Cli\CommandManager::class, ['dummy']);
50  ‪$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
54  ];
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));
61  $commands = ‪$commandManager->getAvailableCommands();
62  $this->assertEquals(3, count($commands));
63  $this->assertSame($mockCommand1, $commands[0]);
64  $this->assertSame($mockCommand2, $commands[1]);
65  $this->assertSame($mockCommand3, $commands[2]);
66  }
67 
72  {
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'));
78  }
79 
84  {
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 '));
90  }
91 
96  {
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');
104  }
105 
110  {
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');
120  }
121 }
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Cli\CommandManagerTest\setUp
‪setUp()
Definition: CommandManagerTest.php:34
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3\CMS\Extbase\Mvc\Exception\NoSuchCommandException
Definition: NoSuchCommandException.php:21
‪TYPO3
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Cli\CommandManagerTest\getCommandByIdentifierWorksCaseInsensitive
‪getCommandByIdentifierWorksCaseInsensitive()
Definition: CommandManagerTest.php:81
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Cli\CommandManagerTest\$commandManager
‪TYPO3 CMS Extbase Mvc Cli CommandManager $commandManager
Definition: CommandManagerTest.php:32
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Cli\CommandManagerTest\getCommandByIdentifierThrowsExceptionIfMoreThanOneMatchingCommandWasFound
‪getCommandByIdentifierThrowsExceptionIfMoreThanOneMatchingCommandWasFound()
Definition: CommandManagerTest.php:107
‪TYPO3\CMS\Extbase\Mvc\Exception\AmbiguousCommandIdentifierException
Definition: AmbiguousCommandIdentifierException.php:23
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Cli\CommandManagerTest\getCommandByIdentifierReturnsCommandIfIdentifierIsEqual
‪getCommandByIdentifierReturnsCommandIfIdentifierIsEqual()
Definition: CommandManagerTest.php:69
‪TYPO3\CMS\Extbase\Mvc\Cli\Command
Definition: Command.php:25
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Cli\CommandManagerTest\$mockObjectManager
‪TYPO3 CMS Extbase Object ObjectManagerInterface $mockObjectManager
Definition: CommandManagerTest.php:28
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Cli\CommandManagerTest\getAvailableCommandsReturnsAllAvailableCommands
‪getAvailableCommandsReturnsAllAvailableCommands()
Definition: CommandManagerTest.php:44
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Cli\CommandManagerTest\getCommandByIdentifierThrowsExceptionIfNoMatchingCommandWasFound
‪getCommandByIdentifierThrowsExceptionIfNoMatchingCommandWasFound()
Definition: CommandManagerTest.php:93
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Cli\CommandManagerTest
Definition: CommandManagerTest.php:25
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Cli
Definition: CommandManagerTest.php:2