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

Commit

Permalink
updates to support Laravel 5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Rideout committed Jul 12, 2017
1 parent 88f1c6e commit 32f3f47
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 54 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ language: php

php:
- 5.6
- 7.0
- 7.1

sudo: false

Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
}
],
"require": {
"php": ">=5.5.9",
"illuminate/container": "5.3.*",
"illuminate/contracts": "5.3.*",
"illuminate/encryption": "5.3.*",
"illuminate/http": "5.3.*",
"illuminate/queue": "5.3.*",
"illuminate/support": "5.3.*",
"php": ">=5.6.4",
"illuminate/container": "5.4.*",
"illuminate/contracts": "5.4.*",
"illuminate/encryption": "5.4.*",
"illuminate/http": "5.4.*",
"illuminate/queue": "5.4.*",
"illuminate/support": "5.4.*",
"iron-io/iron_mq": "~4.0",
"jeremeamia/superclosure": "~2.0"
},
Expand Down
19 changes: 17 additions & 2 deletions src/IronQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function pushRaw($payload, $queue = null, array $options = [])
*/
public function recreate($payload, $queue, $delay)
{
$options = ['delay' => $this->getSeconds($delay)];
$options = ['delay' => $this->secondsUntil($delay)];

return $this->pushRaw($payload, $queue, $options);
}
Expand All @@ -125,7 +125,7 @@ public function recreate($payload, $queue, $delay)
*/
public function later($delay, $job, $data = '', $queue = null)
{
$delay = $this->getSeconds($delay);
$delay = $this->secondsUntil($delay);

$payload = $this->createPayload($job, $data, $queue);

Expand Down Expand Up @@ -267,6 +267,21 @@ public function setRequest(Request $request)
$this->request = $request;
}

/**
* Create a payload array from the given job and data.
*
* @param string $job
* @param mixed $data
* @param string $queue
* @return array
*/
protected function createPayloadArray($job, $data = '', $queue = null)
{
return array_merge(parent::createPayloadArray($job, $data, $queue), [
'queue' => $this->getQueue($queue),
]);
}

/**
* Get the size of the queue.
*
Expand Down
25 changes: 1 addition & 24 deletions src/Jobs/IronJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,6 @@ public function __construct(Container $container,
$this->container = $container;
}

/**
* Fire the job.
*
* @return void
*/
public function fire()
{
$payload = $this->payload();
list($class, $method) = $this->parseJob($payload['job']);
$this->instance = $this->resolve($class);
$this->instance->{$method}($this, $payload['data']);
}

/**
* Get the raw body string for the job.
*
Expand Down Expand Up @@ -145,16 +132,6 @@ public function getJobId()
return $this->job->id;
}

/**
* Get the IoC container instance.
*
* @return \Illuminate\Container\Container
*/
public function getContainer()
{
return $this->container;
}

/**
* Get the underlying Iron queue instance.
*
Expand All @@ -168,7 +145,7 @@ public function getIron()
/**
* Get the underlying IronMQ job.
*
* @return array
* @return object
*/
public function getIronJob()
{
Expand Down
33 changes: 12 additions & 21 deletions tests/IronQueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,44 +12,35 @@ public function tearDown()

public function testPushProperlyPushesJobOntoIron()
{
$queue = new Collective\IronQueue\IronQueue($iron = m::mock('IronMQ\IronMQ'), m::mock('Illuminate\Http\Request'), 'default', true);
$iron = m::mock('IronMQ\IronMQ');
$iron->shouldReceive('postMessage')->once()->with('default', 'encrypted', [])->andReturn((object) ['id' => 1]);
$crypt = m::mock('Illuminate\Contracts\Encryption\Encrypter');
$crypt->shouldReceive('encrypt')->once()->with(json_encode(['displayName' => 'foo', 'job' => 'foo', 'maxTries' => null, 'timeout' => null, 'data' => [1, 2, 3], 'queue' => 'default']))->andReturn('encrypted');
$queue = new Collective\IronQueue\IronQueue($iron, m::mock('Illuminate\Http\Request'), 'default', true);
$queue->setEncrypter($crypt);
$crypt->shouldReceive('encrypt')->once()->with(json_encode(['job' => 'foo', 'data' => [1, 2, 3]]))->andReturn('encrypted');
$iron->shouldReceive('postMessage')->once()->with('default', 'encrypted', [])->andReturn((object) ['id' => 1]);
$queue->push('foo', [1, 2, 3]);
}

public function testPushProperlyPushesJobOntoIronWithoutEncryption()
{
$queue = new Collective\IronQueue\IronQueue($iron = m::mock('IronMQ\IronMQ'), m::mock('Illuminate\Http\Request'), 'default');
$iron = $iron = m::mock('IronMQ\IronMQ');
$iron->shouldReceive('postMessage')->once()->with('default', json_encode(['displayName' => 'foo', 'job' => 'foo', 'maxTries' => null, 'timeout' => null, 'data' => [1, 2, 3], 'queue' => 'default']), [])->andReturn((object) ['id' => 1]);
$crypt = m::mock('Illuminate\Contracts\Encryption\Encrypter');
$queue->setEncrypter($crypt);
$crypt->shouldReceive('encrypt')->never();
$iron->shouldReceive('postMessage')->once()->with('default', json_encode(['job' => 'foo', 'data' => [1, 2, 3]]), [])->andReturn((object) ['id' => 1]);
$queue = new Collective\IronQueue\IronQueue($iron, m::mock('Illuminate\Http\Request'), 'default');
$queue->setEncrypter($crypt);
$queue->push('foo', [1, 2, 3]);
}

public function testDelayedPushProperlyPushesJobOntoIron()
{
$queue = new Collective\IronQueue\IronQueue($iron = m::mock('IronMQ\IronMQ'), m::mock('Illuminate\Http\Request'), 'default', true);
$crypt = m::mock('Illuminate\Contracts\Encryption\Encrypter');
$queue->setEncrypter($crypt);
$crypt->shouldReceive('encrypt')->once()->with(json_encode(['job' => 'foo', 'data' => [1, 2, 3]]))->andReturn('encrypted');
$iron = m::mock('IronMQ\IronMQ');
$iron->shouldReceive('postMessage')->once()->with('default', 'encrypted', ['delay' => 5])->andReturn((object) ['id' => 1]);
$queue->later(5, 'foo', [1, 2, 3]);
}

public function testDelayedPushProperlyPushesJobOntoIronWithTimestamp()
{
$now = Carbon\Carbon::now();
$queue = $this->getMockBuilder('Collective\IronQueue\IronQueue')->setMethods(['getTime'])->setConstructorArgs([$iron = m::mock('IronMQ\IronMQ'), m::mock('Illuminate\Http\Request'), 'default', true])->getMock();
$crypt = m::mock('Illuminate\Contracts\Encryption\Encrypter');
$crypt->shouldReceive('encrypt')->once()->with(json_encode(['displayName' => 'foo', 'job' => 'foo', 'maxTries' => null, 'timeout' => null, 'data' => [1, 2, 3], 'queue' => 'default']))->andReturn('encrypted');
$queue = new Collective\IronQueue\IronQueue($iron, m::mock('Illuminate\Http\Request'), 'default', true);
$queue->setEncrypter($crypt);
$queue->expects($this->once())->method('getTime')->will($this->returnValue($now->getTimestamp()));
$crypt->shouldReceive('encrypt')->once()->with(json_encode(['job' => 'foo', 'data' => [1, 2, 3]]))->andReturn('encrypted');
$iron->shouldReceive('postMessage')->once()->with('default', 'encrypted', ['delay' => 5])->andReturn((object) ['id' => 1]);
$queue->later($now->addSeconds(5), 'foo', [1, 2, 3]);
$queue->later(5, 'foo', [1, 2, 3]);
}

public function testPopProperlyPopsJobOffOfIron()
Expand Down

0 comments on commit 32f3f47

Please sign in to comment.