‪TYPO3CMS  9.5
CommandTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
3 
5 
6 /*
7  * This file is part of the TYPO3 CMS project.
8  *
9  * It is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License, either version 2
11  * of the License, or any later version.
12  *
13  * For the full copyright and license information, please read the
14  * LICENSE.txt file that was distributed with this source code.
15  *
16  * The TYPO3 project - inspiring people to share!
17  */
18 
24 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
25 
29 class ‪CommandTest extends UnitTestCase
30 {
34  protected ‪$resetSingletonInstances = true;
35 
36  public function ‪testIsCliOnly()
37  {
38  $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
39  Command::class,
40  MockCCommandController::class,
41  'empty'
42  );
43 
44  static::assertFalse($commandController->isCliOnly());
45 
46  $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
47  Command::class,
48  MockCCommandController::class,
49  'cliOnly'
50  );
51 
52  static::assertTrue($commandController->isCliOnly());
53  }
54 
58  public function ‪commandIdentifiers()
59  {
60  return [
61 
62  ['Tx\ExtensionKey\Command\CacheCommandController', 'flush', 'extension_key:cache:flush'],
63  ['Tx\Ext\Command\CookieCommandController', 'bake', 'ext:cookie:bake'],
64  ['Tx\OtherExtensionKey\Foo\Faa\Fuuum\Command\CoffeeCommandController', 'brew', 'other_extension_key:coffee:brew'],
65  ];
66  }
67 
75  public function ‪constructRendersACommandIdentifierByTheGivenControllerAndCommandName($controllerClassName, $commandName, $expectedCommandIdentifier)
76  {
77  $command = new \TYPO3\CMS\Extbase\Mvc\Cli\Command($controllerClassName, $commandName);
78  $this->assertEquals($expectedCommandIdentifier, $command->getCommandIdentifier());
79  }
80 
84  public function ‪invalidCommandClassNames()
85  {
86  return [
87  [''],
88  // CommandClassName must not be empty
89  ['Foo']
90  ];
91  }
92 
98  public function ‪constructThrowsExceptionIfCommandClassNameIsInvalid($controllerClassName)
99  {
100  $this->expectException(\InvalidArgumentException::class);
101  $this->expectExceptionCode(1438782187);
102  new \TYPO3\CMS\Extbase\Mvc\Cli\Command($controllerClassName, 'foo');
103  }
104 
105  public function ‪testIsInternal()
106  {
107  $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
108  Command::class,
109  MockCCommandController::class,
110  'empty'
111  );
112 
113  static::assertFalse($commandController->isInternal());
114 
115  $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
116  Command::class,
117  MockCCommandController::class,
118  'internal'
119  );
120 
121  static::assertTrue($commandController->isInternal());
122  }
123 
124  public function ‪testIsFlushinCaches()
125  {
126  $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
127  Command::class,
128  MockCCommandController::class,
129  'empty'
130  );
131 
132  static::assertFalse($commandController->isFlushingCaches());
133 
134  $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
135  Command::class,
136  MockCCommandController::class,
137  'flushingCaches'
138  );
139 
140  static::assertTrue($commandController->isFlushingCaches());
141  }
142 
143  public function ‪testHasArguments()
144  {
145  $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
146  Command::class,
147  MockCCommandController::class,
148  'empty'
149  );
150 
151  static::assertFalse($commandController->hasArguments());
152 
153  $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
154  Command::class,
155  MockCCommandController::class,
156  'withArguments'
157  );
158 
159  static::assertTrue($commandController->hasArguments());
160  }
161 
162  public function ‪testGetArgumentDefinitions()
163  {
164  $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
165  Command::class,
166  MockCCommandController::class,
167  'empty'
168  );
169 
170  static::assertSame([], $commandController->getArgumentDefinitions());
171 
172  $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
173  Command::class,
174  MockCCommandController::class,
175  'withArguments'
176  );
177 
178  $expected = [
179  new ‪CommandArgumentDefinition('foo', true, 'FooParamDescription'),
180  new ‪CommandArgumentDefinition('bar', false, 'BarParamDescription'),
181  ];
182 
183  static::assertEquals($expected, $commandController->getArgumentDefinitions());
184  }
185 
186  public function ‪testGetDescription()
187  {
188  $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
189  Command::class,
190  MockCCommandController::class,
191  'empty'
192  );
193 
194  static::assertSame('', $commandController->getDescription());
195 
196  $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
197  Command::class,
198  MockCCommandController::class,
199  'withDescription'
200  );
201 
202  $expected = 'Longer Description' . LF .
203  'Multine' . LF . LF .
204  'Much Multiline';
205 
206  static::assertEquals($expected, $commandController->getDescription());
207  }
208 
209  public function ‪testGetShortDescription()
210  {
211  $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
212  Command::class,
213  MockCCommandController::class,
214  'empty'
215  );
216 
217  static::assertSame('', $commandController->getShortDescription());
218 
219  $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
220  Command::class,
221  MockCCommandController::class,
222  'withDescription'
223  );
224 
225  $expected = 'Short Description';
226 
227  static::assertEquals($expected, $commandController->getShortDescription());
228  }
229 
230  public function ‪testGetRelatedCommandIdentifiers()
231  {
232  $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
233  Command::class,
234  MockCCommandController::class,
235  'empty'
236  );
237 
238  static::assertSame([], $commandController->getRelatedCommandIdentifiers());
239 
240  $commandController = GeneralUtility::makeInstance(ObjectManager::class)->get(
241  Command::class,
242  MockCCommandController::class,
243  'relatedCommandIdentifiers'
244  );
245 
246  $expected = ['Foo:Bar:Baz'];
247  static::assertEquals($expected, $commandController->getRelatedCommandIdentifiers());
248  }
249 }
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Cli\CommandTest\testGetArgumentDefinitions
‪testGetArgumentDefinitions()
Definition: CommandTest.php:161
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Cli\CommandTest\$resetSingletonInstances
‪bool $resetSingletonInstances
Definition: CommandTest.php:33
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Cli\CommandTest\testIsCliOnly
‪testIsCliOnly()
Definition: CommandTest.php:35
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Cli\Fixture\Command\MockCCommandController
Definition: MockCCommandController.php:23
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Cli\CommandTest\invalidCommandClassNames
‪array invalidCommandClassNames()
Definition: CommandTest.php:83
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Cli\CommandTest\constructThrowsExceptionIfCommandClassNameIsInvalid
‪constructThrowsExceptionIfCommandClassNameIsInvalid($controllerClassName)
Definition: CommandTest.php:97
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Cli\CommandTest\testGetDescription
‪testGetDescription()
Definition: CommandTest.php:185
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Cli\CommandTest\testIsFlushinCaches
‪testIsFlushinCaches()
Definition: CommandTest.php:123
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Cli\CommandTest\commandIdentifiers
‪array commandIdentifiers()
Definition: CommandTest.php:57
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Cli\CommandTest\testGetRelatedCommandIdentifiers
‪testGetRelatedCommandIdentifiers()
Definition: CommandTest.php:229
‪TYPO3\CMS\Extbase\Mvc\Cli\Command
Definition: Command.php:25
‪TYPO3\CMS\Extbase\Mvc\Cli\CommandArgumentDefinition
Definition: CommandArgumentDefinition.php:23
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Cli\CommandTest\constructRendersACommandIdentifierByTheGivenControllerAndCommandName
‪constructRendersACommandIdentifierByTheGivenControllerAndCommandName($controllerClassName, $commandName, $expectedCommandIdentifier)
Definition: CommandTest.php:74
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:25
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Cli\CommandTest\testIsInternal
‪testIsInternal()
Definition: CommandTest.php:104
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Cli\CommandTest
Definition: CommandTest.php:30
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Cli\CommandTest\testHasArguments
‪testHasArguments()
Definition: CommandTest.php:142
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Cli
Definition: CommandManagerTest.php:2
‪TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Cli\CommandTest\testGetShortDescription
‪testGetShortDescription()
Definition: CommandTest.php:208