forked from CoderKungfu/php-queue
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStompTest.php
More file actions
107 lines (92 loc) · 2.51 KB
/
Copy pathStompTest.php
File metadata and controls
107 lines (92 loc) · 2.51 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
<?php
namespace PHPQueue\Backend;
use PHPUnit_Framework_TestCase;
use PHPQueue\Exception\JobNotFoundException;
class StompTest extends PHPUnit_Framework_TestCase
{
protected $object;
protected $unique;
protected $unclean;
public function setUp()
{
parent::setUp();
if (!class_exists('\FuseSource\Stomp\Stomp')) {
$this->markTestSkipped('STOMP library not installed');
} else {
$options = array(
'uri' => 'tcp://127.0.0.1:61613',
'queue' => 'test_queue',
'read_timeout' => 1,
);
$this->object = new Stomp($options);
}
$this->unique = mt_rand();
}
public function tearDown()
{
if ($this->unclean) {
// Gross. Clear the queue.
try {
while ($result = $this->object->pop()) {
// pass
}
} catch (JobNotFoundException $ex) {
// pass
}
}
parent::tearDown();
}
/**
* @medium
*/
public function testPushPop()
{
$data = array('unique' => $this->unique);
$this->unclean = true;
$this->object->push($data);
$this->assertEquals($data, $this->object->pop());
$this->unclean = false;
}
/**
* @medium
*/
public function testSetGet()
{
$data = array('unique' => $this->unique);
$this->unclean = true;
$result = $this->object->set($this->unique, $data);
$result = $this->object->get($this->unique);
$this->assertEquals($data, $result);
$this->unclean = false;
}
/**
* @medium
*/
public function testPopEmpty()
{
$this->assertNull($this->object->pop());
}
/**
* @medium
*/
public function testGetNonexistent()
{
$this->assertNull($this->object->get(mt_rand()));
}
/**
* @medium
*/
public function testMergeHeaders()
{
$data = array('unique' => $this->unique);
$this->unclean = true;
$this->object->push($data, array('fooHeader' => 5));
$this->object->merge_headers = true;
$result = $this->object->pop();
$this->assertTrue(array_key_exists('fooHeader', $result));
$this->assertEquals($result['fooHeader'], 5);
$this->assertTrue(array_key_exists('unique', $result));
$this->assertEquals($result['unique'], $this->unique);
$this->unclean = false;
}
}