Exemplo n.º 1
0
 public function testRequestURI()
 {
     $uri = '/foobar.json?foo=bar';
     $request = \Owl\Http\Request::factory(['uri' => $uri]);
     $this->assertEquals($uri, $request->getRequestURI());
     $this->assertEquals('/foobar.json', $request->getRequestPath());
     $this->assertEquals('json', $request->getExtension());
 }
Exemplo n.º 2
0
 public function testDispatch($path)
 {
     $request = \Owl\Http\Request::factory(['uri' => $path, 'method' => 'GET']);
     if ($router = $this->getDelegateRouter($request)) {
         return $router->dispatch($request);
     }
     return $this->dispatch($request);
 }
Exemplo n.º 3
0
 /**
  * @expectedException \Owl\Http\Exception
  * @expectedExceptionCode 501
  */
 public function test501()
 {
     $app = new \Owl\Application();
     $app->setExceptionHandler(function ($exception) {
         throw $exception;
     });
     $request = \Owl\Http\Request::factory(['method' => 'FOO']);
     $response = new \Owl\Http\Response();
     $app->execute($request, $response);
 }
Exemplo n.º 4
0
 public function testBindIpCookieContext()
 {
     $config = ['request' => \Owl\Http\Request::factory(['ip' => '192.168.1.1']), 'response' => new \Tests\Mock\Http\Response(), 'token' => 'test', 'sign_salt' => 'fdajkfldsjfldsf', 'bind_ip' => true];
     $handler = new \Owl\Context\Cookie($config);
     $handler->set('test', 'abc');
     $handler = new \Owl\Context\Cookie(array_merge($config, ['request' => \Owl\Http\Request::factory(['cookies' => $handler->getConfig('response')->getCookies(), 'ip' => '192.168.1.3']), 'response' => new \Tests\Mock\Http\Response()]));
     $this->assertEquals($handler->get('test'), 'abc', '同子网IP取值');
     $handler = new \Owl\Context\Cookie(array_merge($config, ['request' => \Owl\Http\Request::factory(['cookies' => $handler->getConfig('response')->getCookies(), 'ip' => '192.168.2.1']), 'response' => new \Owl\Http\Response()]));
     $this->assertNull($handler->get('test'), '不同子网IP取值');
 }
Exemplo n.º 5
0
 public function testRequestURI()
 {
     $uri = '/foobar.json?foo=bar';
     $request = \Owl\Http\Request::factory(['uri' => $uri]);
     $this->assertEquals($uri, $request->getRequestTarget());
     $this->assertEquals('/foobar.json', $request->getUri()->getPath());
     $this->assertEquals('json', $request->getUri()->getExtension());
     $request = \Owl\Http\Request::factory(['uri' => '/', '_SERVER' => ['SERVER_NAME' => 'test.example.com']]);
     $uri = $request->getUri();
     $this->assertEquals('test.example.com', $uri->getHost());
     $request = \Owl\Http\Request::factory(['uri' => '/', 'headers' => ['host' => 'www.example.com:88'], '_SERVER' => ['SERVER_NAME' => 'test.example.com']]);
     $uri = $request->getUri();
     $this->assertEquals('www.example.com', $uri->getHost());
     $this->assertEquals(88, $uri->getPort());
 }
Exemplo n.º 6
0
 protected function execute(array $options)
 {
     $path = isset($options['uri']) ? parse_url($options['uri'], PHP_URL_PATH) : '/';
     $cookies = \Tests\Mock\Cookie::getInstance()->get($path);
     if (isset($options['cookies'])) {
         $options['cookies'] = array_merge($cookies, $options['cookies']);
     } else {
         $options['cookies'] = $cookies;
     }
     $request = \Owl\Http\Request::factory($options);
     $response = new \Tests\Mock\Response();
     $app = __get_fpm_app();
     $app->execute($request, $response);
     return $response;
 }