|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace tests; |
| 6 | + |
| 7 | +use Flight; |
| 8 | +use flight\Engine; |
| 9 | +use PHPUnit\Framework\TestCase; |
| 10 | + |
| 11 | +class FlightAsyncTest extends TestCase |
| 12 | +{ |
| 13 | + public static function setUpBeforeClass(): void |
| 14 | + { |
| 15 | + Flight::setEngine(new Engine()); |
| 16 | + } |
| 17 | + |
| 18 | + protected function setUp(): void |
| 19 | + { |
| 20 | + $_SERVER = []; |
| 21 | + $_REQUEST = []; |
| 22 | + } |
| 23 | + |
| 24 | + protected function tearDown(): void |
| 25 | + { |
| 26 | + unset($_REQUEST); |
| 27 | + unset($_SERVER); |
| 28 | + } |
| 29 | + |
| 30 | + // Checks that default components are loaded |
| 31 | + public function testSingleRoute() |
| 32 | + { |
| 33 | + Flight::route('GET /', function () { |
| 34 | + echo 'hello world'; |
| 35 | + }); |
| 36 | + |
| 37 | + $this->expectOutputString('hello world'); |
| 38 | + Flight::start(); |
| 39 | + } |
| 40 | + |
| 41 | + public function testMultipleRoutes() |
| 42 | + { |
| 43 | + Flight::route('GET /', function () { |
| 44 | + echo 'hello world'; |
| 45 | + }); |
| 46 | + |
| 47 | + Flight::route('GET /test', function () { |
| 48 | + echo 'test'; |
| 49 | + }); |
| 50 | + |
| 51 | + $this->expectOutputString('test'); |
| 52 | + $_SERVER['REQUEST_URI'] = '/test'; |
| 53 | + Flight::start(); |
| 54 | + } |
| 55 | + |
| 56 | + public function testMultipleStartsSingleRoute() |
| 57 | + { |
| 58 | + Flight::route('GET /', function () { |
| 59 | + echo 'hello world'; |
| 60 | + }); |
| 61 | + |
| 62 | + $this->expectOutputString('hello worldhello world'); |
| 63 | + Flight::start(); |
| 64 | + Flight::start(); |
| 65 | + } |
| 66 | + |
| 67 | + public function testMultipleStartsMultipleRoutes() |
| 68 | + { |
| 69 | + Flight::route('GET /', function () { |
| 70 | + echo 'hello world'; |
| 71 | + }); |
| 72 | + |
| 73 | + Flight::route('GET /test', function () { |
| 74 | + echo 'test'; |
| 75 | + }); |
| 76 | + |
| 77 | + $this->expectOutputString('testhello world'); |
| 78 | + $_SERVER['REQUEST_URI'] = '/test'; |
| 79 | + Flight::start(); |
| 80 | + $_SERVER['REQUEST_URI'] = '/'; |
| 81 | + Flight::start(); |
| 82 | + } |
| 83 | +} |
0 commit comments