示例#1
0
 public function testWithAppendMiddlewares()
 {
     $app = new Application();
     $app->get('/foo', function () {
         return 'bar';
     });
     $finished = false;
     $app->finish(function () use(&$finished) {
         $finished = true;
     });
     $stack = new Builder();
     $stack->push('functional\\Append', '.A')->push('functional\\Append', '.B');
     $app = $stack->resolve($app);
     $request = Request::create('/foo');
     $response = $app->handle($request);
     $app->terminate($request, $response);
     $this->assertSame('bar.B.A', $response->getContent());
     $this->assertTrue($finished);
 }
 /** @test */
 public function resolveShouldCallSpecFactories()
 {
     $app = $this->getHttpKernelMock(new Response('ok'));
     $stack = new Builder();
     $stack->push(function ($app) {
         return new Append($app, '.foo');
     });
     $stack->push(function ($app) {
         return new Append($app, '.bar');
     });
     $resolved = $stack->resolve($app);
     $request = Request::create('/');
     $response = $resolved->handle($request);
     $this->assertSame('ok.bar.foo', $response->getContent());
 }
示例#3
0
 /**
  * Return the StackPHP stack.
  * @param Builder $stack
  * @return Builder
  */
 public function getStack(Builder $stack)
 {
     $sessionReject = $this->app->bound('session.reject') ? $this->app['session.reject'] : null;
     $stack->push('Illuminate\\Cookie\\Guard', $this->app['encrypter'])->push('Illuminate\\Cookie\\Queue', $this->app['cookie'])->push('Illuminate\\Session\\Middleware', $this->app['session'], $sessionReject);
     return $stack;
 }
 public function testStackInterceptionWithExceptionCallback()
 {
     $app = new CallableHttpKernel(function (Request $request) {
         return new Response('did not get intercepted');
     });
     //the interceptor will now return a SnapSearchException
     $interceptor = Stub::make('SnapSearchClientPHP\\Interceptor', array('detector' => Stub::make('SnapSearchClientPHP\\Detector', array('request' => function () {
         return true;
     })), 'intercept' => function () {
         throw new SnapSearchException('Oh no something went wrong!');
     }));
     $stack = new Builder();
     //just making sure the callback was actually called, this will be late binded
     $was_this_called = false;
     //making tests compatible with php 5.3
     $self = $this;
     //snapsearch layer
     $stack->push('SnapSearchClientPHP\\StackInterceptor', $interceptor, null, function ($exception, $request) use(&$was_this_called, $self) {
         //the SnapSearchException will be received here
         $self->assertInstanceOf('SnapSearchClientPHP\\SnapSearchException', $exception);
         $self->assertEquals('Oh no something went wrong!', $exception->getMessage());
         //the request object will also be available if something failed
         $self->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Request', $request);
         $was_this_called = true;
     });
     //random layer underneath that will be called because exceptions are ignored in production
     $stack->push(function ($app) {
         return new CallableHttpKernel(function () {
             return new Response('random layer', 200);
         });
     });
     $app = $stack->resolve($app);
     $this->app = $app;
     $request = Request::create('/');
     $response = $this->app->handle($request);
     $this->assertTrue($was_this_called);
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertEquals('random layer', $response->getContent());
 }