public function testAmf0TypedObjecDeserializedToNativePHPObject() { Parser\TypeLoader::setMapping("ContactVO", "ZendAmfTest\\TestAsset\\Contact"); $myRequest = file_get_contents(__DIR__ . '/TestAsset/Request/mock/typedObjectAmf0Request.bin'); // send the mock object request to be deserialized $this->_request->initialize($myRequest); // Make sure that no headers where recieved $this->assertEquals(0, sizeof($this->_request->getAmfHeaders())); // Make sure that the message body was set after deserialization $this->assertEquals(1, sizeof($this->_request->getAmfBodies())); $bodies = $this->_request->getAmfBodies(); $this->assertTrue($bodies[0] instanceof Value\MessageBody); $data = $bodies[0]->getData(); // Make sure that we are dealing with a PHP simpleXml element $this->assertTrue($data[0] instanceof TestAsset\Contact); // Make sure that the xml was deserialized properly and check its value $this->assertEquals('arnold', (string) $data[0]->lastname); }
/** * Map ActionScript classes to PHP classes * * @param string $asClass * @param string $phpClass * @return Server */ public function setClassMap($asClass, $phpClass) { Parser\TypeLoader::setMapping($asClass, $phpClass); return $this; }
/** * Test that adding our own mappping will result in it being added to the classMap * */ public function testSetMappingClass() { Parser\TypeLoader::setMapping('com.example.vo.Contact', 'ZendAmfTest\\TestAsset\\Contact'); $class = Parser\TypeLoader::getMappedClassName('com.example.vo.Contact'); $this->assertEquals('ZendAmfTest\\TestAsset\\Contact', $class); }
public function testPhpObjectSerializedToAmf0TypedObjectClassMap() { Parser\TypeLoader::setMapping("ContactVO", "Contact"); $data = array(); $contact = new TestAsset\Contact(); $contact->id = '15'; $contact->firstname = 'Joe'; $contact->lastname = 'Smith'; $contact->email = '*****@*****.**'; $contact->mobile = '123-456-7890'; unset($contact->_explicitType); array_push($data, $contact); $contact = new TestAsset\Contact(); $contact->id = '23'; $contact->firstname = 'Adobe'; $contact->lastname = 'Flex'; $contact->email = '*****@*****.**'; $contact->mobile = '123-456-7890'; unset($contact->_explicitType); array_push($data, $contact); $newBody = new Value\MessageBody('/1/onResult', null, $data); $this->_response->setObjectEncoding(0x0); $this->_response->addAmfBody($newBody); $this->_response->finalize(); $testResponse = $this->_response->getResponse(); // Load the expected response. $mockResponse = file_get_contents(__DIR__ . '/TestAsset/Response/typedObjectAmf0Response.bin'); // Check that the response matches the expected serialized value $this->assertEquals($mockResponse, $testResponse); }