File: amqpexchange_publish_with_properties_nested_header.phpt

package info (click to toggle)
php-amqp 2.1.2-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,536 kB
  • sloc: ansic: 7,295; xml: 1,162; php: 690; pascal: 49; makefile: 2
file content (144 lines) | stat: -rw-r--r-- 2,926 bytes parent folder | download
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
--TEST--
AMQPExchange publish with properties - nested header values
--SKIPIF--
<?php
if (!extension_loaded("amqp")) print "skip AMQP extension is not loaded";
elseif (!getenv("PHP_AMQP_HOST")) print "skip PHP_AMQP_HOST environment variable is not set";
?>
--FILE--
<?php
$cnn = new AMQPConnection();
$cnn->setHost(getenv('PHP_AMQP_HOST'));
$cnn->connect();

$ch = new AMQPChannel($cnn);

$ex = new AMQPExchange($ch);
$ex->setName("exchange-" . bin2hex(random_bytes(32)));
$ex->setType(AMQP_EX_TYPE_FANOUT);
$ex->declareExchange();

$q = new AMQPQueue($ch);
$q->setName('queue-' . bin2hex(random_bytes(32)));
$q->declareQueue();
$q->bind($ex->getName());

$headers = array(
    'nested' => array(
        'string'     => 'passed',
        999          => 'numeric works',
        'sub-nested' => array(
            'should' => 'works',
            42       => 'too'
        ),
    ),
);

$ex->publish('message', 'routing.key', AMQP_NOPARAM, array('headers' => $headers));

$message = $q->get(AMQP_AUTOACK);
var_dump($message->getHeaders());
var_dump($headers);
echo $message->getHeaders() === $headers ? 'same' : 'differs';
echo PHP_EOL, PHP_EOL;


$headers = array(
    'x-death' => array(
        array (
            'reason' => 'rejected',
            'queue' => 'my_queue',
            'time' => 1410527691,
            'exchange' => 'my_exchange',
            'routing-keys' => array ('my_routing_key')
        )
    )
);

$ex->publish('message', 'routing.key', AMQP_NOPARAM, array('headers' => $headers));

$message = $q->get(AMQP_AUTOACK);
var_dump($message->getHeaders());
var_dump($headers);
echo $message->getHeaders() === $headers ? 'same' : 'differs';
echo PHP_EOL, PHP_EOL;

?>
--EXPECT--
array(1) {
  ["nested"]=>
  array(3) {
    ["string"]=>
    string(6) "passed"
    [999]=>
    string(13) "numeric works"
    ["sub-nested"]=>
    array(2) {
      ["should"]=>
      string(5) "works"
      [42]=>
      string(3) "too"
    }
  }
}
array(1) {
  ["nested"]=>
  array(3) {
    ["string"]=>
    string(6) "passed"
    [999]=>
    string(13) "numeric works"
    ["sub-nested"]=>
    array(2) {
      ["should"]=>
      string(5) "works"
      [42]=>
      string(3) "too"
    }
  }
}
same

array(1) {
  ["x-death"]=>
  array(1) {
    [0]=>
    array(5) {
      ["reason"]=>
      string(8) "rejected"
      ["queue"]=>
      string(8) "my_queue"
      ["time"]=>
      int(1410527691)
      ["exchange"]=>
      string(11) "my_exchange"
      ["routing-keys"]=>
      array(1) {
        [0]=>
        string(14) "my_routing_key"
      }
    }
  }
}
array(1) {
  ["x-death"]=>
  array(1) {
    [0]=>
    array(5) {
      ["reason"]=>
      string(8) "rejected"
      ["queue"]=>
      string(8) "my_queue"
      ["time"]=>
      int(1410527691)
      ["exchange"]=>
      string(11) "my_exchange"
      ["routing-keys"]=>
      array(1) {
        [0]=>
        string(14) "my_routing_key"
      }
    }
  }
}
same