-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
3 changed files
with
74 additions
and
9 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,72 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
/** | ||
* Test: Handler\ServiceHandler | ||
*/ | ||
|
||
use Apitte\Core\Exception\Logical\InvalidStateException; | ||
use Apitte\Core\Handler\ServiceHandler; | ||
use Apitte\Core\Http\RequestAttributes; | ||
use Apitte\Core\Schema\Endpoint; | ||
use Apitte\Core\Schema\EndpointHandler; | ||
use Apitte\Core\UI\Controller\IController; | ||
use Contributte\Psr7\Psr7ResponseFactory; | ||
use Contributte\Psr7\Psr7ServerRequestFactory; | ||
use Nette\DI\Container; | ||
use Psr\Http\Message\ResponseInterface; | ||
use Psr\Http\Message\ServerRequestInterface; | ||
use Tester\Assert; | ||
|
||
require_once __DIR__ . '/../../bootstrap.php'; | ||
|
||
// Missing endpoint | ||
test(function (): void { | ||
$container = new Container(); | ||
$sh = new ServiceHandler($container); | ||
|
||
Assert::exception(function () use ($sh): void { | ||
$request = Psr7ServerRequestFactory::fromSuperGlobal(); | ||
$response = Psr7ResponseFactory::fromGlobal(); | ||
|
||
$sh->handle($request, $response); | ||
}, InvalidStateException::class, 'Attribute "apitte.core.endpoint" is required'); | ||
}); | ||
|
||
// Missing endpoint | ||
test(function (): void { | ||
$controller = new class() implements IController | ||
{ | ||
|
||
/** | ||
* @return mixed[] | ||
*/ | ||
public function foobar(ServerRequestInterface $request, ResponseInterface $response): array | ||
{ | ||
return [$request, $response]; | ||
} | ||
|
||
}; | ||
|
||
$eh = new EndpointHandler(); | ||
$eh->setClass(get_class($controller)); | ||
$eh->setMethod('foobar'); | ||
|
||
$endpoint = new Endpoint(); | ||
$endpoint->setHandler($eh); | ||
|
||
$container = Mockery::mock(Container::class); | ||
$container->shouldReceive('getByType') | ||
->once() | ||
->andReturn($controller); | ||
|
||
$sh = new ServiceHandler($container); | ||
|
||
$request = Psr7ServerRequestFactory::fromSuperGlobal() | ||
->withAttribute(RequestAttributes::ATTR_ENDPOINT, $endpoint); | ||
$response = Psr7ResponseFactory::fromGlobal(); | ||
|
||
$res = $sh->handle($request, $response); | ||
|
||
Assert::same($request, $res[0]); | ||
Assert::same($response, $res[1]); | ||
}); |
This file was deleted.
Oops, something went wrong.