TYPO3 CMS  TYPO3_8-7
CommandControllerTest.php
Go to the documentation of this file.
1 <?php
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  */
17 
21 class CommandControllerTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
22 {
26  protected $commandController;
27 
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 
44  {
45  $this->mockConsoleOutput->expects($this->once())->method('output')->with('some text');
46  $this->commandController->_call('output', 'some text');
47  }
48 
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 
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 
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 }