1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Symbiote\QueuedJobs\Tests\Jobs; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Dev\SapphireTest; |
6
|
|
|
use Symbiote\QueuedJobs\DataObjects\QueuedJobDescriptor; |
7
|
|
|
use Symbiote\QueuedJobs\Jobs\DoormanQueuedJobTask; |
8
|
|
|
use Symbiote\QueuedJobs\Services\QueuedJob; |
9
|
|
|
|
10
|
|
|
class DoormanQueuedJobTaskTest extends SapphireTest |
11
|
|
|
{ |
12
|
|
|
protected static $fixture_file = 'DoormanQueuedJobTaskTest.yml'; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @dataProvider canRunTaskProvider |
16
|
|
|
* @param string $status |
17
|
|
|
* @param bool $expected |
18
|
|
|
*/ |
19
|
|
View Code Duplication |
public function testCanRunTask($status, $expected) |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
/** @var QueuedJobDescriptor $descriptor */ |
22
|
|
|
$descriptor = $this->objFromFixture(QueuedJobDescriptor::class, 'dummy_job'); |
23
|
|
|
$descriptor->JobStatus = $status; |
24
|
|
|
$descriptor->write(); |
25
|
|
|
|
26
|
|
|
$task = new DoormanQueuedJobTask($descriptor); |
27
|
|
|
$this->assertSame($expected, $task->canRunTask()); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @return array[] |
32
|
|
|
*/ |
33
|
|
|
public function canRunTaskProvider() |
34
|
|
|
{ |
35
|
|
|
return [ |
36
|
|
|
[QueuedJob::STATUS_NEW, true], |
37
|
|
|
[QueuedJob::STATUS_INIT, true], |
38
|
|
|
[QueuedJob::STATUS_WAIT, true], |
39
|
|
|
[QueuedJob::STATUS_RUN, false], |
40
|
|
|
]; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @dataProvider isCancelledProvider |
45
|
|
|
* @param string $status |
46
|
|
|
* @param bool $expected |
47
|
|
|
*/ |
48
|
|
View Code Duplication |
public function testIsCancelled($status, $expected) |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
/** @var QueuedJobDescriptor $descriptor */ |
51
|
|
|
$descriptor = $this->objFromFixture(QueuedJobDescriptor::class, 'dummy_job'); |
52
|
|
|
$descriptor->JobStatus = $status; |
53
|
|
|
$descriptor->write(); |
54
|
|
|
|
55
|
|
|
$task = new DoormanQueuedJobTask($descriptor); |
56
|
|
|
$this->assertSame($expected, $task->isCancelled()); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @return array[] |
61
|
|
|
*/ |
62
|
|
|
public function isCancelledProvider() |
63
|
|
|
{ |
64
|
|
|
return [ |
65
|
|
|
[QueuedJob::STATUS_CANCELLED, true], |
66
|
|
|
[QueuedJob::STATUS_COMPLETE, true], |
67
|
|
|
[QueuedJob::STATUS_INIT, false], |
68
|
|
|
]; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.