예제 #1
0
 /**
  * testFunctionality
  * 
  * Test basic class functionality
  */
 public function testFunctionality()
 {
     $client = new Client('http://www.somedomain.com/mm5', 'TOKENZrSHWEET');
     $this->assertEquals($client->getUri(), 'http://www.somedomain.com/mm5');
     $this->assertEquals($client->getToken(), 'TOKENZrSHWEET');
     $this->assertEquals($client->getUrl(), 'http://www.somedomain.com/mm5/json.mvc?Function=Module&Module_Code=remoteprovisioning&Module_Function=XML');
     $client->setUri('http://www.someotherdomain.com/mm5')->setToken('TOKENZrSHWEETERWHENCHANGED');
     $this->assertEquals($client->getUri(), 'http://www.someotherdomain.com/mm5');
     $this->assertEquals($client->getToken(), 'TOKENZrSHWEETERWHENCHANGED');
     $this->assertEquals($client->getUrl(), 'http://www.someotherdomain.com/mm5/json.mvc?Function=Module&Module_Code=remoteprovisioning&Module_Function=XML');
     $request = new Request('I AM A REQUEST CONTENT');
     $mockClient = new ClientMock('http://www.somedomain.com/mm5', 'TOKENZrSHWEET');
     $response = $mockClient->doRequest($request);
     $this->assertInstanceOf('Miva\\Provisioning\\Response', $response);
 }
예제 #2
0
 function testPUTRequest()
 {
     $client = new ClientMock(array('baseUri' => 'http://example.org/foo/bar/'));
     $responseBlob = array("HTTP/1.1 200 OK", "Content-Type: text/plain", "", "Hello there!");
     $client->response = array(implode("\r\n", $responseBlob), array('header_size' => 45, 'http_code' => 200), 0, "");
     $result = $client->request('PUT', 'bar', 'newcontent');
     $this->assertEquals('http://example.org/foo/bar/bar', $client->url);
     $this->assertEquals(array(CURLOPT_RETURNTRANSFER => true, CURLOPT_FOLLOWLOCATION => true, CURLOPT_MAXREDIRS => 5, CURLOPT_CUSTOMREQUEST => "PUT", CURLOPT_POSTFIELDS => 'newcontent', CURLOPT_HEADER => true, CURLOPT_HTTPHEADER => array()), $client->curlSettings);
 }
예제 #3
0
 function testDoRequestCurlError()
 {
     $client = new ClientMock();
     $request = new Request('GET', 'http://example.org/');
     $client->on('curlExec', function (&$return) {
         $return = "";
     });
     $client->on('curlStuff', function (&$return) {
         $return = [[], 1, 'Curl error'];
     });
     try {
         $response = $client->doRequest($request);
         $this->fail('This should have thrown an exception');
     } catch (ClientException $e) {
         $this->assertEquals(1, $e->getCode());
         $this->assertEquals('Curl error', $e->getMessage());
     }
 }