Skip to content

Commit 6715092

Browse files
committed
Set the job display name as just the class name
Excludes the `@handle` that the `job` key has.
1 parent 170ded8 commit 6715092

File tree

3 files changed

+109
-1
lines changed

3 files changed

+109
-1
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/vendor
2+
.idea
3+
composer.lock

src/Sqs/Queue.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ public function pop($queue = null)
7676
return new SqsJob($this->container, $this->sqs, $response, $this->connectionName, $queue);
7777
}
7878

79+
dd($queue, $response);
80+
7981
return new SqsJob($this->container, $this->sqs, $queue, $response);
8082
}
8183
}
@@ -92,6 +94,7 @@ private function modifyPayload($payload, $class)
9294
$body = json_decode($payload['Body'], true);
9395

9496
$body = [
97+
'displayName' => $class,
9598
'job' => $class . '@handle',
9699
'data' => isset($body['data']) ? $body['data'] : $body
97100
];

tests/PlainSqs/QueueTest.php

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,75 @@
44
use Aws\Sqs\SqsClient;
55
use Dusterio\PlainSqs\Jobs\DispatcherJob;
66
use Dusterio\PlainSqs\Sqs\Queue;
7+
use Illuminate\Container\Container;
8+
use Illuminate\Contracts\Config\Repository;
79

810
/**
911
* Class QueueTest
1012
* @package Dusterio\PlainSqs\Tests
1113
*/
1214
class QueueTest extends \PHPUnit_Framework_TestCase
1315
{
16+
/**
17+
* @var \PHPUnit_Framework_MockObject_MockObject|SqsClient
18+
*/
19+
private $sqsClientMock;
20+
21+
/**
22+
* @var \PHPUnit_Framework_MockObject_MockObject|Container
23+
*/
24+
private $containerMock;
25+
26+
/**
27+
* @var \PHPUnit_Framework_MockObject_MockObject|\Illuminate\Contracts\Config\Repository
28+
*/
29+
private $configMock;
30+
31+
/**
32+
* @var string
33+
*/
34+
private $version;
35+
36+
protected function setUp()
37+
{
38+
parent::setUp();
39+
40+
$this->sqsClientMock = $this
41+
->getMockBuilder(SqsClient::class)
42+
->disableOriginalConstructor()
43+
->setMethods(['receiveMessage'])
44+
->getMock();
45+
46+
$this->configMock = $this
47+
->getMockBuilder(Repository::class)
48+
->setMethods(['has', 'set', 'get', 'all', 'prepend', 'push'])
49+
->getMock();
50+
51+
$this->containerMock = $this
52+
->getMockBuilder(Container::class)
53+
->setMethods(['version', 'offsetGet'])
54+
->getMock();
55+
56+
$this->containerMock
57+
->expects($this->any())
58+
->method('offsetGet')
59+
->will($this->returnValue($this->configMock));
60+
61+
preg_match("#^\d.\d#", phpversion(), $match);
62+
63+
$this->version = '5.8.0';
64+
switch ($match[0]) {
65+
case '5.5':
66+
$this->version = '5.0.0';
67+
break;
68+
}
69+
70+
$this->containerMock
71+
->expects($this->any())
72+
->method('version')
73+
->will($this->returnValue($this->version));
74+
}
75+
1476
/**
1577
* @test
1678
*/
@@ -35,4 +97,44 @@ public function class_named_is_derived_from_queue_name()
3597

3698
//$response = $method->invokeArgs($queue, [$job]);
3799
}
38-
}
100+
101+
public function testSettingJobDisplayName()
102+
{
103+
104+
$this->sqsClientMock
105+
->expects($this->once())
106+
->method('receiveMessage')
107+
->will($this->returnValue([
108+
'Messages' => [
109+
json_encode([
110+
'Body' => json_encode([
111+
'data' => [
112+
'foo' => 'bar'
113+
]
114+
])
115+
])
116+
]
117+
]));
118+
119+
120+
$this->configMock
121+
->expects($this->any())
122+
->method('get')
123+
->with('sqs-plain.handlers')
124+
->will($this->returnValue([
125+
'default-queue' => 'SomeClass'
126+
]));
127+
128+
$queue = new Queue($this->sqsClientMock, 'default-queue');
129+
130+
$queue->setContainer($this->containerMock);
131+
132+
if ($this->version !== '5.0.0') {
133+
$queue->setConnectionName('default-connection');
134+
}
135+
136+
$result = $queue->pop();
137+
138+
$this->assertEquals('SomeClass', $result->resolveName());
139+
}
140+
}

0 commit comments

Comments
 (0)