-
-
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.
- Loading branch information
Showing
5 changed files
with
137 additions
and
3 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,60 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
use Contributte\FrameX\Application; | ||
use Contributte\FrameX\DI\FrameXExtension; | ||
use Contributte\Tester\Toolkit; | ||
use Contributte\Tester\Utils\ContainerBuilder; | ||
use Contributte\Tester\Utils\Liberator; | ||
use Contributte\Tester\Utils\Neonkit; | ||
use Nette\DI\Compiler; | ||
use React\Http\Message\ServerRequest; | ||
use Tester\Assert; | ||
use Tests\Fixtures\TestHandler; | ||
|
||
require_once __DIR__ . '/../../bootstrap.php'; | ||
|
||
// E2E | ||
Toolkit::test(function (): void { | ||
$container = ContainerBuilder::of() | ||
->withCompiler(function (Compiler $compiler): void { | ||
$compiler->addExtension('framex', new FrameXExtension()); | ||
$compiler->addConfig(Neonkit::load(<<<'NEON' | ||
framex: | ||
middlewares: [] | ||
routing: | ||
- { path: /test, method: get, controller: Tests\Fixtures\TestController } | ||
services: | ||
- Tests\Fixtures\TestController | ||
NEON | ||
)); | ||
}) | ||
->build(); | ||
|
||
/** @var Application $app */ | ||
$app = $container->getByType(Application::class); | ||
|
||
// Test to /test endpoint | ||
$sapi = TestHandler::of(new ServerRequest('GET', '/test')); | ||
Liberator::of(Liberator::of($app)->app)->sapi = $sapi; | ||
$app->run(); | ||
|
||
Assert::equal(200, $sapi->response->getStatusCode()); | ||
Assert::equal('test', $sapi->response->getBody()->getContents()); | ||
|
||
// Send to fake address | ||
$sapi = TestHandler::of(new ServerRequest('GET', '/fake')); | ||
Liberator::of(Liberator::of($app)->app)->sapi = $sapi; | ||
$app->run(); | ||
|
||
Assert::equal(404, $sapi->response->getStatusCode()); | ||
Assert::match('%A%Error 404: Page Not Found%A%', $sapi->response->getBody()->getContents()); | ||
|
||
// Send to invalid HTTP method | ||
$sapi = TestHandler::of(new ServerRequest('POST', '/test')); | ||
Liberator::of(Liberator::of($app)->app)->sapi = $sapi; | ||
$app->run(); | ||
|
||
Assert::equal(405, $sapi->response->getStatusCode()); | ||
Assert::match('%A%Error 405: Method Not Allowed%A%', $sapi->response->getBody()->getContents()); | ||
}); |
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,17 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Tests\Fixtures; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use React\Http\Message\Response; | ||
|
||
class TestController | ||
{ | ||
|
||
public function __invoke(ServerRequestInterface $request): ResponseInterface | ||
{ | ||
return Response::html('test'); | ||
} | ||
|
||
} |
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 Tests\Fixtures; | ||
|
||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use React\Http\Message\ServerRequest; | ||
|
||
class TestHandler | ||
{ | ||
|
||
public ServerRequestInterface $request; | ||
|
||
public ResponseInterface $response; | ||
|
||
public static function of(ServerRequest $param): self | ||
{ | ||
$self = new self(); | ||
$self->request = $param; | ||
|
||
return $self; | ||
} | ||
|
||
public function run(callable $handler): void | ||
{ | ||
$this->response = $handler($this->request); | ||
} | ||
|
||
} |