2 namespace TYPO3\CMS\Extbase\Tests\Unit\Mvc\Cli
;
5 * This script belongs to the Extbase framework. *
7 * It is free software; you can redistribute it and/or modify it under *
8 * the terms of the GNU Lesser General Public License as published by the *
9 * Free Software Foundation, either version 3 of the License, or (at your *
10 * option) any later version. *
12 * This script is distributed in the hope that it will be useful, but *
13 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHAN- *
14 * TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser *
15 * General Public License for more details. *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with the script. *
19 * If not, see http://www.gnu.org/licenses/lgpl.html *
21 * The TYPO3 project - inspiring people to share! *
24 use TYPO3\CMS\Core\Utility\GeneralUtility
;
25 use TYPO3\CMS\Extbase\Mvc\Cli\Command
;
26 use TYPO3\CMS\Extbase\Mvc\Cli\CommandArgumentDefinition
;
27 use TYPO3\CMS\Extbase\
Object\ObjectManager
;
28 use TYPO3\CMS\Extbase\Tests\Unit\Mvc\Cli\Fixture\Command\MockCCommandController
;
29 use TYPO3\TestingFramework\Core\Unit\UnitTestCase
;
34 class CommandTest
extends UnitTestCase
37 * @var bool Reset singletons created by subject
39 protected $resetSingletonInstances = true;
44 public function commandIdentifiers()
48 ['Tx\ExtensionKey\Command\CacheCommandController', 'flush', 'extension_key:cache:flush'],
49 ['Tx\Ext\Command\CookieCommandController', 'bake', 'ext:cookie:bake'],
50 ['Tx\OtherExtensionKey\Foo\Faa\Fuuum\Command\CoffeeCommandController', 'brew', 'other_extension_key:coffee:brew'],
56 * @dataProvider commandIdentifiers
57 * @param string $controllerClassName
58 * @param string $commandName
59 * @param string $expectedCommandIdentifier
61 public function constructRendersACommandIdentifierByTheGivenControllerAndCommandName($controllerClassName, $commandName, $expectedCommandIdentifier)
63 $command = new \TYPO3\CMS\Extbase\Mvc\Cli\
Command($controllerClassName, $commandName);
64 $this->assertEquals($expectedCommandIdentifier, $command->getCommandIdentifier());
70 public function invalidCommandClassNames()
74 // CommandClassName must not be empty
81 * @dataProvider invalidCommandClassNames
82 * @param string $controllerClassName
84 public function constructThrowsExceptionIfCommandClassNameIsInvalid($controllerClassName)
86 $this->expectException(\InvalidArgumentException
::class);
87 $this->expectExceptionCode(1438782187);
88 new \TYPO3\CMS\Extbase\Mvc\Cli\
Command($controllerClassName, 'foo');
91 public function testIsInternal()
93 $commandController = GeneralUtility
::makeInstance(ObjectManager
::class)->get(
95 MockCCommandController
::class,
99 static::assertFalse($commandController->isInternal());
101 $commandController = GeneralUtility
::makeInstance(ObjectManager
::class)->get(
103 MockCCommandController
::class,
107 static::assertTrue($commandController->isInternal());
110 public function testIsCliOnly()
112 $commandController = GeneralUtility
::makeInstance(ObjectManager
::class)->get(
114 MockCCommandController
::class,
118 static::assertFalse($commandController->isCliOnly());
120 $commandController = GeneralUtility
::makeInstance(ObjectManager
::class)->get(
122 MockCCommandController
::class,
126 static::assertTrue($commandController->isCliOnly());
129 public function testIsFlushinCaches()
131 $commandController = GeneralUtility
::makeInstance(ObjectManager
::class)->get(
133 MockCCommandController
::class,
137 static::assertFalse($commandController->isFlushingCaches());
139 $commandController = GeneralUtility
::makeInstance(ObjectManager
::class)->get(
141 MockCCommandController
::class,
145 static::assertTrue($commandController->isFlushingCaches());
148 public function testHasArguments()
150 $commandController = GeneralUtility
::makeInstance(ObjectManager
::class)->get(
152 MockCCommandController
::class,
156 static::assertFalse($commandController->hasArguments());
158 $commandController = GeneralUtility
::makeInstance(ObjectManager
::class)->get(
160 MockCCommandController
::class,
164 static::assertTrue($commandController->hasArguments());
167 public function testGetArgumentDefinitions()
169 $commandController = GeneralUtility
::makeInstance(ObjectManager
::class)->get(
171 MockCCommandController
::class,
175 static::assertSame([], $commandController->getArgumentDefinitions());
177 $commandController = GeneralUtility
::makeInstance(ObjectManager
::class)->get(
179 MockCCommandController
::class,
184 new CommandArgumentDefinition('foo', true, 'FooParamDescription'),
185 new CommandArgumentDefinition('bar', false, 'BarParamDescription'),
188 static::assertEquals($expected, $commandController->getArgumentDefinitions());
191 public function testGetDescription()
193 $commandController = GeneralUtility
::makeInstance(ObjectManager
::class)->get(
195 MockCCommandController
::class,
199 static::assertSame('', $commandController->getDescription());
201 $commandController = GeneralUtility
::makeInstance(ObjectManager
::class)->get(
203 MockCCommandController
::class,
207 $expected = 'Longer Description' . LF
.
208 'Multine' . LF
. LF
.
211 static::assertEquals($expected, $commandController->getDescription());
214 public function testGetShortDescription()
216 $commandController = GeneralUtility
::makeInstance(ObjectManager
::class)->get(
218 MockCCommandController
::class,
222 static::assertSame('', $commandController->getShortDescription());
224 $commandController = GeneralUtility
::makeInstance(ObjectManager
::class)->get(
226 MockCCommandController
::class,
230 $expected = 'Short Description';
232 static::assertEquals($expected, $commandController->getShortDescription());
235 public function testGetRelatedCommandIdentifiers()
237 $commandController = GeneralUtility
::makeInstance(ObjectManager
::class)->get(
239 MockCCommandController
::class,
243 static::assertSame([], $commandController->getRelatedCommandIdentifiers());
245 $commandController = GeneralUtility
::makeInstance(ObjectManager
::class)->get(
247 MockCCommandController
::class,
248 'relatedCommandIdentifiers'
251 $expected = ['Foo:Bar:Baz'];
252 static::assertEquals($expected, $commandController->getRelatedCommandIdentifiers());