-
Notifications
You must be signed in to change notification settings - Fork 439
/
Copy pathDependentJobServiceTest.php
72 lines (56 loc) · 1.9 KB
/
DependentJobServiceTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
namespace Enqueue\JobQueue\Tests;
use Enqueue\JobQueue\DependentJobContext;
use Enqueue\JobQueue\DependentJobService;
use Enqueue\JobQueue\Doctrine\JobStorage;
use Enqueue\JobQueue\Job;
use PHPUnit\Framework\MockObject\MockObject;
class DependentJobServiceTest extends \PHPUnit\Framework\TestCase
{
public function testShouldThrowIfJobIsNotRootJob()
{
$job = new Job();
$job->setId(12345);
$job->setRootJob(new Job());
$context = new DependentJobContext($job);
$service = new DependentJobService($this->createJobStorageMock());
$this->expectException(\LogicException::class);
$this->expectExceptionMessage('Only root jobs allowed but got child. jobId: "12345"');
$service->saveDependentJob($context);
}
public function testShouldSaveDependentJobs()
{
$job = new Job();
$job->setId(12345);
$storage = $this->createJobStorageMock();
$storage
->expects($this->once())
->method('saveJob')
->willReturnCallback(function (Job $job, $callback) {
$callback($job);
return true;
})
;
$context = new DependentJobContext($job);
$context->addDependentJob('job-topic', 'job-message', 'job-priority');
$service = new DependentJobService($storage);
$service->saveDependentJob($context);
$expectedDependentJobs = [
'dependentJobs' => [
[
'topic' => 'job-topic',
'message' => 'job-message',
'priority' => 'job-priority',
],
],
];
$this->assertEquals($expectedDependentJobs, $job->getData());
}
/**
* @return MockObject|JobStorage
*/
private function createJobStorageMock()
{
return $this->createMock(JobStorage::class);
}
}