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