-
Notifications
You must be signed in to change notification settings - Fork 418
Expand file tree
/
Copy pathDocExamplesTest.php
More file actions
95 lines (76 loc) · 2.19 KB
/
DocExamplesTest.php
File metadata and controls
95 lines (76 loc) · 2.19 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
87
88
89
90
91
92
93
94
95
<?php
declare(strict_types=1);
namespace tests;
use Exception;
use Flight;
use flight\Engine;
use PHPUnit\Framework\TestCase;
use Throwable;
class DocExamplesTest extends TestCase
{
protected function setUp(): void
{
$_SERVER = [];
$_REQUEST = [];
Flight::init();
Flight::setEngine(new Engine());
}
protected function tearDown(): void
{
unset($_REQUEST);
unset($_SERVER);
Flight::clear();
}
public function testMapNotFoundMethod(): void
{
Flight::map('notFound', function () {
Flight::json([], 404);
});
Flight::request()->url = '/not-found';
Flight::route('/', function () {
echo 'hello world!';
});
Flight::start();
$this->expectOutputString('[]');
$this->assertEquals(404, Flight::response()->status());
$this->assertEquals('[]', Flight::response()->getBody());
}
public function testMapNotFoundMethodV2OutputBuffering(): void
{
Flight::map('notFound', function () {
Flight::json([], 404);
});
Flight::request()->url = '/not-found';
Flight::route('/', function () {
echo 'hello world!';
});
Flight::set('flight.v2.output_buffering', true);
Flight::start();
ob_get_clean();
$this->assertEquals(404, Flight::response()->status());
$this->assertEquals('[]', Flight::response()->getBody());
}
public function testMapErrorMethod(): void
{
Flight::map('error', function (Throwable $error) {
// Handle error
echo 'Custom: ' . $error->getMessage();
});
Flight::app()->handleException(new Exception('Error'));
$this->expectOutputString('Custom: Error');
}
public function testGetRouterStatically(): void
{
$router = Flight::router();
Flight::request()->method = 'GET';
Flight::request()->url = '/';
$router->get(
'/',
function () {
Flight::response()->write('from resp ');
}
);
Flight::start();
$this->expectOutputString('from resp ');
}
}