‪TYPO3CMS  9.5
TaskTest.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
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 
20 use TYPO3\TestingFramework\Core\Unit\UnitTestCase;
21 
25 class ‪TaskTest extends UnitTestCase
26 {
30  protected ‪$task;
31 
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 
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 
63  {
64  $this->task->_set('taskExecutor', $this->taskExecutor);
65  $this->assertTrue($this->task->execute());
66  }
67 
72  {
73  $this->task->setCommandIdentifier('Foo');
74  $this->assertSame('Foo', $this->task->_get('commandIdentifier'));
75  }
76 
81  {
82  $this->task->_set('commandIdentifier', 'Foo');
83  $this->assertSame('Foo', $this->task->getCommandIdentifier());
84  }
85 
90  {
91  $this->task->setArguments(['Foo']);
92  $this->assertSame(['Foo'], $this->task->_get('arguments'));
93  }
94 
99  {
100  $this->task->_set('arguments', ['Foo']);
101  $this->assertSame(['Foo'], $this->task->getArguments());
102  }
103 
107  public function ‪setDefaultsSetsDefaultsCorrectly()
108  {
109  $this->task->setDefaults(['Foo']);
110  $this->assertSame(['Foo'], $this->task->_get('defaults'));
111  }
112 
116  public function ‪getDefaultsReturnsCorrectDefaults()
117  {
118  $this->task->_set('defaults', ['Foo']);
119  $this->assertSame(['Foo'], $this->task->getDefaults());
120  }
121 
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 
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 
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 }
‪TYPO3\CMS\Extbase\Tests\Unit\Scheduler\TaskTest\getAdditionalInformationRespectsArguments
‪getAdditionalInformationRespectsArguments()
Definition: TaskTest.php:151
‪TYPO3\CMS\Extbase\Scheduler\TaskExecutor
Definition: TaskExecutor.php:25
‪TYPO3\CMS\Extbase\Tests\Unit\Scheduler\TaskTest\addDefaultValueConvertsBooleanValuesToInteger
‪addDefaultValueConvertsBooleanValuesToInteger()
Definition: TaskTest.php:137
‪TYPO3\CMS\Extbase\Scheduler\Task
Definition: Task.php:28
‪TYPO3\CMS\Extbase\Tests\Unit\Scheduler\TaskTest\executeReturnsTrueIfNoExceptionIsCaught
‪executeReturnsTrueIfNoExceptionIsCaught()
Definition: TaskTest.php:60
‪TYPO3\CMS\Extbase\Tests\Unit\Scheduler\TaskTest\getArgumentsReturnsCorrectArguments
‪getArgumentsReturnsCorrectArguments()
Definition: TaskTest.php:96
‪TYPO3\CMS\Extbase\Exception
Definition: Exception.php:23
‪TYPO3\CMS\Extbase\Tests\Unit\Scheduler\TaskTest\setCommandIdentifierSetsCommandIdentifierCorrectly
‪setCommandIdentifierSetsCommandIdentifierCorrectly()
Definition: TaskTest.php:69
‪TYPO3\CMS\Extbase\Tests\Unit\Scheduler\TaskTest\getCommandIdentifierReturnsCorrectCommandIdentifier
‪getCommandIdentifierReturnsCorrectCommandIdentifier()
Definition: TaskTest.php:78
‪TYPO3\CMS\Extbase\Tests\Unit\Scheduler\TaskTest\addDefaultValueAddsDefaultToDefaults
‪addDefaultValueAddsDefaultToDefaults()
Definition: TaskTest.php:123
‪TYPO3\CMS\Extbase\Tests\Unit\Scheduler\TaskTest\getDefaultsReturnsCorrectDefaults
‪getDefaultsReturnsCorrectDefaults()
Definition: TaskTest.php:114
‪TYPO3\CMS\Extbase\Tests\Unit\Scheduler\TaskTest\$taskExecutor
‪TYPO3 CMS Extbase Scheduler TaskExecutor PHPUnit_Framework_MockObject_MockObject $taskExecutor
Definition: TaskTest.php:33
‪TYPO3\CMS\Extbase\Tests\Unit\Scheduler\TaskTest\setDefaultsSetsDefaultsCorrectly
‪setDefaultsSetsDefaultsCorrectly()
Definition: TaskTest.php:105
‪TYPO3\CMS\Extbase\Tests\Unit\Scheduler\TaskTest
Definition: TaskTest.php:26
‪TYPO3\CMS\Extbase\Tests\Unit\Scheduler\TaskTest\executeCallsLogExceptionOnCaughtExceptionAndRethrowsException
‪executeCallsLogExceptionOnCaughtExceptionAndRethrowsException()
Definition: TaskTest.php:47
‪TYPO3\CMS\Extbase\Tests\Unit\Scheduler
Definition: FieldProviderTest.php:2
‪TYPO3\CMS\Extbase\Tests\Unit\Scheduler\TaskTest\$task
‪TYPO3 CMS Extbase Scheduler Task PHPUnit_Framework_MockObject_MockObject TYPO3 TestingFramework Core AccessibleObjectInterface $task
Definition: TaskTest.php:29
‪TYPO3\CMS\Extbase\Tests\Unit\Scheduler\TaskTest\setUp
‪setUp()
Definition: TaskTest.php:35
‪TYPO3\CMS\Extbase\Tests\Unit\Scheduler\TaskTest\setArgumentsSetsArgumentsCorrectly
‪setArgumentsSetsArgumentsCorrectly()
Definition: TaskTest.php:87