mirror of https://github.com/flightphp/core
				
				
				
			
			You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							84 lines
						
					
					
						
							1.8 KiB
						
					
					
				
			
		
		
	
	
							84 lines
						
					
					
						
							1.8 KiB
						
					
					
				<?php
 | 
						|
 | 
						|
declare(strict_types=1);
 | 
						|
 | 
						|
namespace tests;
 | 
						|
 | 
						|
use Flight;
 | 
						|
use flight\Engine;
 | 
						|
use PHPUnit\Framework\TestCase;
 | 
						|
 | 
						|
class FlightAsyncTest extends TestCase
 | 
						|
{
 | 
						|
    public static function setUpBeforeClass(): void
 | 
						|
    {
 | 
						|
        Flight::setEngine(new Engine());
 | 
						|
    }
 | 
						|
 | 
						|
    protected function setUp(): void
 | 
						|
    {
 | 
						|
        $_SERVER = [];
 | 
						|
        $_REQUEST = [];
 | 
						|
    }
 | 
						|
 | 
						|
    protected function tearDown(): void
 | 
						|
    {
 | 
						|
        unset($_REQUEST);
 | 
						|
        unset($_SERVER);
 | 
						|
    }
 | 
						|
 | 
						|
    // Checks that default components are loaded
 | 
						|
    public function testSingleRoute(): void
 | 
						|
    {
 | 
						|
        Flight::route('GET /', function () {
 | 
						|
            echo 'hello world';
 | 
						|
        });
 | 
						|
 | 
						|
        $this->expectOutputString('hello world');
 | 
						|
        Flight::start();
 | 
						|
    }
 | 
						|
 | 
						|
    public function testMultipleRoutes(): void
 | 
						|
    {
 | 
						|
        Flight::route('GET /', function () {
 | 
						|
            echo 'hello world';
 | 
						|
        });
 | 
						|
 | 
						|
        Flight::route('GET /test', function () {
 | 
						|
            echo 'test';
 | 
						|
        });
 | 
						|
 | 
						|
        $this->expectOutputString('test');
 | 
						|
        $_SERVER['REQUEST_URI'] = '/test';
 | 
						|
        Flight::start();
 | 
						|
    }
 | 
						|
 | 
						|
    public function testMultipleStartsSingleRoute(): void
 | 
						|
    {
 | 
						|
        Flight::route('GET /', function () {
 | 
						|
            echo 'hello world';
 | 
						|
        });
 | 
						|
 | 
						|
        $this->expectOutputString('hello worldhello world');
 | 
						|
        Flight::start();
 | 
						|
        Flight::start();
 | 
						|
    }
 | 
						|
 | 
						|
    public function testMultipleStartsMultipleRoutes(): void
 | 
						|
    {
 | 
						|
        Flight::route('GET /', function () {
 | 
						|
            echo 'hello world';
 | 
						|
        });
 | 
						|
 | 
						|
        Flight::route('GET /test', function () {
 | 
						|
            echo 'test';
 | 
						|
        });
 | 
						|
 | 
						|
        $this->expectOutputString('testhello world');
 | 
						|
        $_SERVER['REQUEST_URI'] = '/test';
 | 
						|
        Flight::start();
 | 
						|
        $_SERVER['REQUEST_URI'] = '/';
 | 
						|
        Flight::start();
 | 
						|
    }
 | 
						|
}
 |