Repository navigation
Expand file tree
/
Copy pathChannelTest.php
More file actions
85 lines (64 loc) · 2.8 KB
/
Copy pathChannelTest.php
File metadata and controls
85 lines (64 loc) · 2.8 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
<?php
namespace PhpAmqpLib\Tests\Functional;
use PhpAmqpLib\Connection\AMQPSocketConnection;
use PhpAmqpLib\Exception\AMQPBasicCancelException;
use PhpAmqpLib\Exception\AMQPProtocolChannelException;
use PhpAmqpLib\Exception\AMQPTimeoutException;
use PhpAmqpLib\Helper\Protocol\Wait091;
use PhpAmqpLib\Message\AMQPMessage;
class ChannelTest extends AbstractPublishConsumeTest
{
protected function createConnection()
{
return new AMQPSocketConnection(HOST, PORT, USER, PASS, VHOST);
}
public function testDeclaringExchangeOnChannelWithClosedConnectionThrowsException()
{
$connection = $this->createConnection();
$channel = $connection->channel();
try {
$channel->exchange_declare('tst.exchange2', 'topic', true);
} catch (AMQPProtocolChannelException $e) {
// Do Nothing
}
$this->setExpectedException('\PhpAmqpLib\Exception\AMQPRuntimeException', 'Channel connection is closed.');
$channel->exchange_declare('tst.exchange2', 'topic', false, true, false);
$channel->close();
$connection->close();
}
public function testPublishWithConfirm()
{
$connection = $this->createConnection();
$connection->connectOnConstruct();
$channel = $connection->channel();
try {
$channel->exchange_declare('tst.exchange3', 'topic', false);
} catch (AMQPProtocolChannelException $e) {
// Do Nothing
}
$deliveryTags = array();
$channel->set_ack_handler(function (AMQPMessage $message) use (&$deliveryTags) {
$deliveryTags[] = (int) $message->get('delivery_tag');
return false;
});
$channel->confirm_select();
$connection2 = $this->createConnection();
$channel2 = $connection2->channel();
$channel2->queue_declare('tst.queue3');
$channel2->queue_bind('tst.queue3', 'tst.exchange3', '#');
$channel->basic_publish(new AMQPMessage('foo'), 'tst.exchange3');
$channel->basic_publish(new AMQPMessage('bar'), 'tst.exchange3');
$publishedMessagesProperty = new \ReflectionProperty(get_class($this->channel), 'published_messages');
$publishedMessagesProperty->setAccessible(true);
$channel->wait_for_pending_acks_returns(1);
$msg1 = $channel2->basic_get('tst.queue3');
$this->assertInstanceOf('PhpAmqpLib\Message\AMQPMessage', $msg1);
$msg2 = $channel2->basic_get('tst.queue3');
$this->assertInstanceOf('PhpAmqpLib\Message\AMQPMessage', $msg2);
$this->assertSame('foo', $msg1->getBody());
$this->assertSame('bar', $msg2->getBody());
$this->assertSame(array(1,2), $deliveryTags);
$channel2->queue_delete('tst.queue3');
$channel->exchange_delete('tst.exchange3');
}
}