TYPO3 CMS  TYPO3_7-6
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 
21 {
25  protected $task;
26 
30  protected $taskExecutor;
31 
32  protected function setUp()
33  {
34  $this->taskExecutor = $this->getMock(\TYPO3\CMS\Extbase\Scheduler\TaskExecutor::class, ['execute'], [], '', false);
35  $this->task = $this->getAccessibleMock(\TYPO3\CMS\Extbase\Scheduler\Task::class, ['logException', '__wakeup'], [], '', false);
36  }
37 
43  {
44  $this->taskExecutor->expects($this->once())->method('execute')->will($this->throwException(new \Exception()));
45  $this->task->_set('taskExecutor', $this->taskExecutor);
46  $this->task->expects($this->once())->method('logException');
47  $this->task->execute();
48  }
49 
54  {
55  $this->task->_set('taskExecutor', $this->taskExecutor);
56  $this->assertTrue($this->task->execute());
57  }
58 
63  {
64  $this->task->setCommandIdentifier('Foo');
65  $this->assertSame('Foo', $this->task->_get('commandIdentifier'));
66  }
67 
72  {
73  $this->task->_set('commandIdentifier', 'Foo');
74  $this->assertSame('Foo', $this->task->getCommandIdentifier());
75  }
76 
81  {
82  $this->task->setArguments(['Foo']);
83  $this->assertSame(['Foo'], $this->task->_get('arguments'));
84  }
85 
90  {
91  $this->task->_set('arguments', ['Foo']);
92  $this->assertSame(['Foo'], $this->task->getArguments());
93  }
94 
99  {
100  $this->task->setDefaults(['Foo']);
101  $this->assertSame(['Foo'], $this->task->_get('defaults'));
102  }
103 
108  {
109  $this->task->_set('defaults', ['Foo']);
110  $this->assertSame(['Foo'], $this->task->getDefaults());
111  }
112 
117  {
118  $defaults = ['foo' => 'bar'];
119  $this->task->_set('defaults', $defaults);
120 
121  $defaults['baz'] = 'qux';
122  $this->task->addDefaultValue('baz', 'qux');
123 
124  $this->assertSame($defaults, $this->task->getDefaults());
125  }
126 
131  {
132  $defaults = ['foo' => 'bar'];
133  $this->task->_set('defaults', $defaults);
134 
135  $defaults['baz'] = 1;
136  $this->task->addDefaultValue('baz', true);
137 
138  $this->assertSame($defaults, $this->task->getDefaults());
139  }
140 
145  {
146  $this->task->_set('commandIdentifier', 'foo');
147  $this->task->_set('defaults', ['bar' => 'baz']);
148  $this->task->_set('arguments', ['qux' => 'quux']);
149 
150  $this->assertSame('foo qux=quux', $this->task->getAdditionalInformation());
151  }
152 }
getAccessibleMock( $originalClassName, $methods=[], array $arguments=[], $mockClassName='', $callOriginalConstructor=true, $callOriginalClone=true, $callAutoload=true)