Skip to content

Commit

Permalink
Merge pull request #3 from Micro-PHP/v1.0.2-release
Browse files Browse the repository at this point in the history
v1.0.2 released
  • Loading branch information
Asisyas authored Jan 16, 2023
2 parents 202a9db + 709fc66 commit e2f4f54
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 114 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
},
"autoload-dev": {
"psr-4": {
"Micro\\Plugin\\Http\\Test\\": "test/"
"Micro\\Plugin\\Http\\Test\\": "tests/"
}
},
"config": {
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</php>
<testsuites>
<testsuite name="Unit tests">
<directory>test/Unit</directory>
<directory>tests/Unit</directory>
</testsuite>
</testsuites>
<coverage>
Expand Down
23 changes: 10 additions & 13 deletions src/Business/Locator/RouteCodeLocator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
* (c) Stanislau Komar <[email protected]>
*
* 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;
Expand All @@ -22,13 +22,10 @@
*/
readonly class RouteCodeLocator implements RouteLocatorInterface
{
/**
* @param KernelInterface $kernel
*/
public function __construct(
private KernelInterface $kernel
)
{
private KernelInterface $kernel,
private HttpFacadeInterface $httpFacade
) {
}

/**
Expand All @@ -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;
}
}
}
}
}
17 changes: 9 additions & 8 deletions src/HttpRouterCodePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
* (c) Stanislau Komar <[email protected]>
*
* 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;
Expand All @@ -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;

/**
Expand All @@ -27,7 +28,6 @@
readonly class HttpRouterCodePlugin implements HttpRouteLocatorPluginInterface, DependencyProviderInterface, PluginDependedInterface
{
/**
* @var Container
* @phpstan-ignore-next-line
*/
private Container $container;
Expand All @@ -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);
}

/**
Expand All @@ -59,4 +60,4 @@ public function getDependedPlugins(): iterable
HttpCorePlugin::class,
];
}
}
}
15 changes: 8 additions & 7 deletions src/Plugin/RouteProviderPluginInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
* (c) Stanislau Komar <[email protected]>
*
* 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 <[email protected]>
Expand All @@ -23,5 +24,5 @@ interface RouteProviderPluginInterface
/**
* @return iterable<RouteInterface>
*/
public function provideRoutes(): iterable;
}
public function provideRoutes(HttpFacadeInterface $httpFacade): iterable;
}
54 changes: 0 additions & 54 deletions test/Unit/TestPlugin.php

This file was deleted.

15 changes: 7 additions & 8 deletions test/Unit/AppTest.php → tests/Unit/AppTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>
* (c) Stanislau Komar <[email protected]>
*
* 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;
Expand All @@ -30,7 +30,7 @@ public function testApp()
$kernel = new AppKernel(
$configuration,
[
TestPlugin::class
HttpTestPlugin::class,
],
);

Expand All @@ -40,6 +40,5 @@ public function testApp()
->execute($request);

$this->assertEquals('Hello, kost', $response->getContent());

}
}
}
Original file line number Diff line number Diff line change
@@ -1,39 +1,38 @@
<?php

/**
* This file is part of the Micro framework package.
/*
* This file is part of the Micro framework package.
*
* (c) Stanislau Komar <[email protected]>
* (c) Stanislau Komar <[email protected]>
*
* 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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<?php

/**
* This file is part of the Micro framework package.
/*
* This file is part of the Micro framework package.
*
* (c) Stanislau Komar <[email protected]>
* (c) Stanislau Komar <[email protected]>
*
* 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;
Expand All @@ -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;
Expand All @@ -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);
}

Expand All @@ -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());
Expand All @@ -62,7 +63,7 @@ public function testProvideDependencies()
public function testGetDependedPlugins()
{
$this->assertEquals(
[ HttpCorePlugin::class ],
[HttpCorePlugin::class],
$this->plugin->getDependedPlugins()
);
}
Expand Down
Loading

0 comments on commit e2f4f54

Please sign in to comment.