forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueueIronQueueTest.php
More file actions
executable file
·86 lines (67 loc) · 4.39 KB
/
QueueIronQueueTest.php
File metadata and controls
executable file
·86 lines (67 loc) · 4.39 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
<?php
use Mockery as m;
class QueueIronQueueTest extends PHPUnit_Framework_TestCase {
public function tearDown()
{
m::close();
}
public function testPushProperlyPushesJobOntoIron()
{
$queue = new Illuminate\Queue\IronQueue($iron = m::mock('IronMQ'), $crypt = m::mock('Illuminate\Encryption\Encrypter'), m::mock('Illuminate\Http\Request'), 'default');
$crypt->shouldReceive('encrypt')->once()->with(json_encode(array('job' => 'foo', 'data' => array(1, 2, 3), 'attempts' => 1, 'queue' => 'default')))->andReturn('encrypted');
$iron->shouldReceive('postMessage')->once()->with('default', 'encrypted', array())->andReturn((object) array('id' => 1));
$queue->push('foo', array(1, 2, 3));
}
public function testPushProperlyPushesJobOntoIronWithClosures()
{
$queue = new Illuminate\Queue\IronQueue($iron = m::mock('IronMQ'), $crypt = m::mock('Illuminate\Encryption\Encrypter'), m::mock('Illuminate\Http\Request'), 'default');
$name = 'Foo';
$closure = new Illuminate\Support\SerializableClosure($innerClosure = function() use ($name) { return $name; });
$crypt->shouldReceive('encrypt')->once()->with(json_encode(array(
'job' => 'IlluminateQueueClosure', 'data' => array('closure' => serialize($closure)), 'attempts' => 1, 'queue' => 'default'
)))->andReturn('encrypted');
$iron->shouldReceive('postMessage')->once()->with('default', 'encrypted', array())->andReturn((object) array('id' => 1));
$queue->push($innerClosure);
}
public function testDelayedPushProperlyPushesJobOntoIron()
{
$queue = new Illuminate\Queue\IronQueue($iron = m::mock('IronMQ'), $crypt = m::mock('Illuminate\Encryption\Encrypter'), m::mock('Illuminate\Http\Request'), 'default');
$crypt->shouldReceive('encrypt')->once()->with(json_encode(array(
'job' => 'foo', 'data' => array(1, 2, 3), 'attempts' => 1, 'queue' => 'default',
)))->andReturn('encrypted');
$iron->shouldReceive('postMessage')->once()->with('default', 'encrypted', array('delay' => 5))->andReturn((object) array('id' => 1));
$queue->later(5, 'foo', array(1, 2, 3));
}
public function testDelayedPushProperlyPushesJobOntoIronWithTimestamp()
{
$now = Carbon\Carbon::now();
$queue = $this->getMock('Illuminate\Queue\IronQueue', array('getTime'), array($iron = m::mock('IronMQ'), $crypt = m::mock('Illuminate\Encryption\Encrypter'), m::mock('Illuminate\Http\Request'), 'default'));
$queue->expects($this->once())->method('getTime')->will($this->returnValue($now->getTimestamp()));
$crypt->shouldReceive('encrypt')->once()->with(json_encode(array('job' => 'foo', 'data' => array(1, 2, 3), 'attempts' => 1, 'queue' => 'default')))->andReturn('encrypted');
$iron->shouldReceive('postMessage')->once()->with('default', 'encrypted', array('delay' => 5))->andReturn((object) array('id' => 1));
$queue->later($now->addSeconds(5), 'foo', array(1, 2, 3));
}
public function testPopProperlyPopsJobOffOfIron()
{
$queue = new Illuminate\Queue\IronQueue($iron = m::mock('IronMQ'), $crypt = m::mock('Illuminate\Encryption\Encrypter'), m::mock('Illuminate\Http\Request'), 'default');
$queue->setContainer(m::mock('Illuminate\Container\Container'));
$iron->shouldReceive('getMessage')->once()->with('default')->andReturn($job = m::mock('IronMQ_Message'));
$job->body = 'foo';
$crypt->shouldReceive('decrypt')->once()->with('foo')->andReturn('foo');
$result = $queue->pop();
$this->assertInstanceOf('Illuminate\Queue\Jobs\IronJob', $result);
}
public function testPushedJobsCanBeMarshaled()
{
$queue = $this->getMock('Illuminate\Queue\IronQueue', array('createPushedIronJob'), array($iron = m::mock('IronMQ'), $crypt = m::mock('Illuminate\Encryption\Encrypter'), $request = m::mock('Illuminate\Http\Request'), 'default'));
$request->shouldReceive('header')->once()->with('iron-message-id')->andReturn('message-id');
$request->shouldReceive('getContent')->once()->andReturn($content = json_encode(array('foo' => 'bar')));
$crypt->shouldReceive('decrypt')->once()->with($content)->andReturn($content);
$job = (object) array('id' => 'message-id', 'body' => json_encode(array('foo' => 'bar')), 'pushed' => true);
$queue->expects($this->once())->method('createPushedIronJob')->with($this->equalTo($job))->will($this->returnValue($mockIronJob = m::mock('StdClass')));
$mockIronJob->shouldReceive('fire')->once();
$response = $queue->marshal();
$this->assertInstanceOf('Illuminate\Http\Response', $response);
$this->assertEquals(200, $response->getStatusCode());
}
}