Esempio n. 1
0
 /**
  * Test serialization of an array
  */
 public function testArraySerialization()
 {
     $request = new UrlRequestWithArray();
     $formWalker = new UrlEncode();
     $serilizer = new Serializer();
     $serilizer->setVisitor($formWalker);
     $serilizer->setVisitor(new Json());
     $serilizedData = $formWalker->visit($request, $serilizer);
     $this->assertEquals("test=1&test2=2&arrayValue=%5B%7B%22test%22%3A1%2C%22test2%22%3A2%7D%2C%7B%22test%22%3A1%2C%22test2%22%3A2%7D%5D", $serilizedData, "Message serilized string is not what is expected");
 }
Esempio n. 2
0
 /**
  * Test if a successful return of a string when a mock walker is found for a mock object
  */
 public function testSerializeSuccess()
 {
     $serializer = new Serializer();
     $serializer->setVisitor(new Json());
     $value = $serializer->serialize(new NonRecursiveJsonRequest());
     $this->assertInternalType('string', $value, "The serializer should return a string");
     $this->assertEquals('{"testa": 1}', $value, "The serialized string is not what is expected\n        Please either amend the mock object or test");
 }
Esempio n. 3
0
 /**
  * Test serialization of an array
  */
 public function testArraySerialization()
 {
     $request = new JsonRequestWithArray();
     $jsonWalker = new Json();
     $serilizer = new Serializer();
     $serilizer->setVisitor($jsonWalker);
     $serilizedData = $jsonWalker->visit($request, $serilizer);
     $this->assertJson($serilizedData, "Walker did not return json");
     $this->assertJsonStringEqualsJsonString($serilizedData, '{"test":1,"test2":2,"arrayValue":[{"test":1,"test2":2},{"test":1,"test2":2}]}');
 }
 public function testRecursiveSerialization()
 {
     $request = new MultipartRequest();
     $multipartRequest = new MultipartFormData();
     $request->data = array('test1' => 1, 'json' => new NonRecursiveJsonRequest());
     $serializer = new Serializer();
     $serializer->setVisitor(new Json());
     $serilizedData = $multipartRequest->visit($request, $serializer);
     $this->assertNotEmpty($serilizedData, "serializer returned nothing");
     $this->assertArrayHasKey('test1', $serilizedData, "test1 field is non existent");
     $this->assertArrayHasKey('json', $serilizedData, "test1 field is non existent");
     $this->assertEquals(1, $serilizedData['test1']);
     $this->assertJson($serilizedData['json']);
     $this->assertJsonStringEqualsJsonString($serilizedData['json'], '{"test":1,"test2":2}');
 }