Skip to content

Commit

Permalink
Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Jul 16, 2018
1 parent 9f5a234 commit c74593b
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 9 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@
"codesniffer src tests"
],
"tester": [
"tester -s -p php --colors 1 -C tests/cases"
"tester -s -p phpdbg --colors 1 -C tests/cases"
],
"coverage": [
"tester -s -p php --colors 1 -C -d extension=xdebug.so --coverage ./coverage.xml --coverage-src ./src tests/cases"
"tester -s -p phpdbg --colors 1 -C -d extension=xdebug.so --coverage ./coverage.xml --coverage-src ./src tests/cases"
],
"phpstan-install": [
"mkdir -p temp/phpstan",
Expand Down
72 changes: 72 additions & 0 deletions tests/cases/Handler/ServiceHandler.phpt
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]);
});
7 changes: 0 additions & 7 deletions tests/php-unix.ini

This file was deleted.

0 comments on commit c74593b

Please sign in to comment.