From 384edcf02224ea8314a40d01f748466a60894da8 Mon Sep 17 00:00:00 2001 From: hschoenenberger Date: Tue, 26 Nov 2024 16:07:59 +0100 Subject: [PATCH 1/5] feat: wip unit tests --- composer.json | 14 ++++++++++++++ tests/phpstan.neon | 9 +++++++++ .../ServiceContainer/ServiceContainerTest.php | 16 ++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 tests/phpstan.neon create mode 100644 tests/src/ServiceContainer/ServiceContainerTest.php diff --git a/composer.json b/composer.json index 5e27e64..996459b 100644 --- a/composer.json +++ b/composer.json @@ -7,6 +7,11 @@ "PrestaShopCorp\\LightweightContainer\\": "src/" } }, + "autoload-dev": { + "psr-4": { + "PrestaShopCorp\\LightweightContainer\\Test\\": "tests/src/" + } + }, "authors": [ { "name": "hschoenenberger", @@ -15,5 +20,14 @@ ], "require": { "php": ">=5.6" + }, + "require-dev": { + "phpunit/phpunit": "^8.0 || ^9.0", + "phpstan/phpstan": "^1.7", + "prestashop/php-dev-tools": "^4.2" + }, + "scripts": { + "phpunit": "./vendor/bin/phpunit --coverage-text", + "php-cs-fixer": "./vendor/bin/php-cs-fixer fix --config .php_cs.dist.php --diff" } } diff --git a/tests/phpstan.neon b/tests/phpstan.neon new file mode 100644 index 0000000..c170fbc --- /dev/null +++ b/tests/phpstan.neon @@ -0,0 +1,9 @@ +parameters: + paths: + - ../src + bootstrapFiles: + - ../vendor/autoload.php + checkMissingIterableValueType: false + reportUnmatchedIgnoredErrors: false + + level: 6 diff --git a/tests/src/ServiceContainer/ServiceContainerTest.php b/tests/src/ServiceContainer/ServiceContainerTest.php new file mode 100644 index 0000000..42ce7a8 --- /dev/null +++ b/tests/src/ServiceContainer/ServiceContainerTest.php @@ -0,0 +1,16 @@ + Date: Tue, 26 Nov 2024 16:17:27 +0100 Subject: [PATCH 2/5] feat: wip unit tests --- .github/workflows/php.yml | 110 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 .github/workflows/php.yml diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml new file mode 100644 index 0000000..8e036e5 --- /dev/null +++ b/.github/workflows/php.yml @@ -0,0 +1,110 @@ +name: PHP tests +on: [push, pull_request] +jobs: + php-linter: + name: PHP Syntax check 5.6|7.2|8.0|8.1 + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: PHP syntax checker 5.6 + uses: prestashop/github-action-php-lint/5.6@master + with: + folder-to-exclude: "! -path \"./vendor/*\" ! -path \"./tests/*\"" + + - name: PHP syntax checker 7.2 + uses: prestashop/github-action-php-lint/7.2@master + with: + folder-to-exclude: "! -path \"./vendor/*\" ! -path \"./tests/*\"" + + - name: PHP syntax checker 8.0 + uses: prestashop/github-action-php-lint/8.0@master + with: + folder-to-exclude: "! -path \"./vendor/*\" ! -path \"./tests/*\"" + + - name: PHP syntax checker 8.1 + uses: prestashop/github-action-php-lint/8.1@master + with: + folder-to-exclude: "! -path \"./vendor/*\" ! -path \"./tests/*\"" + + php-cs-fixer: + name: PHP-CS-Fixer + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Cache vendor folder + uses: actions/cache@v3 + with: + path: vendor + key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }} + + - name: Cache composer folder + uses: actions/cache@v3 + with: + path: ~/.composer/cache + key: php-composer-cache + + - run: composer install + + - name: Run PHP-CS-Fixer + run: vendor/bin/php-cs-fixer fix --config .php_cs.dist.php --diff --dry-run + + phpstan: + name: PHPStan + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Cache vendor folder + uses: actions/cache@v3 + with: + path: vendor + key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }} + + - name: Cache composer folder + uses: actions/cache@v3 + with: + path: ~/.composer/cache + key: php-composer-cache + + - run: composer install + + - name : Run PHPStan for Guzzle 7 + run: vendor/bin/phpstan analyse -c tests/phpstan.neon + + phpunit: + name: PHPUnit + runs-on: ubuntu-latest + strategy: + matrix: + php-versions: ["7.2", "7.3", "8.0", "8.1"] + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Setup PHP with Xdebug + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-versions }} + coverage: xdebug + + - name: Cache vendor folder + uses: actions/cache@v3 + with: + path: vendor + key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}-${{ matrix.php-versions }} + + - name: Cache composer folder + uses: actions/cache@v3 + with: + path: ~/.composer/cache + key: php-composer-cache-${{ matrix.php-versions }} + + - run: composer install + + - name: Run PHPUnit + run: vendor/bin/phpunit --coverage-text From 7f6e43979b143fc68cf31048ccff5577ca145823 Mon Sep 17 00:00:00 2001 From: hschoenenberger Date: Tue, 26 Nov 2024 16:34:46 +0100 Subject: [PATCH 3/5] chore: public status links --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 932b1cf..f8c38d2 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,14 @@ # lightweight-container +[![Source Code](https://img.shields.io/badge/source-PrestaShopCorp/lightweight--container-blue.svg?style=flat-square)](https://github.com/PrestaShopCorp/lightweight-container) +[![Latest Version](https://img.shields.io/github/release/PrestaShopCorp/lightweight-container.svg?style=flat-square)](https://github.com/PrestaShopCorp/lightweight-container/releases) +[![Software License](https://img.shields.io/badge/license-OSL-brightgreen.svg?style=flat-square)](https://github.com/PrestaShopCorp/lightweight-container/blob/main/LICENSE) +[![Build Status](https://img.shields.io/github/actions/workflow/status/PrestaShopCorp/lightweight-container/.github/workflows/php.yml?label=CI&logo=github&style=flat-square)](https://github.com/PrestaShopCorp/lightweight-container/actions?query=workflow%3ACI) + +[//]: # ([![Total Downloads](https://img.shields.io/packagist/dt/PrestaShopCorp/lightweight-container.svg?style=flat-square)](https://packagist.org/packages/prestashopcorp/lightweight-container)) + +--- + # Context A module should not bundle and duplicate a heavy dependency from the framework used by the PrestaShop Core, we propose to replace module-lib-service-container with a simple service container to provide the following benefits : From 16d31dcd5ff44bd2538744b426412db9da258599 Mon Sep 17 00:00:00 2001 From: hschoenenberger Date: Tue, 26 Nov 2024 16:35:41 +0100 Subject: [PATCH 4/5] chore: public status links --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index f8c38d2..0e3f89f 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,6 @@ [//]: # ([![Total Downloads](https://img.shields.io/packagist/dt/PrestaShopCorp/lightweight-container.svg?style=flat-square)](https://packagist.org/packages/prestashopcorp/lightweight-container)) ---- - # Context A module should not bundle and duplicate a heavy dependency from the framework used by the PrestaShop Core, we propose to replace module-lib-service-container with a simple service container to provide the following benefits : From 5cfdd941f061c709e49486e616e2ac47a4ca4ab9 Mon Sep 17 00:00:00 2001 From: hschoenenberger Date: Wed, 27 Nov 2024 11:23:32 +0100 Subject: [PATCH 5/5] fix: load config must require file every time --- src/ServiceContainer/ServiceContainer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ServiceContainer/ServiceContainer.php b/src/ServiceContainer/ServiceContainer.php index 59b396d..9d6507d 100644 --- a/src/ServiceContainer/ServiceContainer.php +++ b/src/ServiceContainer/ServiceContainer.php @@ -81,7 +81,7 @@ public static function createInstance($configPath) */ public function loadConfig() { - $this->config = require_once $this->configPath; + $this->config = require $this->configPath; } /**