File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -17,8 +17,16 @@ public function __construct($action, array $parts = array())
1717 public function getMessageSerialized ()
1818 {
1919 $ message = 'Action: ' . $ this ->action . "\r\n" ;
20- foreach ($ this ->parts as $ key => $ value ) {
21- $ message .= $ key . ': ' . $ value . "\r\n" ;
20+ foreach ($ this ->parts as $ key => $ values ) {
21+ if (!is_array ($ values )) {
22+ $ values = array ($ values );
23+ }
24+ foreach ($ values as $ i => $ value ) {
25+ if (!is_int ($ i )) {
26+ $ value = $ i . '= ' . $ value ;
27+ }
28+ $ message .= $ key . ': ' . $ value . "\r\n" ;
29+ }
2230 }
2331 $ message .= "\r\n" ;
2432
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ use Clue \React \Ami \Protocol \Action ;
4+ class ActionTest extends TestCase
5+ {
6+ public function testSerializeSimple ()
7+ {
8+ $ action = new Action ('name ' );
9+ $ id = $ action ->getActionId ();
10+
11+ $ this ->assertEquals ("Action: name \r\nActionID: $ id \r\n\r\n" , $ action ->getMessageSerialized ());
12+ }
13+
14+ public function testSerializeKeySingle ()
15+ {
16+ $ action = new Action ('name ' , array ('Key ' => 'Value ' ));
17+ $ id = $ action ->getActionId ();
18+
19+ $ this ->assertEquals ("Action: name \r\nKey: Value \r\nActionID: $ id \r\n\r\n" , $ action ->getMessageSerialized ());
20+ }
21+
22+ public function testSerializeKeyMultipleValues ()
23+ {
24+ $ action = new Action ('name ' , array ('Key ' => array ('Value1 ' , 'Value2 ' )));
25+ $ id = $ action ->getActionId ();
26+
27+ $ this ->assertEquals ("Action: name \r\nKey: Value1 \r\nKey: Value2 \r\nActionID: $ id \r\n\r\n" , $ action ->getMessageSerialized ());
28+ }
29+
30+ public function testSerializeKeyMultipleKeyValues ()
31+ {
32+ $ action = new Action ('name ' , array ('Variables ' => array ('first ' => 'on ' , 'second ' => 'off ' )));
33+ $ id = $ action ->getActionId ();
34+
35+ $ this ->assertEquals ("Action: name \r\nVariables: first=on \r\nVariables: second=off \r\nActionID: $ id \r\n\r\n" , $ action ->getMessageSerialized ());
36+ }
37+ }
You can’t perform that action at this time.
0 commit comments