public function testFromGlobalsUrlNoModRewriteRootDir()
 {
     Configure::write('App', ['dir' => 'cake', 'webroot' => 'webroot', 'base' => false, 'baseUrl' => '/index.php']);
     $server = ['DOCUMENT_ROOT' => '/Users/markstory/Sites/cake', 'SCRIPT_FILENAME' => '/Users/markstory/Sites/cake/index.php', 'PHP_SELF' => '/index.php/posts/add', 'REQUEST_URI' => '/index.php/posts/add'];
     $res = ServerRequestFactory::fromGlobals($server);
     $this->assertEquals('/webroot/', $res->getAttribute('webroot'));
     $this->assertEquals('/index.php', $res->getAttribute('base'));
     $this->assertEquals('/posts/add', $res->getUri()->getPath());
 }
 /**
  * Integration test for a simple controller.
  *
  * @return void
  */
 public function testInvoke()
 {
     $next = function ($req, $res) {
         return $res;
     };
     $response = new Response();
     $request = ServerRequestFactory::fromGlobals(['REQUEST_URI' => '/cakes']);
     $request = $request->withAttribute('params', ['controller' => 'Cakes', 'action' => 'index', 'plugin' => null, 'pass' => []]);
     $app = $this->getMockForAbstractClass('Spekkoek\\BaseApplication', [TESTS]);
     $result = $app($request, $response, $next);
     $this->assertInstanceOf('Psr\\Http\\Message\\ResponseInterface', $result);
     $this->assertEquals('Hello Jane', '' . $result->getBody());
 }
Пример #3
0
 /**
  * Run the request/response through the Application and its middleware.
  *
  * This will invoke the following methods:
  *
  * - App->bootstrap() - Perform any bootstrapping logic for your application here.
  * - App->middleware() - Attach any application middleware here.
  * - Trigger the 'Server.buildMiddleware' event. You can use this to modify the
  *   from event listeners.
  * - Run the middleware stack including the application.
  *
  * @param \Psr\Http\Message\ServerRequestInterface $request  The request to use or null.
  * @param \Psr\Http\Message\ResponseInterface      $response The response to use or null.
  * @return \Psr\Http\Message\ResponseInterface
  */
 public function run(ServerRequestInterface $request = null, ResponseInterface $response = null)
 {
     $this->app->bootstrap();
     $request = $request ?: ServerRequestFactory::fromGlobals();
     $response = $response ?: new Response();
     $middleware = $this->app->middleware(new MiddlewareStack());
     if (!$middleware instanceof MiddlewareStack) {
         throw new RuntimeException('The application `middleware` method did not return a middleware stack.');
     }
     $middleware->push($this->app);
     $this->dispatchEvent('Server.buildMiddleware', ['middleware' => $middleware]);
     $response = $this->runner->run($middleware, $request, $response);
     if (!$response instanceof ResponseInterface) {
         throw new RuntimeException(sprintf('Application did not create a response. Got "%s" instead.', is_object($response) ? get_class($response) : $response));
     }
     return $response;
 }
 public function testToCakeBaseSessionPath()
 {
     Configure::write('App.baseUrl', false);
     $server = ['DOCUMENT_ROOT' => '/cake/repo/branches', 'PHP_SELF' => '/thisapp/webroot/index.php', 'REQUEST_URI' => '/posts/view/1'];
     $psr = ServerRequestFactory::fromGlobals($server);
     $cake = RequestTransformer::toCake($psr);
     $this->assertEquals('/thisapp', ini_get('session.cookie_path'));
 }
 public function test404OnDoubleDot()
 {
     $request = ServerRequestFactory::fromGlobals(['REQUEST_URI' => '/test_plugin/../webroot/root.js']);
     $response = new Response();
     $next = function ($req, $res) {
         return $res;
     };
     $middleware = new AssetMiddleware();
     $res = $middleware($request, $response, $next);
     $this->assertEmpty($res->getBody()->getContents());
 }