diff --git a/composer.json b/composer.json
index 5b4b9b8..0dca7c3 100644
--- a/composer.json
+++ b/composer.json
@@ -27,7 +27,7 @@
},
"autoload-dev": {
"psr-4": {
- "Micro\\Plugin\\Http\\Test\\": "test/"
+ "Micro\\Plugin\\Http\\Test\\": "tests/"
}
},
"config": {
@@ -37,8 +37,8 @@
},
"scripts": {
"coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-text",
- "php-cs-fix": "./vendor/bin/php-cs-fixer fix --verbose --using-cache=no",
- "php-cs-try": "./vendor/bin/php-cs-fixer fix --verbose --dry-run --using-cache=no",
+ "php-cs-fix": "PHP_CS_FIXER_IGNORE_ENV=1 ./vendor/bin/php-cs-fixer fix --verbose --using-cache=no",
+ "php-cs-try": "PHP_CS_FIXER_IGNORE_ENV=1 ./vendor/bin/php-cs-fixer fix --verbose --dry-run --using-cache=no",
"phpstan": "./vendor/bin/phpstan analyze --no-progress",
"phpunit": "./vendor/bin/phpunit",
"psalm": "./vendor/bin/psalm --no-progress --show-info=true",
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index a9f4a78..ea8cb64 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -13,7 +13,7 @@
- test/Unit
+ tests/Unit
diff --git a/src/Business/Locator/RouteCodeLocator.php b/src/Business/Locator/RouteCodeLocator.php
index c41d464..2d9c5be 100644
--- a/src/Business/Locator/RouteCodeLocator.php
+++ b/src/Business/Locator/RouteCodeLocator.php
@@ -2,13 +2,13 @@
declare(strict_types=1);
-/**
- * This file is part of the Micro framework package.
+/*
+ * This file is part of the Micro framework package.
*
- * (c) Stanislau Komar
+ * (c) Stanislau Komar
*
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
*/
namespace Micro\Plugin\Http\Business\Locator;
@@ -22,13 +22,10 @@
*/
readonly class RouteCodeLocator implements RouteLocatorInterface
{
- /**
- * @param KernelInterface $kernel
- */
public function __construct(
- private KernelInterface $kernel
- )
- {
+ private KernelInterface $kernel,
+ private HttpFacadeInterface $httpFacade
+ ) {
}
/**
@@ -39,9 +36,9 @@ public function locate(): iterable
$iterator = $this->kernel->plugins(RouteProviderPluginInterface::class);
/** @var RouteProviderPluginInterface $plugin */
foreach ($iterator as $plugin) {
- foreach ($plugin->provideRoutes() as $route) {
+ foreach ($plugin->provideRoutes($this->httpFacade) as $route) {
yield $route;
}
}
}
-}
\ No newline at end of file
+}
diff --git a/src/HttpRouterCodePlugin.php b/src/HttpRouterCodePlugin.php
index e26a996..27b3ba0 100644
--- a/src/HttpRouterCodePlugin.php
+++ b/src/HttpRouterCodePlugin.php
@@ -2,13 +2,13 @@
declare(strict_types=1);
-/**
- * This file is part of the Micro framework package.
+/*
+ * This file is part of the Micro framework package.
*
- * (c) Stanislau Komar
+ * (c) Stanislau Komar
*
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
*/
namespace Micro\Plugin\Http;
@@ -19,6 +19,7 @@
use Micro\Framework\Kernel\Plugin\PluginDependedInterface;
use Micro\Plugin\Http\Business\Locator\RouteCodeLocator;
use Micro\Plugin\Http\Business\Locator\RouteLocatorInterface;
+use Micro\Plugin\Http\Facade\HttpFacadeInterface;
use Micro\Plugin\Http\Plugin\HttpRouteLocatorPluginInterface;
/**
@@ -27,7 +28,6 @@
readonly class HttpRouterCodePlugin implements HttpRouteLocatorPluginInterface, DependencyProviderInterface, PluginDependedInterface
{
/**
- * @var Container
* @phpstan-ignore-next-line
*/
private Container $container;
@@ -46,8 +46,9 @@ public function getLocatorType(): string
public function createLocator(): RouteLocatorInterface
{
$kernel = $this->container->get(KernelInterface::class);
+ $httpFacade = $this->container->get(HttpFacadeInterface::class);
// @phpstan-ignore-next-line
- return new RouteCodeLocator($kernel);
+ return new RouteCodeLocator($kernel, $httpFacade);
}
/**
@@ -59,4 +60,4 @@ public function getDependedPlugins(): iterable
HttpCorePlugin::class,
];
}
-}
\ No newline at end of file
+}
diff --git a/src/Plugin/RouteProviderPluginInterface.php b/src/Plugin/RouteProviderPluginInterface.php
index 70b048c..b2b80bc 100644
--- a/src/Plugin/RouteProviderPluginInterface.php
+++ b/src/Plugin/RouteProviderPluginInterface.php
@@ -2,18 +2,19 @@
declare(strict_types=1);
-/**
- * This file is part of the Micro framework package.
+/*
+ * This file is part of the Micro framework package.
*
- * (c) Stanislau Komar
+ * (c) Stanislau Komar
*
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
*/
namespace Micro\Plugin\Http\Plugin;
use Micro\Plugin\Http\Business\Route\RouteInterface;
+use Micro\Plugin\Http\Facade\HttpFacadeInterface;
/**
* @author Stanislau Komar
@@ -23,5 +24,5 @@ interface RouteProviderPluginInterface
/**
* @return iterable
*/
- public function provideRoutes(): iterable;
-}
\ No newline at end of file
+ public function provideRoutes(HttpFacadeInterface $httpFacade): iterable;
+}
diff --git a/test/Unit/TestPlugin.php b/test/Unit/TestPlugin.php
deleted file mode 100644
index 534edca..0000000
--- a/test/Unit/TestPlugin.php
+++ /dev/null
@@ -1,54 +0,0 @@
-
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
-
-namespace Micro\Plugin\Http\Test\Unit;
-
-use Micro\Component\DependencyInjection\Container;
-use Micro\Framework\Kernel\Plugin\DependencyProviderInterface;
-use Micro\Framework\Kernel\Plugin\PluginDependedInterface;
-use Micro\Plugin\Http\Facade\HttpFacadeInterface;
-use Micro\Plugin\Http\HttpRouterCodePlugin;
-use Micro\Plugin\Http\Plugin\RouteProviderPluginInterface;
-use Symfony\Component\HttpFoundation\Request;
-use Symfony\Component\HttpFoundation\Response;
-
-/**
- * @author Stanislau Komar
- */
-class TestPlugin implements RouteProviderPluginInterface, DependencyProviderInterface, PluginDependedInterface
-{
- private Container $container;
-
- public function provideDependencies(Container $container): void
- {
- $this->container = $container;
- }
-
- public function provideRoutes(): iterable
- {
- yield $this->container
- ->get(HttpFacadeInterface::class)
- ->createRouteBuilder()
- ->setUri('/{parameter}')
- ->setController(function(Request $request) { return new Response('Hello, ' . $request->get('parameter'));})
- ->build()
- ;
- }
-
- public function getDependedPlugins(): iterable
- {
- return [
- HttpRouterCodePlugin::class
- ];
- }
-}
\ No newline at end of file
diff --git a/test/Unit/AppTest.php b/tests/Unit/AppTest.php
similarity index 76%
rename from test/Unit/AppTest.php
rename to tests/Unit/AppTest.php
index ef06c70..1cfb6cb 100644
--- a/test/Unit/AppTest.php
+++ b/tests/Unit/AppTest.php
@@ -2,13 +2,13 @@
declare(strict_types=1);
-/**
- * This file is part of the Micro framework package.
+/*
+ * This file is part of the Micro framework package.
*
- * (c) Stanislau Komar
+ * (c) Stanislau Komar
*
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
*/
namespace Micro\Plugin\Http\Test\Unit;
@@ -30,7 +30,7 @@ public function testApp()
$kernel = new AppKernel(
$configuration,
[
- TestPlugin::class
+ HttpTestPlugin::class,
],
);
@@ -40,6 +40,5 @@ public function testApp()
->execute($request);
$this->assertEquals('Hello, kost', $response->getContent());
-
}
-}
\ No newline at end of file
+}
diff --git a/test/Unit/Business/Locator/RouteCodeLocatorTest.php b/tests/Unit/Business/Locator/RouteCodeLocatorTest.php
similarity index 73%
rename from test/Unit/Business/Locator/RouteCodeLocatorTest.php
rename to tests/Unit/Business/Locator/RouteCodeLocatorTest.php
index 0c27d1c..62f9154 100644
--- a/test/Unit/Business/Locator/RouteCodeLocatorTest.php
+++ b/tests/Unit/Business/Locator/RouteCodeLocatorTest.php
@@ -1,39 +1,38 @@
+ * (c) Stanislau Komar
*
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
*/
-
namespace Micro\Plugin\Http\Test\Unit\Business\Locator;
use Micro\Framework\Kernel\KernelInterface;
use Micro\Plugin\Http\Business\Locator\RouteCodeLocator;
use Micro\Plugin\Http\Business\Route\RouteInterface;
+use Micro\Plugin\Http\Facade\HttpFacadeInterface;
use Micro\Plugin\Http\Plugin\RouteProviderPluginInterface;
use PHPUnit\Framework\TestCase;
class RouteCodeLocatorTest extends TestCase
{
-
public function testLocate()
{
$kernel = $this->createMock(KernelInterface::class);
+ $httpFacadeMock = $this->createMock(HttpFacadeInterface::class);
$kernel
->expects($this->once())
->method('plugins')
->with(RouteProviderPluginInterface::class)
->willReturn([
$this->createRouteProvider(),
- $this->createRouteProvider()
]);
- $routerCodeLocator = new RouteCodeLocator($kernel);
+ $routerCodeLocator = new RouteCodeLocator($kernel, $httpFacadeMock);
foreach ($routerCodeLocator->locate() as $route) {
$this->assertInstanceOf(RouteInterface::class, $route);
}
diff --git a/test/Unit/HttpRouterCodePluginTest.php b/tests/Unit/HttpRouterCodePluginTest.php
similarity index 74%
rename from test/Unit/HttpRouterCodePluginTest.php
rename to tests/Unit/HttpRouterCodePluginTest.php
index d8cd7e9..3809529 100644
--- a/test/Unit/HttpRouterCodePluginTest.php
+++ b/tests/Unit/HttpRouterCodePluginTest.php
@@ -1,12 +1,12 @@
+ * (c) Stanislau Komar
*
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
*/
namespace Micro\Plugin\Http\Test\Unit;
@@ -15,6 +15,7 @@
use Micro\Framework\Kernel\KernelInterface;
use Micro\Framework\Kernel\Plugin\DependencyProviderInterface;
use Micro\Plugin\Http\Business\Locator\RouteLocatorInterface;
+use Micro\Plugin\Http\Facade\HttpFacadeInterface;
use Micro\Plugin\Http\HttpCorePlugin;
use Micro\Plugin\Http\HttpRouterCodePlugin;
use Micro\Plugin\Http\Plugin\HttpRouteLocatorPluginInterface;
@@ -25,14 +26,15 @@ class HttpRouterCodePluginTest extends TestCase
protected \Micro\Plugin\Http\HttpRouterCodePlugin $plugin;
protected Container $container;
- public function setUp(): void
+ protected function setUp(): void
{
$this->container = $this->createMock(Container::class);
$this->plugin = new HttpRouterCodePlugin();
$this->plugin->provideDependencies($this->container);
}
- public function testConstruct() {
+ public function testConstruct()
+ {
$this->assertInstanceOf(HttpRouteLocatorPluginInterface::class, $this->plugin);
}
@@ -44,11 +46,10 @@ public function testGetLocatorType()
public function testCreateLocator()
{
$this->container
- ->expects($this->once())
->method('get')
- ->with(KernelInterface::class)
->willReturn(
- $this->createMock(KernelInterface::class)
+ $this->createMock(KernelInterface::class),
+ $this->createMock(HttpFacadeInterface::class)
);
$this->assertInstanceOf(RouteLocatorInterface::class, $this->plugin->createLocator());
@@ -62,7 +63,7 @@ public function testProvideDependencies()
public function testGetDependedPlugins()
{
$this->assertEquals(
- [ HttpCorePlugin::class ],
+ [HttpCorePlugin::class],
$this->plugin->getDependedPlugins()
);
}
diff --git a/tests/Unit/HttpTestPlugin.php b/tests/Unit/HttpTestPlugin.php
new file mode 100644
index 0000000..933eadd
--- /dev/null
+++ b/tests/Unit/HttpTestPlugin.php
@@ -0,0 +1,44 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Micro\Plugin\Http\Test\Unit;
+
+use Micro\Framework\Kernel\Plugin\PluginDependedInterface;
+use Micro\Plugin\Http\Facade\HttpFacadeInterface;
+use Micro\Plugin\Http\HttpRouterCodePlugin;
+use Micro\Plugin\Http\Plugin\RouteProviderPluginInterface;
+use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
+
+/**
+ * @author Stanislau Komar
+ */
+class HttpTestPlugin implements RouteProviderPluginInterface, PluginDependedInterface
+{
+ public function provideRoutes(HttpFacadeInterface $httpFacade): iterable
+ {
+ yield $httpFacade
+ ->createRouteBuilder()
+ ->setUri('/{parameter}')
+ ->setController(function (Request $request) { return new Response('Hello, '.$request->get('parameter')); })
+ ->build()
+ ;
+ }
+
+ public function getDependedPlugins(): iterable
+ {
+ return [
+ HttpRouterCodePlugin::class,
+ ];
+ }
+}