protected function _callService($method, $class = 'Zend_Amf_Resource_testclass') { $request = new Zend_Amf_Request(); $request->setObjectEncoding(0x3); $this->_server->setClass($class); $newBody = new Zend_Amf_Value_MessageBody("{$class}.{$method}", "/1", array("test")); $request->addAmfBody($newBody); $this->_server->handle($request); $response = $this->_server->getResponse(); return $response; }
public function testPHPNullSerializedToAmf0Null() { $data = null; $newBody = new Zend_Amf_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(dirname(__FILE__) . '/Response/mock/nullAmf0Response.bin'); // Check that the response matches the expected serialized value $this->assertEquals($mockResponse, $testResponse); }
public function testCtorExcection() { $this->_server->setClass('Zend_Amf_testException'); $this->_server->setProduction(false); $message = new Zend_Amf_Value_Messaging_RemotingMessage(); $message->operation = 'hello'; $message->source = 'Zend_Amf_testException'; $message->body = array("123"); // create a mock message body to place th remoting message inside $newBody = new Zend_Amf_Value_MessageBody(null, "/1", $message); $request = new Zend_Amf_Request(); // at the requested service to a request $request->addAmfBody($newBody); $request->setObjectEncoding(0x3); // let the server handle mock request $this->_server->handle($request); $response = $this->_server->getResponse()->getAMFBodies(); $this->assertTrue($response[0]->getData() instanceof Zend_Amf_Value_Messaging_ErrorMessage); $this->assertContains("Oops, exception!", $response[0]->getData()->faultString); }
/** * @group ZF-6130 */ public function testServerShouldCastObjectArgumentsToAppropriateType() { $server = new Zend_Amf_Server(); $server->addDirectory(dirname(__FILE__) . '/_files/zf-6130/services'); // Create a mock message $message = new Zend_Amf_Value_Messaging_RemotingMessage(); $message->operation = 'createEmployee'; $message->source = 'EmployeeService'; // original raw request used "destination" $message->body = array(array('office' => 322, 'departmentid' => 3, 'street' => 32, 'zipcode' => 32, 'state' => 32, 'lastname' => 4, 'firstname' => 2, 'photofile' => 322, 'city' => 32, 'id' => 1, 'title' => 4, 'officephone' => 233, 'email' => 32, 'cellphone' => 22)); $body = new Zend_Amf_Value_MessageBody(null, "", $message); $request = new Zend_Amf_Request(); $request->addAmfBody($body); $request->setObjectEncoding(0x3); $response = $server->handle($request); $employee = EmployeeService::$employee; $this->assertNotNull($employee); $this->assertNotEquals(1, $employee->id); $this->assertRegexp('/[a-z0-9]{3,}/', $employee->id); }
/** * Handles passing a request through the amf client * @param {string} $servicePath Service path i.e ServerController.connect * @param {object|array} $data Data to be sent with the request should be an array or an object * @return {array} Server response */ protected function getAMFResponse($servicePath, $data = null) { require_once 'Zend/Amf/Request.php'; require_once 'Zend/Amf/Constants.php'; require_once 'Zend/Amf/Value/MessageBody.php'; require_once 'Zend/Amf/Value/Messaging/RemotingMessage.php'; require_once 'Zend/Amf/Value/Messaging/ErrorMessage.php'; if ($data) { if (is_array($data)) { $data = $this->arrayToObject($data); } else { if (!is_object($data)) { user_error('$data is not an array or object', E_USER_ERROR); } } } //Find the method and service $service = explode('.', $servicePath); $method = array_pop($service); $service = implode('.', $service); //Build the message $message = new Zend_Amf_Value_Messaging_RemotingMessage(); $message->parameters = $data; $message->operation = $method; $message->source = $service; //Build the message body $body = new Zend_Amf_Value_MessageBody($servicePath, '/1', array($data)); //Build the AMF Request $request = new Zend_Amf_Request(); $request->addAmfBody($body); $request->setObjectEncoding(Zend_Amf_Constants::AMF3_OBJECT_ENCODING); //Init the client api $amfClient = new CodeBank_ClientAPI(); $amfClient->setTestRequest($request); //Capture the response as an amf input stream ob_start(); $response = $amfClient->index(); ob_end_clean(); //Get the amf bodies $bodies = $response->getAmfBodies(); if (count($bodies) > 0) { $body = $bodies[0]->getData(); if ($body instanceof Zend_Amf_Value_Messaging_ErrorMessage) { $this->fail('AMF Server returned an error: ' . $body->faultString . "\n\n" . $body->faultDetail); return false; } return $body; } return false; }