Skip to content

Commit

Permalink
add tests for parsing nested custom headers
Browse files Browse the repository at this point in the history
  • Loading branch information
bkw committed Apr 16, 2013
1 parent 1aff5c5 commit f25e471
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 0 deletions.
64 changes: 64 additions & 0 deletions tests/amqpqueue_nested_arrays.phpt
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"
}
79 changes: 79 additions & 0 deletions tests/amqpqueue_nested_headers.phpt
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"
}
}
}

0 comments on commit f25e471

Please sign in to comment.