Example #1
0
 public function testCompositor()
 {
     $compositor = new Compositor();
     $compositor->enable('Pux\\Middleware\\TryCatchMiddleware', ['throw' => true]);
     $compositor->enable(function ($app) {
         return function (array &$environment, array $response) use($app) {
             $environment['middleware.app'] = true;
             return $app($environment, $response);
         };
     });
     // TODO
     // $compositor->mount('/foo', function() {  });
     $compositor->app(function (array &$environment, array $response) {
         $request = RouteRequest::createFromEnv($environment);
         // $mux = new Mux;
         if ($request->pathStartWith('/foo')) {
         }
         $response[0] = 200;
         return $response;
     });
     $app = $compositor->wrap();
     $env = Utils::createEnv('GET', '/foo');
     $res = [];
     $res = $app($env, $res);
     $this->assertNotEmpty($res);
     $this->assertEquals(200, $res[0]);
 }
 public function testContentNegotiationMiddleware()
 {
     $testing = $this;
     $app = function (array &$environment, array $response) use($testing) {
         $testing->assertEquals('text/html', $environment['request.best_format']->getValue());
     };
     $env = Utils::createEnv('GET', '/');
     $env['HTTP_ACCEPT'] = 'text/html, application/xhtml+xml, application/xml;q=0.9, */*;q=0.8';
     $env['negotiation.priorities'] = array('text/html', 'application/json');
     $m = new ContentNegotiationMiddleware($app, new Negotiator());
     $response = $m->call($env, []);
 }
Example #3
0
 public function testMiddleware()
 {
     $app = function (array $environment, array $response) {
         $request = RouteRequest::createFromEnv($environment);
         return $response;
     };
     $middleware = new TryCatchMiddleware($app);
     $middleware2 = new TryCatchMiddleware($middleware);
     // $request = RouteRequest::create('GET', '/path');
     $env = Utils::createGlobals('GET', '/foo');
     $response = $middleware2($env, [200, [], []]);
     $this->assertNotEmpty($response);
 }
Example #4
0
 public function testGeocoderMiddleware()
 {
     $testing = $this;
     $app = function (array &$env, array $res) use($testing) {
         $testing->assertEquals('US', $env['geoip.country_code']);
         return $res;
     };
     // $adapter = new CurlHttpAdapter([ 'CURLOPT_CONNECTTIMEOUT' => 10000 ]);
     $adapter = new FileGetContentsHttpAdapter();
     $geocoder = new FreeGeoIp($adapter);
     $middleware = new GeocoderMiddleware($app, $geocoder);
     $env = Utils::createEnv('GET', '/');
     $env['REMOTE_ADDR'] = '173.194.72.113';
     $middleware($env, []);
 }
Example #5
0
 public function testXHProfMiddleware()
 {
     if (!extension_loaded('xhprof')) {
         return $this->markTestSkipped('xhprof extension required.');
     }
     $xhprofRoot = getenv('XHPROF_ROOT');
     if (!$xhprofRoot) {
         return $this->markTestSkipped("'XHPROF_ROOT' environment variable is unset.");
     }
     $testing = $this;
     $app = function (array &$environment, array $response) use($testing) {
         $cnt = 0;
         for ($i = 0; $i < 10000; $i++) {
             $cnt++;
         }
         return [200, [], ['Hell Yeah']];
     };
     $env = Utils::createEnv('GET', '/');
     $m = new XHProfMiddleware($app, ['flags' => XHPROF_FLAGS_NO_BUILTINS | XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY, 'root' => getenv('XHPROF_ROOT'), 'prefix' => 'pux_testing_']);
     $response = $m($env, []);
     $this->assertNotEmpty($response);
 }