[TASK] Make TaskTest notice free
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Tests / Unit / Scheduler / TaskTest.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Extbase\Tests\Unit\Scheduler;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use TYPO3\CMS\Extbase\Scheduler\Task;
19 use TYPO3\CMS\Extbase\Scheduler\TaskExecutor;
20 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
21
22 /**
23 * Test case
24 */
25 class TaskTest extends UnitTestCase
26 {
27 /**
28 * @var \TYPO3\CMS\Extbase\Scheduler\Task|\PHPUnit_Framework_MockObject_MockObject|\TYPO3\TestingFramework\Core\AccessibleObjectInterface
29 */
30 protected $task;
31
32 /**
33 * @var \TYPO3\CMS\Extbase\Scheduler\TaskExecutor|\PHPUnit_Framework_MockObject_MockObject
34 */
35 protected $taskExecutor;
36
37 protected function setUp()
38 {
39 $this->taskExecutor = $this->getMockBuilder(TaskExecutor::class)
40 ->setMethods(['execute'])
41 ->disableOriginalConstructor()
42 ->getMock();
43 $this->task = $this->getAccessibleMock(Task::class, ['logException', '__wakeup'], [], '', false);
44 }
45
46 /**
47 * @test
48 */
49 public function executeCallsLogExceptionOnCaughtExceptionAndRethrowsException()
50 {
51 $this->expectException(\Exception::class);
52 // @TODO expectExceptionCode is 0
53 $this->taskExecutor->expects($this->once())->method('execute')->will($this->throwException(new \Exception('testing', 1476107518)));
54 $this->task->_set('taskExecutor', $this->taskExecutor);
55 $this->task->expects($this->once())->method('logException');
56 $this->task->execute();
57 }
58
59 /**
60 * @test
61 */
62 public function executeReturnsTrueIfNoExceptionIsCaught()
63 {
64 $this->task->_set('taskExecutor', $this->taskExecutor);
65 $this->assertTrue($this->task->execute());
66 }
67
68 /**
69 * @test
70 */
71 public function setCommandIdentifierSetsCommandIdentifierCorrectly()
72 {
73 $this->task->setCommandIdentifier('Foo');
74 $this->assertSame('Foo', $this->task->_get('commandIdentifier'));
75 }
76
77 /**
78 * @test
79 */
80 public function getCommandIdentifierReturnsCorrectCommandIdentifier()
81 {
82 $this->task->_set('commandIdentifier', 'Foo');
83 $this->assertSame('Foo', $this->task->getCommandIdentifier());
84 }
85
86 /**
87 * @test
88 */
89 public function setArgumentsSetsArgumentsCorrectly()
90 {
91 $this->task->setArguments(['Foo']);
92 $this->assertSame(['Foo'], $this->task->_get('arguments'));
93 }
94
95 /**
96 * @test
97 */
98 public function getArgumentsReturnsCorrectArguments()
99 {
100 $this->task->_set('arguments', ['Foo']);
101 $this->assertSame(['Foo'], $this->task->getArguments());
102 }
103
104 /**
105 * @test
106 */
107 public function setDefaultsSetsDefaultsCorrectly()
108 {
109 $this->task->setDefaults(['Foo']);
110 $this->assertSame(['Foo'], $this->task->_get('defaults'));
111 }
112
113 /**
114 * @test
115 */
116 public function getDefaultsReturnsCorrectDefaults()
117 {
118 $this->task->_set('defaults', ['Foo']);
119 $this->assertSame(['Foo'], $this->task->getDefaults());
120 }
121
122 /**
123 * @test
124 */
125 public function addDefaultValueAddsDefaultToDefaults()
126 {
127 $defaults = ['foo' => 'bar'];
128 $this->task->_set('defaults', $defaults);
129
130 $defaults['baz'] = 'qux';
131 $this->task->addDefaultValue('baz', 'qux');
132
133 $this->assertSame($defaults, $this->task->getDefaults());
134 }
135
136 /**
137 * @test
138 */
139 public function addDefaultValueConvertsBooleanValuesToInteger()
140 {
141 $defaults = ['foo' => 'bar'];
142 $this->task->_set('defaults', $defaults);
143
144 $defaults['baz'] = 1;
145 $this->task->addDefaultValue('baz', true);
146
147 $this->assertSame($defaults, $this->task->getDefaults());
148 }
149
150 /**
151 * @test
152 */
153 public function getAdditionalInformationRespectsArguments()
154 {
155 $this->task->_set('commandIdentifier', 'foo');
156 $this->task->_set('defaults', ['bar' => 'baz']);
157 $this->task->_set('arguments', ['qux' => 'quux']);
158
159 $this->assertSame('foo qux=quux', $this->task->getAdditionalInformation());
160 }
161 }