-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathQueueSqsJobTest.php
More file actions
124 lines (104 loc) · 4.11 KB
/
QueueSqsJobTest.php
File metadata and controls
124 lines (104 loc) · 4.11 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
use Aws\Common\Credentials\Credentials;
use Aws\Common\Signature\SignatureV4;
use Aws\Sqs\SqsClient;
use Guzzle\Common\Collection;
use Illuminate\Container\Container;
use Illuminate\Queue\SqsQueue;
use L4\Tests\BackwardCompatibleTestCase;
use Mockery as m;
class QueueSqsJobTest extends BackwardCompatibleTestCase
{
private string $key;
private string $secret;
private string $service;
private string $region;
private string $account;
private string $queueName;
private string $baseUrl;
private Credentials $credentials;
private SignatureV4 $signature;
private Collection $config;
private string $queueUrl;
private \PHPUnit\Framework\MockObject\MockObject $mockedSqsClient;
private $mockedContainer;
private string $mockedJob;
/**
* @var string[]
*/
private array $mockedData;
/**
* @var bool|non-empty-string
*/
private string|bool $mockedPayload;
private string $mockedMessageId;
private string $mockedReceiptHandle;
private array $mockedJobData;
protected function setUp(): void
{
$this->markTestSkipped();
$this->key = 'AMAZONSQSKEY';
$this->secret = 'AmAz0n+SqSsEcReT+aLpHaNuM3R1CsTr1nG';
$this->service = 'sqs';
$this->region = 'someregion';
$this->account = '1234567891011';
$this->queueName = 'emails';
$this->baseUrl = 'https://sqs.someregion.amazonaws.com';
// The Aws\Common\AbstractClient needs these three constructor parameters
$this->credentials = new Credentials( $this->key, $this->secret );
$this->signature = new SignatureV4( $this->service, $this->region );
$this->config = new Collection();
// This is how the modified getQueue builds the queueUrl
$this->queueUrl = $this->baseUrl . '/' . $this->account . '/' . $this->queueName;
// Get a mock of the SqsClient
$this->mockedSqsClient = $this->getMock('Aws\Sqs\SqsClient', ['deleteMessage'], [$this->credentials, $this->signature, $this->config]
);
// Use Mockery to mock the IoC Container
$this->mockedContainer = m::mock(Container::class);
$this->mockedJob = 'foo';
$this->mockedData = ['data'];
$this->mockedPayload = json_encode(['job' => $this->mockedJob, 'data' => $this->mockedData, 'attempts' => 1]);
$this->mockedMessageId = 'e3cd03ee-59a3-4ad8-b0aa-ee2e3808ac81';
$this->mockedReceiptHandle = '0NNAq8PwvXuWv5gMtS9DJ8qEdyiUwbAjpp45w2m6M4SJ1Y+PxCh7R930NRB8ylSacEmoSnW18bgd4nK\/O6ctE+VFVul4eD23mA07vVoSnPI4F\/voI1eNCp6Iax0ktGmhlNVzBwaZHEr91BRtqTRM3QKd2ASF8u+IQaSwyl\/DGK+P1+dqUOodvOVtExJwdyDLy1glZVgm85Yw9Jf5yZEEErqRwzYz\/qSigdvW4sm2l7e4phRol\/+IjMtovOyH\/ukueYdlVbQ4OshQLENhUKe7RNN5i6bE\/e5x9bnPhfj2gbM';
$this->mockedJobData = [
'Body' => $this->mockedPayload,
'MD5OfBody' => md5((string) $this->mockedPayload),
'ReceiptHandle' => $this->mockedReceiptHandle,
'MessageId' => $this->mockedMessageId,
'Attributes' => ['ApproximateReceiveCount' => 1]
];
}
protected function tearDown(): void
{
m::close();
}
public function testFireProperlyCallsTheJobHandler()
{
$job = $this->getJob();
$job->getContainer()->shouldReceive('make')->once()->with('foo')->andReturn($handler = m::mock('StdClass'));
$handler->shouldReceive('fire')->once()->with($job, ['data']);
$job->fire();
}
public function testDeleteRemovesTheJobFromSqs()
{
$this->mockedSqsClient = $this->getMock('Aws\Sqs\SqsClient', ['deleteMessage'], [$this->credentials, $this->signature, $this->config]
);
$queue = $this->getMock(SqsQueue::class, ['getQueue'], [$this->mockedSqsClient, $this->queueName, $this->account]
);
$queue->setContainer($this->mockedContainer);
$job = $this->getJob();
$job->getSqs()->expects($this->once())->method('deleteMessage')->with(
['QueueUrl' => $this->queueUrl, 'ReceiptHandle' => $this->mockedReceiptHandle]
);
$job->delete();
}
protected function getJob()
{
return new Illuminate\Queue\Jobs\SqsJob(
$this->mockedContainer,
$this->mockedSqsClient,
$this->queueUrl,
$this->mockedJobData
);
}
}