This repository was archived by the owner on Jul 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
Expand file tree
/
Copy pathApplicationTest.php
More file actions
55 lines (44 loc) · 1.37 KB
/
ApplicationTest.php
File metadata and controls
55 lines (44 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace functional;
use Application;
use PHPUnit\Framework\TestCase;
use Stack\Builder;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\HttpKernelInterface;
class ApplicationTest extends TestCase
{
public function testWithAppendMiddlewares()
{
$request = Request::create('/foo');
$app = new Application();
$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);
$response = $app->handle($request);
$app->terminate($request, $response);
$this->assertSame('bar.B.A', $response->getContent());
$this->assertTrue($finished);
}
}
class Append implements HttpKernelInterface
{
private $app;
private $appendix;
public function __construct(HttpKernelInterface $app, $appendix)
{
$this->app = $app;
$this->appendix = $appendix;
}
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true)
{
$response = clone $this->app->handle($request, $type, $catch);
$response->setContent($response->getContent().$this->appendix);
return $response;
}
}