Skip to content

Commit

Permalink
Added container to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lulco committed Jul 22, 2024
1 parent 9fd7057 commit ffc7a48
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 11 deletions.
18 changes: 14 additions & 4 deletions tests/ApiDeciderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Tomaj\NetteApi\Test\Params;

use Nette\DI\Container;
use PHPUnit\Framework\TestCase;
use Tomaj\NetteApi\ApiDecider;
use Tomaj\NetteApi\Authorization\NoAuthorization;
Expand All @@ -14,9 +15,18 @@

class ApiDeciderTest extends TestCase
{
/** @var Container */
private $container;

protected function setUp(): void
{
$this->container = new Container();
}

public function testDefaultHandlerWithNoRegisteredHandlers()
{
$apiDecider = new ApiDecider();

$apiDecider = new ApiDecider($this->container);
$result = $apiDecider->getApi('POST', '1', 'article', 'list');

$this->assertInstanceOf(EndpointIdentifier::class, $result->getEndpoint());
Expand All @@ -26,7 +36,7 @@ public function testDefaultHandlerWithNoRegisteredHandlers()

public function testFindRightHandler()
{
$apiDecider = new ApiDecider();
$apiDecider = new ApiDecider($this->container);
$apiDecider->addApi(
new EndpointIdentifier('POST', '2', 'comments', 'list'),
new AlwaysOkHandler(),
Expand All @@ -47,7 +57,7 @@ public function testFindRightHandler()

public function testGetHandlers()
{
$apiDecider = new ApiDecider();
$apiDecider = new ApiDecider($this->container);

$this->assertEquals(0, count($apiDecider->getApis()));

Expand All @@ -62,7 +72,7 @@ public function testGetHandlers()

public function testGlobalPreflight()
{
$apiDecider = new ApiDecider();
$apiDecider = new ApiDecider($this->container);
$apiDecider->enableGlobalPreflight();

$this->assertEquals(0, count($apiDecider->getApis()));
Expand Down
13 changes: 11 additions & 2 deletions tests/Handler/ApiListingHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Nette\Application\LinkGenerator;
use Nette\Application\Routers\SimpleRouter;
use Nette\DI\Container;
use Nette\Http\UrlScript;
use PHPUnit\Framework\TestCase;
use Tomaj\NetteApi\ApiDecider;
Expand All @@ -18,12 +19,20 @@

class ApiListingHandlerTest extends TestCase
{
/** @var Container */
private $container;

protected function setUp(): void
{
$this->container = new Container();
}

public function testDefaultHandle()
{
$linkGenerator = new LinkGenerator(new SimpleRouter([]), new UrlScript('http://test/'));
$apiLink = new ApiLink($linkGenerator);

$apiDecider = new ApiDecider();
$apiDecider = new ApiDecider($this->container);
$apiDecider->addApi(
new EndpointIdentifier('POST', '2', 'comments', 'list'),
new AlwaysOkHandler(),
Expand All @@ -50,7 +59,7 @@ public function testHandlerWithParam()
$linkGenerator = new LinkGenerator(new SimpleRouter([]), new UrlScript('http://test/'));
$apiLink = new ApiLink($linkGenerator);

$apiDecider = new ApiDecider();
$apiDecider = new ApiDecider($this->container);
$apiDecider->addApi(
new EndpointIdentifier('POST', '1', 'comments', 'list'),
new EchoHandler(),
Expand Down
11 changes: 10 additions & 1 deletion tests/Handler/OpenApiHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Nette\Application\LinkGenerator;
use Nette\Application\Routers\SimpleRouter;
use Nette\DI\Container;
use Nette\Http\UrlScript;
use PHPUnit\Framework\TestCase;
use Tomaj\NetteApi\ApiDecider;
Expand All @@ -17,13 +18,21 @@

class OpenApiHandlerTest extends TestCase
{
/** @var Container */
private $container;

protected function setUp(): void
{
$this->container = new Container();
}

public function testHandlerWithMultipleResponseSchemas()
{
$linkGenerator = new LinkGenerator(new SimpleRouter([]), new UrlScript('http://test/'));
$apiLink = new ApiLink($linkGenerator);
$request = new Request(new UrlScript('http://test/'));

$apiDecider = new ApiDecider();
$apiDecider = new ApiDecider($this->container);
$apiDecider->addApi(
new EndpointIdentifier('GET', '1', 'test'),
new MultipleOutputTestHandler(),
Expand Down
16 changes: 12 additions & 4 deletions tests/Presenters/ApiPresenterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,17 @@

class ApiPresenterTest extends TestCase
{
/** @var Container */
private $container;

protected function setUp(): void
{
$this->container = new Container();
}

public function testSimpleResponse()
{
$apiDecider = new ApiDecider();
$apiDecider = new ApiDecider($this->container);
$apiDecider->addApi(new EndpointIdentifier('GET', '1', 'test', 'api'), new AlwaysOkHandler(), new NoAuthorization());

$presenter = new ApiPresenter();
Expand All @@ -45,7 +53,7 @@ public function testSimpleResponse()

public function testWithAuthorization()
{
$apiDecider = new ApiDecider();
$apiDecider = new ApiDecider($this->container);
$apiDecider->addApi(
new EndpointIdentifier('GET', '1', 'test', 'api'),
new AlwaysOkHandler(),
Expand All @@ -66,7 +74,7 @@ public function testWithAuthorization()

public function testWithParams()
{
$apiDecider = new ApiDecider();
$apiDecider = new ApiDecider($this->container);
$apiDecider->addApi(
new EndpointIdentifier('GET', '1', 'test', 'api'),
new EchoHandler(),
Expand Down Expand Up @@ -95,7 +103,7 @@ public function testWithParams()

public function testWithOutputs()
{
$apiDecider = new ApiDecider();
$apiDecider = new ApiDecider($this->container);
$apiDecider->addApi(
new EndpointIdentifier('GET', '1', 'test', 'api'),
new TestHandler(),
Expand Down

0 comments on commit ffc7a48

Please sign in to comment.