19 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
64 protected function setUp()
66 $this->request = $this->getAccessibleMock(\
TYPO3\CMS\
Extbase\Mvc\Cli\Request::class, [
'dummy']);
67 $this->mockObjectManager = $this->createMock(\
TYPO3\CMS\
Extbase\Object\ObjectManagerInterface::class);
68 $this->mockObjectManager->expects($this->any())->method(
'get')->with(\
TYPO3\CMS\
Extbase\Mvc\Cli\Request::class)->will($this->returnValue($this->request));
69 $this->mockCommand = $this->createMock(\
TYPO3\CMS\
Extbase\Mvc\Cli\Command::class);
70 $this->mockCommand->expects($this->any())->method(
'getControllerClassName')->will($this->returnValue(
'Tx\\SomeExtensionName\\Command\\DefaultCommandController'));
71 $this->mockCommand->expects($this->any())->method(
'getControllerCommandName')->will($this->returnValue(
'list'));
72 $this->mockCommandManager = $this->createMock(\
TYPO3\CMS\
Extbase\Mvc\Cli\CommandManager::class);
73 $this->mockCommandManager->expects($this->any())->method(
'getCommandByIdentifier')->with(
'some_extension_name:default:list')->will($this->returnValue($this->mockCommand));
74 $this->mockReflectionService = $this->createMock(\
TYPO3\CMS\
Extbase\Reflection\ReflectionService::class);
75 $this->mockConfigurationManager = $this->createMock(\
TYPO3\CMS\
Extbase\Configuration\ConfigurationManagerInterface::class);
76 $this->requestBuilder = $this->getAccessibleMock(\
TYPO3\CMS\
Extbase\Mvc\Cli\RequestBuilder::class, [
'dummy']);
77 $this->requestBuilder->_set(
'objectManager', $this->mockObjectManager);
78 $this->requestBuilder->_set(
'reflectionService', $this->mockReflectionService);
79 $this->requestBuilder->_set(
'commandManager', $this->mockCommandManager);
80 $this->requestBuilder->_set(
'configurationManager', $this->mockConfigurationManager);
90 $classSchemaMock = $this->createMock(ClassSchema::class);
91 $classSchemaMock->expects($this->any())->method(
'getMethod')->with(
'listCommand')->willReturn([
95 $this->mockReflectionService->expects($this->any())->method(
'getClassSchema')->with(
'Tx\\SomeExtensionName\\Command\\DefaultCommandController')->willReturn($classSchemaMock);
96 $request = $this->requestBuilder->build(
'some_extension_name:default:list');
97 $this->assertSame(
'Tx\\SomeExtensionName\\Command\\DefaultCommandController',
$request->getControllerObjectName());
98 $this->assertSame(
'list',
$request->getControllerCommandName(),
'The CLI request specifying a package, controller and action name did not return a request object pointing to the expected action.');
108 $this->mockCommandManager->getCommandByIdentifier(
'some_extension_name:default:list');
111 ->expects($this->any())
112 ->method(
'getCommandByIdentifier')
113 ->with(
'test:default:list')
115 $this->throwException(
120 $request = $this->requestBuilder->build(
'test:default:list');
129 $methodParameters = [
130 'testArgument' => [
'optional' =>
false,
'type' =>
'string']
133 $classSchemaMock = $this->createMock(ClassSchema::class);
134 $classSchemaMock->expects($this->any())->method(
'getMethod')->with(
'listCommand')->willReturn([
135 'params' => $methodParameters
138 $this->mockReflectionService->expects($this->any())->method(
'getClassSchema')->with(
'Tx\\SomeExtensionName\\Command\\DefaultCommandController')->willReturn($classSchemaMock);
139 $request = $this->requestBuilder->build(
'some_extension_name:default:list --test-argument=value');
140 $this->assertTrue(
$request->hasArgument(
'testArgument'),
'The given "testArgument" was not found in the built request.');
141 $this->assertSame(
$request->getArgument(
'testArgument'),
'value',
'The "testArgument" had not the given value.');
151 $methodParameters = [
152 'testArgument' => [
'optional' =>
false,
'type' =>
'string'],
153 'testArgument2' => [
'optional' =>
false,
'type' =>
'string']
156 $classSchemaMock = $this->createMock(ClassSchema::class);
157 $classSchemaMock->expects($this->any())->method(
'getMethod')->with(
'listCommand')->willReturn([
158 'params' => $methodParameters
161 $this->mockReflectionService->expects($this->any())->method(
'getClassSchema')->with(
'Tx\\SomeExtensionName\\Command\\DefaultCommandController')->willReturn($classSchemaMock);
162 $request = $this->requestBuilder->build(
'some_extension_name:default:list --test-argument=value --test-argument2=value2');
163 $this->assertTrue(
$request->hasArgument(
'testArgument'),
'The given "testArgument" was not found in the built request.');
164 $this->assertTrue(
$request->hasArgument(
'testArgument2'),
'The given "testArgument2" was not found in the built request.');
165 $this->assertEquals(
$request->getArgument(
'testArgument'),
'value',
'The "testArgument" had not the given value.');
166 $this->assertEquals(
$request->getArgument(
'testArgument2'),
'value2',
'The "testArgument2" had not the given value.');
176 $methodParameters = [
177 'testArgument' => [
'optional' =>
false,
'type' =>
'string'],
178 'testArgument2' => [
'optional' =>
false,
'type' =>
'string'],
179 'testArgument3' => [
'optional' =>
false,
'type' =>
'string'],
180 'testArgument4' => [
'optional' =>
false,
'type' =>
'string']
183 $classSchemaMock = $this->createMock(ClassSchema::class);
184 $classSchemaMock->expects($this->any())->method(
'getMethod')->with(
'listCommand')->willReturn([
185 'params' => $methodParameters
188 $this->mockReflectionService->expects($this->any())->method(
'getClassSchema')->with(
'Tx\\SomeExtensionName\\Command\\DefaultCommandController')->willReturn($classSchemaMock);
189 $request = $this->requestBuilder->build(
'some_extension_name:default:list --test-argument= value --test-argument2 =value2 --test-argument3 = value3 --test-argument4=value4');
190 $this->assertTrue(
$request->hasArgument(
'testArgument'),
'The given "testArgument" was not found in the built request.');
191 $this->assertTrue(
$request->hasArgument(
'testArgument2'),
'The given "testArgument2" was not found in the built request.');
192 $this->assertTrue(
$request->hasArgument(
'testArgument3'),
'The given "testArgument3" was not found in the built request.');
193 $this->assertTrue(
$request->hasArgument(
'testArgument4'),
'The given "testArgument4" was not found in the built request.');
194 $this->assertSame(
$request->getArgument(
'testArgument'),
'value',
'The "testArgument" had not the given value.');
195 $this->assertSame(
$request->getArgument(
'testArgument2'),
'value2',
'The "testArgument2" had not the given value.');
196 $this->assertSame(
$request->getArgument(
'testArgument3'),
'value3',
'The "testArgument3" had not the given value.');
197 $this->assertSame(
$request->getArgument(
'testArgument4'),
'value4',
'The "testArgument4" had not the given value.');
207 $methodParameters = [
208 'a' => [
'optional' =>
false,
'type' =>
'string'],
209 'd' => [
'optional' =>
false,
'type' =>
'string'],
210 'f' => [
'optional' =>
false,
'type' =>
'string']
213 $classSchemaMock = $this->createMock(ClassSchema::class);
214 $classSchemaMock->expects($this->any())->method(
'getMethod')->with(
'listCommand')->willReturn([
215 'params' => $methodParameters
218 $this->mockReflectionService->expects($this->any())->method(
'getClassSchema')->with(
'Tx\\SomeExtensionName\\Command\\DefaultCommandController')->willReturn($classSchemaMock);
220 $request = $this->requestBuilder->build(
'some_extension_name:default:list -d valued -f=valuef -a = valuea');
221 $this->assertTrue(
$request->hasArgument(
'd'),
'The given "d" was not found in the built request.');
222 $this->assertTrue(
$request->hasArgument(
'f'),
'The given "f" was not found in the built request.');
223 $this->assertTrue(
$request->hasArgument(
'a'),
'The given "a" was not found in the built request.');
224 $this->assertSame(
$request->getArgument(
'd'),
'valued',
'The "d" had not the given value.');
225 $this->assertSame(
$request->getArgument(
'f'),
'valuef',
'The "f" had not the given value.');
226 $this->assertSame(
$request->getArgument(
'a'),
'valuea',
'The "a" had not the given value.');
237 $methodParameters = [
238 'testArgument' => [
'optional' =>
false,
'type' =>
'string'],
239 'testArgument2' => [
'optional' =>
false,
'type' =>
'string'],
240 'testArgument3' => [
'optional' =>
false,
'type' =>
'string'],
241 'testArgument4' => [
'optional' =>
false,
'type' =>
'string'],
242 'testArgument5' => [
'optional' =>
false,
'type' =>
'string'],
243 'testArgument6' => [
'optional' =>
false,
'type' =>
'string'],
244 'testArgument7' => [
'optional' =>
false,
'type' =>
'string'],
245 'f' => [
'optional' =>
false,
'type' =>
'string'],
246 'd' => [
'optional' =>
false,
'type' =>
'string'],
247 'a' => [
'optional' =>
false,
'type' =>
'string'],
248 'c' => [
'optional' =>
false,
'type' =>
'string'],
249 'j' => [
'optional' =>
false,
'type' =>
'string'],
250 'k' => [
'optional' =>
false,
'type' =>
'string'],
251 'm' => [
'optional' =>
false,
'type' =>
'string']
254 $classSchemaMock = $this->createMock(ClassSchema::class);
255 $classSchemaMock->expects($this->any())->method(
'getMethod')->with(
'listCommand')->willReturn([
256 'params' => $methodParameters
259 $this->mockReflectionService->expects($this->any())->method(
'getClassSchema')->with(
'Tx\\SomeExtensionName\\Command\\DefaultCommandController')->willReturn($classSchemaMock);
261 $request = $this->requestBuilder->build(
'some_extension_name:default:list --test-argument=value --test-argument2= value2 -k --test-argument-3 = value3 --test-argument4=value4 -f valuef -d=valued -a = valuea -c --testArgument7 --test-argument5 = 5 --test-argument6 -j kjk -m');
262 $this->assertTrue(
$request->hasArgument(
'testArgument'),
'The given "testArgument" was not found in the built request.');
263 $this->assertTrue(
$request->hasArgument(
'testArgument2'),
'The given "testArgument2" was not found in the built request.');
264 $this->assertTrue(
$request->hasArgument(
'k'),
'The given "k" was not found in the built request.');
265 $this->assertTrue(
$request->hasArgument(
'testArgument3'),
'The given "testArgument3" was not found in the built request.');
266 $this->assertTrue(
$request->hasArgument(
'testArgument4'),
'The given "testArgument4" was not found in the built request.');
267 $this->assertTrue(
$request->hasArgument(
'f'),
'The given "f" was not found in the built request.');
268 $this->assertTrue(
$request->hasArgument(
'd'),
'The given "d" was not found in the built request.');
269 $this->assertTrue(
$request->hasArgument(
'a'),
'The given "a" was not found in the built request.');
270 $this->assertTrue(
$request->hasArgument(
'c'),
'The given "d" was not found in the built request.');
271 $this->assertTrue(
$request->hasArgument(
'testArgument7'),
'The given "testArgument7" was not found in the built request.');
272 $this->assertTrue(
$request->hasArgument(
'testArgument5'),
'The given "testArgument5" was not found in the built request.');
273 $this->assertTrue(
$request->hasArgument(
'testArgument6'),
'The given "testArgument6" was not found in the built request.');
274 $this->assertTrue(
$request->hasArgument(
'j'),
'The given "j" was not found in the built request.');
275 $this->assertTrue(
$request->hasArgument(
'm'),
'The given "m" was not found in the built request.');
276 $this->assertSame(
$request->getArgument(
'testArgument'),
'value',
'The "testArgument" had not the given value.');
277 $this->assertSame(
$request->getArgument(
'testArgument2'),
'value2',
'The "testArgument2" had not the given value.');
278 $this->assertSame(
$request->getArgument(
'testArgument3'),
'value3',
'The "testArgument3" had not the given value.');
279 $this->assertSame(
$request->getArgument(
'testArgument4'),
'value4',
'The "testArgument4" had not the given value.');
280 $this->assertSame(
$request->getArgument(
'f'),
'valuef',
'The "f" had not the given value.');
281 $this->assertSame(
$request->getArgument(
'd'),
'valued',
'The "d" had not the given value.');
282 $this->assertSame(
$request->getArgument(
'a'),
'valuea',
'The "a" had not the given value.');
283 $this->assertSame(
$request->getArgument(
'testArgument5'),
'5',
'The "testArgument4" had not the given value.');
284 $this->assertSame(
$request->getArgument(
'j'),
'kjk',
'The "j" had not the given value.');
292 $methodParameters = [
293 'testArgument1' => [
'optional' =>
false,
'type' =>
'string'],
294 'testArgument2' => [
'optional' =>
false,
'type' =>
'string']
297 $classSchemaMock = $this->createMock(ClassSchema::class);
298 $classSchemaMock->expects($this->any())->method(
'getMethod')->with(
'listCommand')->willReturn([
299 'params' => $methodParameters
302 $this->mockReflectionService->expects($this->any())->method(
'getClassSchema')->with(
'Tx\\SomeExtensionName\\Command\\DefaultCommandController')->willReturn($classSchemaMock);
303 $request = $this->requestBuilder->build(
'some_extension_name:default:list --test-argument1 firstArgumentValue --test-argument2 secondArgumentValue');
304 $this->assertSame(
'firstArgumentValue',
$request->getArgument(
'testArgument1'));
305 $this->assertSame(
'secondArgumentValue',
$request->getArgument(
'testArgument2'));
306 $request = $this->requestBuilder->build(
'some_extension_name:default:list firstArgumentValue secondArgumentValue');
307 $this->assertSame(
'firstArgumentValue',
$request->getArgument(
'testArgument1'));
308 $this->assertSame(
'secondArgumentValue',
$request->getArgument(
'testArgument2'));
316 $methodParameters = [
317 'some' => [
'optional' =>
true,
'type' =>
'boolean'],
318 'option' => [
'optional' =>
true,
'type' =>
'string'],
319 'argument1' => [
'optional' =>
false,
'type' =>
'string'],
320 'argument2' => [
'optional' =>
false,
'type' =>
'string']
323 $classSchemaMock = $this->createMock(ClassSchema::class);
324 $classSchemaMock->expects($this->any())->method(
'getMethod')->with(
'listCommand')->willReturn([
325 'params' => $methodParameters
328 $this->mockReflectionService->expects($this->any())->method(
'getClassSchema')->with(
'Tx\\SomeExtensionName\\Command\\DefaultCommandController')->willReturn($classSchemaMock);
329 $request = $this->requestBuilder->build(
'some_extension_name:default:list --some -option=value file1 file2');
330 $this->assertSame(
'list',
$request->getControllerCommandName());
331 $this->assertTrue(
$request->getArgument(
'some'));
332 $this->assertSame(
'file1',
$request->getArgument(
'argument1'));
333 $this->assertSame(
'file2',
$request->getArgument(
'argument2'));
341 $methodParameters = [
342 'testArgument1' => [
'optional' =>
false,
'type' =>
'string'],
343 'testArgument2' => [
'optional' =>
false,
'type' =>
'string']
346 $classSchemaMock = $this->createMock(ClassSchema::class);
347 $classSchemaMock->expects($this->any())->method(
'getMethod')->with(
'listCommand')->willReturn([
348 'params' => $methodParameters
351 $this->mockReflectionService->expects($this->any())->method(
'getClassSchema')->with(
'Tx\\SomeExtensionName\\Command\\DefaultCommandController')->willReturn($classSchemaMock);
353 $expectedArguments = [
'testArgument1' =>
'firstArgumentValue',
'testArgument2' =>
'secondArgumentValue'];
354 $request = $this->requestBuilder->build(
'some_extension_name:default:list --test-argument1=firstArgumentValue --test-argument2 secondArgumentValue exceedingArgument1');
355 $this->assertEquals($expectedArguments,
$request->getArguments());
356 $this->assertEquals([
'exceedingArgument1'],
$request->getExceedingArguments());
364 $this->expectException(InvalidArgumentMixingException::class);
365 $this->expectExceptionCode(1309971820);
366 $methodParameters = [
367 'testArgument1' => [
'optional' =>
false,
'type' =>
'string'],
368 'testArgument2' => [
'optional' =>
false,
'type' =>
'string']
371 $classSchemaMock = $this->createMock(ClassSchema::class);
372 $classSchemaMock->expects($this->any())->method(
'getMethod')->with(
'listCommand')->willReturn([
373 'params' => $methodParameters
376 $this->mockReflectionService->expects($this->any())->method(
'getClassSchema')->with(
'Tx\\SomeExtensionName\\Command\\DefaultCommandController')->willReturn($classSchemaMock);
378 $this->requestBuilder->build(
'some_extension_name:default:list --test-argument1 firstArgumentValue secondArgumentValue');
386 $this->expectException(InvalidArgumentMixingException::class);
387 $this->expectExceptionCode(1309971821);
388 $methodParameters = [
389 'requiredArgument1' => [
'optional' =>
false,
'type' =>
'string'],
390 'requiredArgument2' => [
'optional' =>
false,
'type' =>
'string']
393 $classSchemaMock = $this->createMock(ClassSchema::class);
394 $classSchemaMock->expects($this->any())->method(
'getMethod')->with(
'listCommand')->willReturn([
395 'params' => $methodParameters
398 $this->mockReflectionService->expects($this->any())->method(
'getClassSchema')->with(
'Tx\\SomeExtensionName\\Command\\DefaultCommandController')->willReturn($classSchemaMock);
400 $this->requestBuilder->build(
'some_extension_name:default:list firstArgumentValue --required-argument2 secondArgumentValue');
408 $methodParameters = [
409 'requiredArgument1' => [
'optional' =>
false,
'type' =>
'string'],
410 'requiredArgument2' => [
'optional' =>
false,
'type' =>
'string'],
411 'booleanOption' => [
'optional' =>
true,
'type' =>
'boolean']
414 $classSchemaMock = $this->createMock(ClassSchema::class);
415 $classSchemaMock->expects($this->any())->method(
'getMethod')->with(
'listCommand')->willReturn([
416 'params' => $methodParameters
419 $this->mockReflectionService->expects($this->any())->method(
'getClassSchema')->with(
'Tx\\SomeExtensionName\\Command\\DefaultCommandController')->willReturn($classSchemaMock);
421 $expectedArguments = [
'requiredArgument1' =>
'firstArgumentValue',
'requiredArgument2' =>
'secondArgumentValue',
'booleanOption' =>
true];
422 $request = $this->requestBuilder->build(
'some_extension_name:default:list --booleanOption firstArgumentValue secondArgumentValue');
423 $this->assertEquals($expectedArguments,
$request->getArguments());
431 $methodParameters = [
432 'b1' => [
'optional' =>
true,
'type' =>
'boolean'],
433 'b2' => [
'optional' =>
true,
'type' =>
'boolean'],
434 'b3' => [
'optional' =>
true,
'type' =>
'boolean'],
435 'b4' => [
'optional' =>
true,
'type' =>
'boolean'],
436 'b5' => [
'optional' =>
true,
'type' =>
'boolean'],
437 'b6' => [
'optional' =>
true,
'type' =>
'boolean']
440 $classSchemaMock = $this->createMock(ClassSchema::class);
441 $classSchemaMock->expects($this->any())->method(
'getMethod')->with(
'listCommand')->willReturn([
442 'params' => $methodParameters
445 $this->mockReflectionService->expects($this->any())->method(
'getClassSchema')->with(
'Tx\\SomeExtensionName\\Command\\DefaultCommandController')->willReturn($classSchemaMock);
447 $expectedArguments = [
'b1' =>
true,
'b2' =>
true,
'b3' =>
true,
'b4' =>
false,
'b5' =>
false,
'b6' =>
false];
448 $request = $this->requestBuilder->build(
'some_extension_name:default:list --b2 y --b1 1 --b3 true --b4 false --b5 n --b6 0');
449 $this->assertEquals($expectedArguments,
$request->getArguments());