TYPO3 CMS  TYPO3_8-7
TaskTest.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  */
16 
20 class TaskTest extends \TYPO3\TestingFramework\Core\Unit\UnitTestCase
21 {
25  protected $task;
26 
30  protected $taskExecutor;
31 
32  protected function setUp()
33  {
34  $this->taskExecutor = $this->getMockBuilder(\TYPO3\CMS\Extbase\Scheduler\TaskExecutor::class)
35  ->setMethods(['execute'])
36  ->disableOriginalConstructor()
37  ->getMock();
38  $this->task = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Scheduler\Task::class, ['logException', '__wakeup'], [], '', false);
39  }
40 
45  {
46  $this->expectException(\Exception::class);
47  // @TODO expectExceptionCode is 0
48  $this->taskExecutor->expects($this->once())->method('execute')->will($this->throwException(new \Exception('testing', 1476107518)));
49  $this->task->_set('taskExecutor', $this->taskExecutor);
50  $this->task->expects($this->once())->method('logException');
51  $this->task->execute();
52  }
53 
58  {
59  $this->task->_set('taskExecutor', $this->taskExecutor);
60  $this->assertTrue($this->task->execute());
61  }
62 
67  {
68  $this->task->setCommandIdentifier('Foo');
69  $this->assertSame('Foo', $this->task->_get('commandIdentifier'));
70  }
71 
76  {
77  $this->task->_set('commandIdentifier', 'Foo');
78  $this->assertSame('Foo', $this->task->getCommandIdentifier());
79  }
80 
85  {
86  $this->task->setArguments(['Foo']);
87  $this->assertSame(['Foo'], $this->task->_get('arguments'));
88  }
89 
94  {
95  $this->task->_set('arguments', ['Foo']);
96  $this->assertSame(['Foo'], $this->task->getArguments());
97  }
98 
103  {
104  $this->task->setDefaults(['Foo']);
105  $this->assertSame(['Foo'], $this->task->_get('defaults'));
106  }
107 
112  {
113  $this->task->_set('defaults', ['Foo']);
114  $this->assertSame(['Foo'], $this->task->getDefaults());
115  }
116 
121  {
122  $defaults = ['foo' => 'bar'];
123  $this->task->_set('defaults', $defaults);
124 
125  $defaults['baz'] = 'qux';
126  $this->task->addDefaultValue('baz', 'qux');
127 
128  $this->assertSame($defaults, $this->task->getDefaults());
129  }
130 
135  {
136  $defaults = ['foo' => 'bar'];
137  $this->task->_set('defaults', $defaults);
138 
139  $defaults['baz'] = 1;
140  $this->task->addDefaultValue('baz', true);
141 
142  $this->assertSame($defaults, $this->task->getDefaults());
143  }
144 
149  {
150  $this->task->_set('commandIdentifier', 'foo');
151  $this->task->_set('defaults', ['bar' => 'baz']);
152  $this->task->_set('arguments', ['qux' => 'quux']);
153 
154  $this->assertSame('foo qux=quux', $this->task->getAdditionalInformation());
155  }
156 }