Skip to content
This repository was archived by the owner on Feb 14, 2024. It is now read-only.

Commit 6665adb

Browse files
authored
Merge pull request #20 from trideout/5.3
5.3 support
2 parents 3ebfbdd + 52054c4 commit 6665adb

File tree

6 files changed

+52
-27
lines changed

6 files changed

+52
-27
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
language: php
22

33
php:
4-
- 5.5
54
- 5.6
6-
- hhvm
75

86
sudo: false
97

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515
],
1616
"require": {
1717
"php": ">=5.5.9",
18-
"illuminate/container": "5.2.*",
19-
"illuminate/contracts": "5.2.*",
20-
"illuminate/encryption": "5.2.*",
21-
"illuminate/http": "5.2.*",
22-
"illuminate/queue": "5.2.*",
23-
"illuminate/support": "5.2.*",
18+
"illuminate/container": "5.3.*",
19+
"illuminate/contracts": "5.3.*",
20+
"illuminate/encryption": "5.3.*",
21+
"illuminate/http": "5.3.*",
22+
"illuminate/queue": "5.3.*",
23+
"illuminate/support": "5.3.*",
2424
"iron-io/iron_mq": "~4.0",
2525
"jeremeamia/superclosure": "~2.0"
2626
},

src/Connectors/IronConnector.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function __construct(EncrypterContract $crypt, Request $request)
4444
* @param array $config
4545
* @param array $config
4646
*
47-
* @return \Illuminate\Contracts\Queue\Queue
47+
* @return IronQueue
4848
*/
4949
public function connect(array $config)
5050
{

src/IronQueue.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace Collective\IronQueue;
44

55
use Collective\IronQueue\Jobs\IronJob;
6+
use Illuminate\Contracts\Encryption\Encrypter;
67
use Illuminate\Contracts\Queue\Queue as QueueContract;
78
use Illuminate\Http\Request;
89
use Illuminate\Http\Response;
@@ -281,4 +282,42 @@ public function setRequest(Request $request)
281282
{
282283
$this->request = $request;
283284
}
285+
286+
/**
287+
* Get the size of the queue.
288+
*
289+
* @param null $queue
290+
*
291+
* @return int
292+
*/
293+
public function size($queue = null)
294+
{
295+
return (int)$this->iron->getQueue($queue)->size;
296+
}
297+
298+
/**
299+
* Get the encrypter implementation.
300+
*
301+
* @return \Illuminate\Contracts\Encryption\Encrypter
302+
*
303+
* @throws \Exception
304+
*/
305+
protected function getEncrypter()
306+
{
307+
if (is_null($this->encrypter)) {
308+
throw new \Exception('No encrypter has been set on the Queue.');
309+
}
310+
return $this->encrypter;
311+
}
312+
313+
/**
314+
* Set the encrypter implementation.
315+
*
316+
* @param \Illuminate\Contracts\Encryption\Encrypter $encrypter
317+
* @return void
318+
*/
319+
public function setEncrypter(Encrypter $encrypter)
320+
{
321+
$this->encrypter = $encrypter;
322+
}
284323
}

src/Jobs/IronJob.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ public function __construct(Container $container,
5959
*/
6060
public function fire()
6161
{
62-
$this->resolveAndFire(json_decode($this->getRawBody(), true));
62+
$payload = $this->payload();
63+
list($class, $method) = $this->parseJob($payload['job']);
64+
$this->instance = $this->resolve($class);
65+
$this->instance->{$method}($this, $payload['data']);
6366
}
6467

6568
/**

tests/IronQueueTest.php

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,6 @@ public function testPushProperlyPushesJobOntoIronWithoutEncryption()
3030
$queue->push('foo', [1, 2, 3]);
3131
}
3232

33-
public function testPushProperlyPushesJobOntoIronWithClosures()
34-
{
35-
$queue = new Collective\IronQueue\IronQueue($iron = m::mock('IronMQ\IronMQ'), m::mock('Illuminate\Http\Request'), 'default', true);
36-
$crypt = m::mock('Illuminate\Contracts\Encryption\Encrypter');
37-
$queue->setEncrypter($crypt);
38-
$name = 'Foo';
39-
$closure = (new Serializer())->serialize($innerClosure = function () use ($name) { return $name; });
40-
$crypt->shouldReceive('encrypt')->once()->with($closure)->andReturn('serial_closure');
41-
$crypt->shouldReceive('encrypt')->once()->with(json_encode([
42-
'job' => 'IlluminateQueueClosure', 'data' => ['closure' => 'serial_closure'], 'attempts' => 1, 'queue' => 'default',
43-
]))->andReturn('encrypted');
44-
$iron->shouldReceive('postMessage')->once()->with('default', 'encrypted', [])->andReturn((object) ['id' => 1]);
45-
$queue->push($innerClosure);
46-
}
47-
4833
public function testDelayedPushProperlyPushesJobOntoIron()
4934
{
5035
$queue = new Collective\IronQueue\IronQueue($iron = m::mock('IronMQ\IronMQ'), m::mock('Illuminate\Http\Request'), 'default', true);
@@ -60,7 +45,7 @@ public function testDelayedPushProperlyPushesJobOntoIron()
6045
public function testDelayedPushProperlyPushesJobOntoIronWithTimestamp()
6146
{
6247
$now = Carbon\Carbon::now();
63-
$queue = $this->getMock('Collective\IronQueue\IronQueue', ['getTime'], [$iron = m::mock('IronMQ\IronMQ'), m::mock('Illuminate\Http\Request'), 'default', true]);
48+
$queue = $this->getMockBuilder('Collective\IronQueue\IronQueue')->setMethods(['getTime'])->setConstructorArgs([$iron = m::mock('IronMQ\IronMQ'), m::mock('Illuminate\Http\Request'), 'default', true])->getMock();
6449
$crypt = m::mock('Illuminate\Contracts\Encryption\Encrypter');
6550
$queue->setEncrypter($crypt);
6651
$queue->expects($this->once())->method('getTime')->will($this->returnValue($now->getTimestamp()));
@@ -124,7 +109,7 @@ public function testDeleteJobWithExpiredReservationIdThrowsAnException()
124109

125110
public function testPushedJobsCanBeMarshaled()
126111
{
127-
$queue = $this->getMock('Collective\IronQueue\IronQueue', ['createPushedIronJob'], [$iron = m::mock('IronMQ\IronMQ'), $request = m::mock('Illuminate\Http\Request'), 'default', true]);
112+
$queue = $this->getMockBuilder('Collective\IronQueue\IronQueue')->setMethods(['createPushedIronJob'])->setConstructorArgs([$iron = m::mock('IronMQ\IronMQ'), $request = m::mock('Illuminate\Http\Request'), 'default', true])->getMock();
128113
$crypt = m::mock('Illuminate\Contracts\Encryption\Encrypter');
129114
$queue->setEncrypter($crypt);
130115
$request->shouldReceive('header')->once()->with('iron-message-id')->andReturn('message-id');

0 commit comments

Comments
 (0)