-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from gacela-project/route-not-found-404
Trigger NotFound404Controller if no Route was found
- Loading branch information
Showing
16 changed files
with
112 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Gacela\Router\Controllers; | ||
|
||
final class NotFound404Controller | ||
{ | ||
public function __invoke(): void | ||
{ | ||
header('HTTP/1.0 404 Not Found'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace GacelaTest\Feature; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
include_once __DIR__ . '/header.php'; | ||
|
||
abstract class HeaderTestCase extends TestCase | ||
{ | ||
/** | ||
* @runInSeparateProcess | ||
*/ | ||
protected function setUp(): void | ||
{ | ||
global $testHeaders; | ||
|
||
$testHeaders = null; | ||
} | ||
|
||
protected function headers(): array | ||
{ | ||
global $testHeaders; | ||
|
||
return $testHeaders; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace GacelaTest\Feature\Router; | ||
|
||
use Gacela\Router\Entities\Request; | ||
use Gacela\Router\Router; | ||
use Gacela\Router\Routes; | ||
use GacelaTest\Feature\HeaderTestCase; | ||
use GacelaTest\Feature\Router\Fixtures\FakeController; | ||
|
||
final class ErrorHandlingTest extends HeaderTestCase | ||
{ | ||
public function test_match_does_not_matches_other_methods(): void | ||
{ | ||
$_SERVER['REQUEST_URI'] = 'https://example.org/expected/uri'; | ||
$_SERVER['REQUEST_METHOD'] = 'GET'; | ||
|
||
$this->expectOutputString(''); | ||
|
||
Router::configure(static function (Routes $routes): void { | ||
$routes->post('expected/uri', FakeController::class, 'basicAction'); | ||
}); | ||
} | ||
|
||
public function test_respond_status_404_when_the_uri_does_not_matches(): void | ||
{ | ||
$_SERVER['REQUEST_URI'] = 'https://example.org/optional/uri'; | ||
$_SERVER['REQUEST_METHOD'] = Request::METHOD_OPTIONS; | ||
|
||
Router::configure(static function (): void { | ||
}); | ||
|
||
self::assertSame([ | ||
[ | ||
'header' => 'HTTP/1.0 404 Not Found', | ||
'replace' => true, | ||
'response_code' => 0, | ||
], | ||
], $this->headers()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file was deleted.
Oops, something went wrong.