-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DI: replace deprecated nette/reflection with contributte/utils
- Loading branch information
Showing
7 changed files
with
161 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
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); | ||
|
||
namespace Tests\Cases; | ||
|
||
use Contributte\ApiRouter\DI\ApiRouterExtension; | ||
use Nette\Application\Routers\RouteList; | ||
use Nette\DI\Compiler; | ||
use Nette\DI\Container; | ||
use Nette\DI\ContainerLoader; | ||
use Tester\Assert; | ||
use Tester\TestCase; | ||
use Tests\Toolkit\Helpers; | ||
use Tests\Toolkit\Tests; | ||
|
||
require __DIR__ . '/../bootstrap.php'; | ||
|
||
/** | ||
* @testCase | ||
*/ | ||
final class ApiRouteExtensionTest extends TestCase | ||
{ | ||
|
||
/** @var Container */ | ||
private $container; | ||
|
||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$loader = new ContainerLoader(Tests::TEMP_PATH, true); | ||
$class = $loader->load(function (Compiler $compiler): void { | ||
$compiler->addExtension('api', new ApiRouterExtension()); | ||
$compiler->addConfig(Helpers::neon(' | ||
services: | ||
router: Tests\Fixtures\DummyRouterFactory::create | ||
- Tests\Fixtures\UsersController | ||
')); | ||
$compiler->addConfig([ | ||
'parameters' => [ | ||
'debugMode' => false, | ||
'tempDir' => Tests::TEMP_PATH, | ||
], | ||
]); | ||
}, __FILE__ . time()); | ||
|
||
$this->container = new $class(); | ||
$this->container->initialize(); | ||
} | ||
|
||
public function testRouter(): void | ||
{ | ||
/** @var RouteList $router */ | ||
$router = $this->container->getByType(RouteList::class); | ||
|
||
Assert::count(2, $router->getRouters()); | ||
} | ||
|
||
} | ||
|
||
(new ApiRouteExtensionTest())->run(); |
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,15 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Tests\Fixtures; | ||
|
||
use Nette\Application\Routers\RouteList; | ||
|
||
final class DummyRouterFactory | ||
{ | ||
|
||
public static function create(): RouteList | ||
{ | ||
return new RouteList(); | ||
} | ||
|
||
} |
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,50 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Tests\Fixtures; | ||
|
||
use Contributte\ApiRouter\ApiRoute; | ||
use Nette\Application\UI\Presenter; | ||
|
||
/** | ||
* @ApiRoute( | ||
* "/api/users[/<id>]", | ||
* parameters={ | ||
* "id"={ | ||
* "requirement": "\d+", | ||
* "default": 10 | ||
* } | ||
* } | ||
* ) | ||
*/ | ||
class UsersController extends Presenter | ||
{ | ||
|
||
/** | ||
* Get user detail | ||
* | ||
* @ApiRoute( | ||
* "/api/users/<id>[/<foo>-<bar>]", | ||
* parameters={ | ||
* "id"={ | ||
* "requirement": "\d+" | ||
* } | ||
* }, | ||
* method="GET" | ||
* ) | ||
*/ | ||
public function actionRead($id, $foo = null, $bar = null) | ||
{ | ||
$this->sendJson(['id' => $id, 'foo' => $foo, 'bar' => $bar]); | ||
} | ||
|
||
public function actionUpdate($id) | ||
{ | ||
$this->sendJson(['id' => $id]); | ||
} | ||
|
||
public function actionDelete($id) | ||
{ | ||
$this->sendJson(['id' => $id]); | ||
} | ||
|
||
} |
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,19 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Tests\Toolkit; | ||
|
||
use Nette\DI\Config\Adapters\NeonAdapter; | ||
use Nette\Neon\Neon; | ||
|
||
final class Helpers | ||
{ | ||
|
||
/** | ||
* @return mixed[] | ||
*/ | ||
public static function neon(string $str): array | ||
{ | ||
return (new NeonAdapter())->process((array) Neon::decode($str)); | ||
} | ||
|
||
} |
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,11 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Tests\Toolkit; | ||
|
||
final class Tests | ||
{ | ||
|
||
public const APP_PATH = __DIR__ . '/..'; | ||
public const TEMP_PATH = __DIR__ . '/../tmp'; | ||
|
||
} |