Пример #1
0
 public function testCtorPost()
 {
     $uri = Uri::createFromString('https://api.example.com/v1/help');
     $request = Request::post($uri);
     $this->assertEquals(IRequest::METHOD_POST, $request->getMethod());
     $this->assertEquals($uri->__toString(), $request->getUri()->__toString());
 }
Пример #2
0
 public function handle(IServerRequest $request)
 {
     $doc = MimedDocument::createText('test');
     $uri = Uri::createFromString('/test');
     switch ($request->getQueryParams()['r']) {
         case 'ok':
             return $this->responseOk($doc);
             break;
         case 'bad_request':
             return $this->responseBadRequest($doc);
             break;
         case 'forbidden':
             return $this->responseForbidden($doc);
             break;
         case 'not_found':
             return $this->responseNotFound($doc);
             break;
         case 'redirect_perm':
             return $this->redirect($uri, true);
             break;
         case 'redirect_temp':
             return $this->redirect($uri, false);
             break;
         case 'error':
             return $this->responseError($doc);
             break;
         default:
             throw new \LogicException('Undefined');
             break;
     }
 }
Пример #3
0
 public function testError()
 {
     $this->expectException(\RuntimeException::class);
     $uri = Uri::createFromString('http://127.0.0.1:1234');
     $request = new Request($uri);
     $client = new CurlHttpClient();
     $response = $client->send($request);
 }
Пример #4
0
 public function testUnknownRoute()
 {
     $this->expectException(\LogicException::class);
     $this->expectExceptionMessage('Unknown route: unknown');
     $router = Router::createDefault();
     $url_builder = new UrlBuilder($router);
     $uri = \Yen\Http\Uri::createFromString('route:unknown');
     $url_builder->build($uri);
 }
Пример #5
0
 public function build(Http\Contract\IUri $uri, array $args = [])
 {
     if ($uri->getScheme() == 'route') {
         $resolved = $this->router->resolve($uri->getPath(), $args);
         $uri = Http\Uri::createFromString($resolved->path());
         $args = $resolved->arguments();
     }
     if (!$uri->getScheme()) {
         $uri = $this->base_url->withPath($uri->getPath());
     }
     return $uri->withQuery(http_build_query($args));
 }
Пример #6
0
 public function testJsonSerialize()
 {
     $uri = Uri::createFromString($url = 'http://testing.net/index.html?foo=bar&a=12');
     $json = json_encode(['uri' => $uri]);
     $this->assertEquals('{"uri":"http:\\/\\/testing.net\\/index.html?foo=bar&a=12"}', $json);
 }