Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to generate new requests/responses on duplicate start() #622

Merged
merged 2 commits into from
Feb 21, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion flight/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,7 @@ public function _start(): void
$this->unregister('response');
$this->register('request', Request::class);
$this->register('response', Response::class);
$this->router()->reset();
}
$request = $this->request();
$response = $this->response();
Expand All @@ -513,7 +514,6 @@ public function _start(): void

// Route the request
$failedMiddlewareCheck = false;

while ($route = $router->route($request)) {
$params = array_values($route->params);

Expand Down
83 changes: 83 additions & 0 deletions tests/FlightAsyncTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?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()
{
Flight::route('GET /', function () {
echo 'hello world';
});

$this->expectOutputString('hello world');
Flight::start();
}

public function testMultipleRoutes()
{
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()
{
Flight::route('GET /', function () {
echo 'hello world';
});

$this->expectOutputString('hello worldhello world');
Flight::start();
Flight::start();
}

public function testMultipleStartsMultipleRoutes()
{
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();
}
}