-
-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathRunnerTest.php
More file actions
86 lines (70 loc) · 2.51 KB
/
RunnerTest.php
File metadata and controls
86 lines (70 loc) · 2.51 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
declare(strict_types=1);
namespace Runtime\FrankenPhpSymfony\Tests;
require_once __DIR__.'/function-mock.php';
use PHPUnit\Framework\TestCase;
use Runtime\FrankenPhpSymfony\Exception\InvalidMiddlewareException;
use Runtime\FrankenPhpSymfony\Runner;
use Runtime\FrankenPhpSymfony\Tests\Support\InvalidMiddleware;
use Runtime\FrankenPhpSymfony\Tests\Support\TestMiddleware;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\HttpKernelInterface;
use Symfony\Component\HttpKernel\TerminableInterface;
interface TestAppInterface extends HttpKernelInterface, TerminableInterface
{
}
/**
* @author Kévin Dunglas <kevin@dunglas.fr>
*/
class RunnerTest extends TestCase
{
public static function runData(): iterable
{
yield 'basic' => [];
yield 'middleware' => [
'middleware' => TestMiddleware::class,
];
yield 'Invalid middleware' => [
'middleware' => InvalidMiddleware::class,
'expectException' => InvalidMiddlewareException::class,
];
}
/**
* @dataProvider runData
*/
public function testRun(
?string $middleware = null,
?string $expectException = null,
): void {
$application = $this->createMock(TestAppInterface::class);
if (null === $expectException) {
$application
->expects($this->once())
->method('handle')
->willReturnCallback(
function (
Request $request,
int $type = HttpKernelInterface::MAIN_REQUEST,
bool $catch = true
): Response {
$this->assertSame('bar', $request->server->get('FOO'));
return new Response();
}
);
$application->expects($this->once())->method('terminate');
} else {
$this->expectException($expectException);
}
$_SERVER['FOO'] = 'bar';
$runner = new Runner($application, 500, array_filter([$middleware]));
$assertMiddlewareInvoked = null === $expectException && $middleware && method_exists($middleware, 'isInvoked');
if ($assertMiddlewareInvoked) {
$this->assertFalse($middleware::isInvoked());
}
$this->assertSame(0, $runner->run());
if ($assertMiddlewareInvoked) {
$this->assertTrue($middleware::isInvoked());
}
}
}