Security update for Core, with self-updated composer
[yaffs-website] / vendor / stack / builder / tests / functional / SilexApplicationTest.php
1 <?php
2
3 namespace functional;
4
5 use Silex\Application;
6 use Stack\Builder;
7 use Symfony\Component\HttpFoundation\Request;
8 use Symfony\Component\HttpKernel\HttpKernelInterface;
9
10 class SilexApplicationTest extends \PHPUnit_Framework_TestCase
11 {
12     public function testWithAppendMiddlewares()
13     {
14         $app = new Application();
15
16         $app->get('/foo', function () {
17             return 'bar';
18         });
19
20         $finished = false;
21
22         $app->finish(function () use (&$finished) {
23             $finished = true;
24         });
25
26         $stack = new Builder();
27         $stack
28             ->push('functional\Append', '.A')
29             ->push('functional\Append', '.B');
30
31         $app = $stack->resolve($app);
32
33         $request = Request::create('/foo');
34         $response = $app->handle($request);
35         $app->terminate($request, $response);
36
37         $this->assertSame('bar.B.A', $response->getContent());
38         $this->assertTrue($finished);
39     }
40 }
41
42 class Append implements HttpKernelInterface
43 {
44     private $app;
45     private $appendix;
46
47     public function __construct(HttpKernelInterface $app, $appendix)
48     {
49         $this->app = $app;
50         $this->appendix = $appendix;
51     }
52
53     public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
54     {
55         $response = clone $this->app->handle($request, $type, $catch);
56         $response->setContent($response->getContent().$this->appendix);
57
58         return $response;
59     }
60 }