@@ -13,6 +13,35 @@ public function testCreateEvent()
1313 $ this ->assertRequestJson (['created_at ' => 1401970113 , 'event_name ' => 'invited-friend ' ]);
1414 }
1515
16+ /*
17+ * Empty associative arrays get mapped to [] in PHP
18+ * Check that we filter them out to nulls, which are valid on the server
19+ */
20+ public function testNoMetadata ()
21+ {
22+ $ this ->setMockResponse ($ this ->client , 'Event/Event.txt ' );
23+ $ this ->client ->createEvent (['metadata ' => [], 'created_at ' => 1401970113 , 'event_name ' => 'invited-friend ' ]);
24+
25+ $ this ->assertRequest ('POST ' , '/events ' );
26+ $ body = $ this ->getOnlyMockedRequest ()->getBody ()->__toString ();
27+ $ json = json_decode ($ body );
28+ $ this ->assertEquals (NULL , $ json ->metadata );
29+ }
30+
31+ /*
32+ * Check that our array filtering doesn't interfere with valid metadata
33+ */
34+ public function testMetadata ()
35+ {
36+ $ this ->setMockResponse ($ this ->client , 'Event/Event.txt ' );
37+ $ this ->client ->createEvent (['metadata ' => ['foo ' => 'bar ' ], 'created_at ' => 1401970113 , 'event_name ' => 'invited-friend ' ]);
38+
39+ $ this ->assertRequest ('POST ' , '/events ' );
40+ $ body = $ this ->getOnlyMockedRequest ()->getBody ()->__toString ();
41+ $ json = json_decode ($ body );
42+ $ this ->assertEquals ('bar ' , $ json ->metadata ->foo );
43+ }
44+
1645 /**
1746 * @expectedException \Guzzle\Service\Exception\ValidationException
1847 */
@@ -36,4 +65,4 @@ public function testCreateEventNoEventName()
3665 {
3766 $ this ->client ->createEvent (['created_at ' => 1401970113 ]);
3867 }
39- }
68+ }
0 commit comments