forked from mcintyred/php-amqp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for parsing nested custom headers
- Loading branch information
Showing
2 changed files
with
143 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
--TEST-- | ||
AMQPQueue::get headers | ||
--SKIPIF-- | ||
<?php if (!extension_loaded("amqp")) print "skip"; ?> | ||
--FILE-- | ||
<?php | ||
$cnn = new AMQPConnection(); | ||
$cnn->connect(); | ||
|
||
$ch = new AMQPChannel($cnn); | ||
|
||
$ex = new AMQPExchange($ch); | ||
$ex->setName('exchange' . time()); | ||
$ex->setType(AMQP_EX_TYPE_TOPIC); | ||
$ex->declare(); | ||
$q = new AMQPQueue($ch); | ||
$q->setName('queue1' . time()); | ||
$q->declare(); | ||
$q->bind($ex->getName(), '#'); | ||
|
||
|
||
// publish a message: | ||
$ex->publish( | ||
'body', 'routing.1', AMQP_NOPARAM, array( | ||
'headers' => array( | ||
'foo' => 'bar', | ||
'baz' => array('a', 'bc', 'def') | ||
) | ||
) | ||
); | ||
|
||
// Read from the queue | ||
$msg = $q->get(AMQP_AUTOACK); | ||
|
||
var_dump($msg->getHeaders()); | ||
echo $msg->getHeader('foo') . "\n"; | ||
var_dump($msg->getHeader('baz')); | ||
|
||
$ex->delete(); | ||
$q->delete(); | ||
?> | ||
--EXPECT-- | ||
array(2) { | ||
["foo"]=> | ||
string(3) "bar" | ||
["baz"]=> | ||
array(3) { | ||
[0]=> | ||
string(1) "a" | ||
[1]=> | ||
string(2) "bc" | ||
[2]=> | ||
string(3) "def" | ||
} | ||
} | ||
bar | ||
array(3) { | ||
[0]=> | ||
string(1) "a" | ||
[1]=> | ||
string(2) "bc" | ||
[2]=> | ||
string(3) "def" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
--TEST-- | ||
AMQPQueue::get headers | ||
--SKIPIF-- | ||
<?php if (!extension_loaded("amqp")) print "skip"; ?> | ||
--FILE-- | ||
<?php | ||
$cnn = new AMQPConnection(); | ||
$cnn->connect(); | ||
|
||
$ch = new AMQPChannel($cnn); | ||
|
||
// create an error exchange and bind a queue to it: | ||
$errorXchange = new AMQPExchange($ch); | ||
$errorXchange->setName('errorXchange' . time()); | ||
$errorXchange->setType(AMQP_EX_TYPE_TOPIC); | ||
$errorXchange->declare(); | ||
|
||
$errorQ = new AMQPQueue($ch); | ||
$errorQ->setName('errorQueue' . time()); | ||
$errorQ->declare(); | ||
$errorQ->bind($errorXchange->getName(), '#'); | ||
|
||
|
||
// Declare a new exchange and queue using this dead-letter-exchange: | ||
$ex = new AMQPExchange($ch); | ||
$ex->setName('exchange' . time()); | ||
$ex->setType(AMQP_EX_TYPE_TOPIC); | ||
$ex->declare(); | ||
$q = new AMQPQueue($ch); | ||
$q->setName('queue1' . time()); | ||
$q->setArgument('x-dead-letter-exchange', $errorXchange->getName()); | ||
$q->declare(); | ||
$q->bind($ex->getName(), '#'); | ||
|
||
|
||
// publish a message: | ||
$ex->publish( | ||
'body', 'routing.1', AMQP_NOPARAM, array( | ||
'headers' => array( | ||
'foo' => 'bar', | ||
'baz' => array('a', 'bc', 'def') | ||
) | ||
) | ||
); | ||
|
||
// Read from the queue and reject, so it gets dead-lettered: | ||
$msg = $q->get(AMQP_NOPARAM); | ||
$q->nack($msg->getDeliveryTag()); | ||
|
||
// Now read from the error queue: | ||
$msg = $errorQ->get(AMQP_AUTOACK); | ||
|
||
var_dump($msg->getHeader('x-death')); | ||
|
||
$ex->delete(); | ||
$q->delete(); | ||
$errorXchange->delete(); | ||
$errorQ->delete(); | ||
?> | ||
--EXPECTF-- | ||
array(1) { | ||
[0]=> | ||
array(5) { | ||
["reason"]=> | ||
string(8) "rejected" | ||
["queue"]=> | ||
string(16) "queue%d" | ||
["time"]=> | ||
float(%d) | ||
["exchange"]=> | ||
string(18) "exchange%d" | ||
["routing-keys"]=> | ||
array(1) { | ||
[0]=> | ||
string(9) "routing.1" | ||
} | ||
} | ||
} | ||
|