Ejemplo n.º 1
0
 public function testCreateFactory()
 {
     $factory = new Factory('http://localhost/');
     $factory->setRequestClassNamespace('\\Sokil\\Rest\\Client\\RequestMock');
     $request = $factory->createRequest('getRequestMock');
     $this->assertInstanceOf('\\Sokil\\Rest\\Client\\Request', $request);
 }
Ejemplo n.º 2
0
 public function testBehaviorOwner()
 {
     $factory = new Factory('http://localhost/');
     $factory->setRequestClassNamespace('\\Sokil\\Rest\\Client\\RequestMock');
     $factory->attachBehavior('my', new \Sokil\Rest\Client\MyBehavior());
     // exec behavior
     $requert = $factory->createRequest('GetRequestMock');
     $this->assertEquals('http://localhost/some/resource', $requert->getRequestUrl());
 }
Ejemplo n.º 3
0
 /**
  * @expectedException \Guzzle\Http\Exception\BadResponseException
  */
 public function testOnError()
 {
     // replace response
     $plugin = new \Guzzle\Plugin\Mock\MockPlugin();
     $plugin->addResponse(new \Guzzle\Http\Message\Response(404, array('Content-type' => 'application/json'), json_encode(array('error' => 0))));
     $factory = new Factory('http://localhost/');
     $factory->setRequestClassNamespace('\\Sokil\\Rest\\Client\\RequestMock');
     $factory->addSubscriber($plugin);
     $status = new \stdclass();
     $status->status = 0;
     $factory->onError(function ($event) use($status) {
         $status->status = $event['response']->getStatusCode();
     });
     // send
     $request = $factory->createRequest('GetRequestMock');
     try {
         $response = $request->send();
     } catch (\Exception $e) {
         // check if event occured
         $this->assertEquals(404, $status->status);
         throw $e;
     }
 }
Ejemplo n.º 4
0
 public function testBuildUrlForRequest()
 {
     // configure subscriber
     $factory = new Factory('http://localhost/basepath');
     $factory->setRequestClassNamespace('\\Sokil\\Rest\\Client\\RequestMock');
     $request = $factory->createRequest('GetRequestMock');
     $this->assertEquals('http://localhost/basepath/some/resource', $request->getUrl());
 }