[TASK] Deprecate Extbase CommandControllers and @cli annotation
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / UnitDeprecated / Mvc / Controller / CommandControllerTest.php
1 <?php
2 namespace TYPO3\CMS\Extbase\Tests\UnitDeprecated\Mvc\Controller;
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 use TYPO3\CMS\Extbase\Mvc\Exception\StopActionException;
17
18 /**
19 * Test case
20 */
21 class CommandControllerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
22 {
23 /**
24 * @var \TYPO3\CMS\Extbase\Mvc\Controller\CommandController|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface
25 */
26 protected $commandController;
27
28 /**
29 * \Symfony\Component\Console\Output\ConsoleOutput|\PHPUnit_Framework_MockObject_MockObject
30 */
31 protected $mockConsoleOutput;
32
33 protected function setUp()
34 {
35 $this->commandController = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Mvc\Controller\CommandController::class, ['dummyCommand']);
36 $this->mockConsoleOutput = $this->getMockBuilder(\TYPO3\CMS\Extbase\Mvc\Cli\ConsoleOutput::class)->disableOriginalConstructor()->getMock();
37 $this->commandController->_set('output', $this->mockConsoleOutput);
38 }
39
40 /**
41 * @test
42 */
43 public function outputAppendsGivenStringToTheResponseContent()
44 {
45 $this->mockConsoleOutput->expects($this->once())->method('output')->with('some text');
46 $this->commandController->_call('output', 'some text');
47 }
48
49 /**
50 * @test
51 */
52 public function outputReplacesArgumentsInGivenString()
53 {
54 $this->mockConsoleOutput->expects($this->once())->method('output')->with('%2$s %1$s', ['text', 'some']);
55 $this->commandController->_call('output', '%2$s %1$s', ['text', 'some']);
56 }
57
58 /**
59 * @test
60 */
61 public function quitThrowsStopActionException()
62 {
63 $this->expectException(StopActionException::class);
64 // @TODO expectExceptionCode is 0
65 $mockResponse = $this->createMock(\TYPO3\CMS\Extbase\Mvc\Cli\Response::class);
66 $this->commandController->_set('response', $mockResponse);
67 $this->commandController->_call('quit');
68 }
69
70 /**
71 * @test
72 */
73 public function quitSetsResponseExitCode()
74 {
75 $this->expectException(StopActionException::class);
76 // @TODO expectExceptionCode is 0
77 $mockResponse = $this->createMock(\TYPO3\CMS\Extbase\Mvc\Cli\Response::class);
78 $mockResponse->expects($this->once())->method('setExitCode')->with(123);
79 $this->commandController->_set('response', $mockResponse);
80 $this->commandController->_call('quit', 123);
81 }
82 }