diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..1366148 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,9 @@ +/.github export-ignore +/tests export-ignore +/phpunit.xml.dist export-ignore +/.gitattributes export-ignore +/.gitignore export-ignore +/.php-cs-fixer.dist.php export-ignore +/psalm.xml export-ignore + +*.php diff=php \ No newline at end of file diff --git a/.github/workflows/.editorconfig b/.github/workflows/.editorconfig new file mode 100644 index 0000000..473df25 --- /dev/null +++ b/.github/workflows/.editorconfig @@ -0,0 +1,2 @@ +[{*.yaml,*.yml}] +indent_size = 2 \ No newline at end of file diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..e54001a --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,58 @@ +name: Plugin CI +on: + push: + branches: [ 'master' ] + pull_request: + +env: + PHP_CS_FIXER_IGNORE_ENV: 1 + XDEBUG_MODE: coverage + +jobs: + tests: + name: "Tests ${{ matrix.php-version }} deps ${{ matrix.dependency-versions }}" + runs-on: ubuntu-22.04 + + strategy: + fail-fast: false + matrix: + # normal, highest, non-dev installs + php-version: [ '8.2' ] + dependency-versions: [ 'highest' ] + include: + # testing lowest PHP version with the lowest dependencies + # - php-version: '8.2' + # dependency-versions: 'lowest' + + # testing dev versions with the highest PHP + - php-version: '8.2' + dependency-versions: 'highest' + + steps: + - name: "Checkout code" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + + - name: "Composer install" + uses: "ramsey/composer-install@v2" + with: + dependency-versions: "${{ matrix.dependency-versions }}" + composer-options: "--prefer-dist --no-progress" + + - name: Run tests + run: composer run test + + - name: Coverage report + run: XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-clover coverage.xml + + - name: Upload coverage reports to Codecov + run: | + # Replace `linux` below with the appropriate OS + curl -Os https://uploader.codecov.io/latest/linux/codecov + chmod +x codecov + ./codecov -t ${CODECOV_TOKEN} \ No newline at end of file diff --git a/.gitignore b/.gitignore old mode 100755 new mode 100644 index 8759011..d22afeb --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,10 @@ -.phpdoc/ -docs/ -vendor/ +.idea +vendor composer.lock .phpunit.result.cache +.php-cs-fixer.cache +test-coverage-report +coverage +phpunit.xml +.php-cs-fixer.php +phpstan.neon \ No newline at end of file diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..5147b69 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,31 @@ +in(__DIR__.'/src') + ->in(__DIR__.'/tests') +; + +return (new PhpCsFixer\Config()) + ->setRules(array( + '@Symfony' => true, + '@Symfony:risky' => true, + 'protected_to_private' => false, + 'semicolon_after_instruction' => false, + 'phpdoc_to_comment' => ['ignored_tags' => ['psalm-suppress']], + 'header_comment' => [ + 'header' => << + + For the full copyright and license information, please view the LICENSE + file that was distributed with this source code. +EOF + ] + )) + ->setRiskyAllowed(true) + ->setFinder($finder); \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100755 index 0000000..e6c0e69 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2022 Komar Stanislau + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..cba81fa --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# Micro Framework - The minimum kernel for application initialization. + +Documentation is available [here](https://micro-php.net/docs). If not, we will be grateful if you can become its author :) \ No newline at end of file diff --git a/composer.json b/composer.json index b2ad0d0..3480291 100644 --- a/composer.json +++ b/composer.json @@ -1,21 +1,59 @@ { "name": "micro/kernel-boot-plugin-depended", "description": "Micro Framework: Kernel Boot loader - component to provide dependencies", - "type": "library", - "version": "1.0", + "license": "MIT", + "type": "micro-plugin", + "authors": [ + { + "name": "Stanislau Komar", + "email": "stanislau_komar@epam.com" + } + ], "require": { - "micro/kernel": "^1" + "micro/kernel": "^1.6" + }, + "require-dev": { + "ergebnis/composer-normalize": "^2.29", + "friendsofphp/php-cs-fixer": "^3.13", + "phpstan/phpstan": "^1.9", + "phpunit/php-code-coverage": "^9.2", + "phpunit/phpunit": "^9.5", + "vimeo/psalm": "^5.2" }, - "license": "MIT", "autoload": { "psr-4": { "Micro\\Framework\\Kernel\\": "src/" } }, - "authors": [ - { - "name": "Stanislau Komar", - "email": "stanislau_komar@epam.com" + "autoload-dev": { + "psr-4": { + "Micro\\Framework\\Kernel\\Test\\Unit\\": "tests/Unit" } - ] + }, + "config": { + "allow-plugins": { + "ergebnis/composer-normalize": true + }, + "sort-packages": true + }, + "scripts": { + "coverage": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-text", + "coverage-html": "XDEBUG_MODE=coverage ./vendor/bin/phpunit --coverage-html ./test-coverage-report", + "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 --no-cache", + "statics": [ + "@phpstan", + "@psalm", + "@php-cs-try" + ], + "test": [ + "@statics", + "composer validate --strict", + "composer normalize", + "@coverage" + ] + } } diff --git a/phpcs.xml b/phpcs.xml new file mode 100755 index 0000000..a92f5e2 --- /dev/null +++ b/phpcs.xml @@ -0,0 +1,64 @@ + + + src/ + + + + + Micro Framework - сode formatting rules. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/phpstan.neon.dist b/phpstan.neon.dist new file mode 100644 index 0000000..18d77f7 --- /dev/null +++ b/phpstan.neon.dist @@ -0,0 +1,4 @@ +parameters: + level: 7 + paths: + - src \ No newline at end of file diff --git a/phpunit.xml.dist b/phpunit.xml.dist new file mode 100644 index 0000000..88daaff --- /dev/null +++ b/phpunit.xml.dist @@ -0,0 +1,41 @@ + + + + + + + + + tests/Unit + + + + + src/ + + src/Exception + src/HttpCorePlugin.php + + + + + + src + + + + + + + + + + + \ No newline at end of file diff --git a/psalm.xml b/psalm.xml new file mode 100644 index 0000000..99ad2c8 --- /dev/null +++ b/psalm.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/src/Boot/DependedPluginsBootLoader.php b/src/Boot/DependedPluginsBootLoader.php index 104ce46..177ded5 100644 --- a/src/Boot/DependedPluginsBootLoader.php +++ b/src/Boot/DependedPluginsBootLoader.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\Framework\Kernel\Boot; @@ -16,20 +16,15 @@ use Micro\Framework\Kernel\KernelInterface; use Micro\Framework\Kernel\Plugin\PluginBootLoaderInterface; use Micro\Framework\Kernel\Plugin\PluginDependedInterface; -use Micro\Kernel\App\AppKernelInterface; /** - * @author Stanislau Komar + * @author Stanislau Komar */ readonly class DependedPluginsBootLoader implements PluginBootLoaderInterface { - /** - * @param AppKernelInterface $kernel - */ public function __construct( private KernelInterface $kernel - ) - { + ) { } /** @@ -42,7 +37,7 @@ public function boot(object $applicationPlugin): void } $dependedPlugins = $applicationPlugin->getDependedPlugins(); - if(!$dependedPlugins) { + if (!$dependedPlugins) { return; } @@ -50,4 +45,4 @@ public function boot(object $applicationPlugin): void $this->kernel->loadPlugin($plugin); } } -} \ No newline at end of file +} diff --git a/src/Plugin/PluginDependedInterface.php b/src/Plugin/PluginDependedInterface.php index 96b5b7a..ca61205 100644 --- a/src/Plugin/PluginDependedInterface.php +++ b/src/Plugin/PluginDependedInterface.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\Framework\Kernel\Plugin; @@ -24,4 +24,4 @@ interface PluginDependedInterface * @return iterable */ public function getDependedPlugins(): iterable; -} \ No newline at end of file +} diff --git a/tests/Unit/Boot/DependedPluginsBootLoaderTest.php b/tests/Unit/Boot/DependedPluginsBootLoaderTest.php new file mode 100644 index 0000000..16e81ae --- /dev/null +++ b/tests/Unit/Boot/DependedPluginsBootLoaderTest.php @@ -0,0 +1,59 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Micro\Framework\Kernel\Test\Unit\Boot; + +use Micro\Component\DependencyInjection\Container; +use Micro\Framework\Kernel\Boot\DependedPluginsBootLoader; +use Micro\Framework\Kernel\Kernel; +use Micro\Framework\Kernel\KernelInterface; +use Micro\Framework\Kernel\Plugin\PluginDependedInterface; +use Micro\Framework\Kernel\Test\Unit\PluginHasDepends; +use PHPUnit\Framework\TestCase; + +class DependedPluginsBootLoaderTest extends TestCase +{ + private KernelInterface|null $kernel = null; + + private object $pluginNotHasDepends; + + private PluginDependedInterface $pluginDependedWithEmptyDepends; + + private PluginDependedInterface $pluginDependedWithDepends; + + protected function setUp(): void + { + } + + public function testBoot() + { + $this->kernel = new Kernel( + [ + PluginHasDepends::class, + ], + [], + new Container(), + ); + + $bootLoader = new DependedPluginsBootLoader($this->kernel); + $this->kernel->addBootLoader($bootLoader); + $this->kernel->run(); + + $i = 0; + foreach ($this->kernel->plugins() as $plugin) { + ++$i; + } + + $this->assertEquals(3, $i); + } +} diff --git a/tests/Unit/EmptyPlugin.php b/tests/Unit/EmptyPlugin.php new file mode 100644 index 0000000..8fb7324 --- /dev/null +++ b/tests/Unit/EmptyPlugin.php @@ -0,0 +1,21 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Micro\Framework\Kernel\Test\Unit; + +/** + * @author Stanislau Komar + */ +class EmptyPlugin +{ +} diff --git a/tests/Unit/PluginHasDepends.php b/tests/Unit/PluginHasDepends.php new file mode 100644 index 0000000..2b4ff81 --- /dev/null +++ b/tests/Unit/PluginHasDepends.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Micro\Framework\Kernel\Test\Unit; + +use Micro\Framework\Kernel\Plugin\PluginDependedInterface; + +/** + * @author Stanislau Komar + */ +class PluginHasDepends implements PluginDependedInterface +{ + public function getDependedPlugins(): iterable + { + return [ + EmptyPlugin::class, + PluginHasEmptyDepends::class, + ]; + } +} diff --git a/tests/Unit/PluginHasEmptyDepends.php b/tests/Unit/PluginHasEmptyDepends.php new file mode 100644 index 0000000..c13ad34 --- /dev/null +++ b/tests/Unit/PluginHasEmptyDepends.php @@ -0,0 +1,27 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Micro\Framework\Kernel\Test\Unit; + +use Micro\Framework\Kernel\Plugin\PluginDependedInterface; + +/** + * @author Stanislau Komar + */ +class PluginHasEmptyDepends implements PluginDependedInterface +{ + public function getDependedPlugins(): iterable + { + return []; + } +}