From e639fd75471804fd392a4eb7f886c315b365ef75 Mon Sep 17 00:00:00 2001 From: mepihindeveloper Date: Fri, 14 Jan 2022 12:33:51 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D1=82=D0=B5=D1=81=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/php.yml | 61 ++++++++++++++++++++++++++++ README.md | 8 ++++ codeception.yml | 16 ++++++++ composer.json | 7 +++- tests/_data/.gitkeep | 0 tests/_output/.gitignore | 2 + tests/_support/AcceptanceTester.php | 26 ++++++++++++ tests/_support/FunctionalTester.php | 26 ++++++++++++ tests/_support/Helper/Acceptance.php | 10 +++++ tests/_support/Helper/Functional.php | 10 +++++ tests/_support/Helper/Unit.php | 10 +++++ tests/_support/UnitTester.php | 26 ++++++++++++ tests/_support/_generated/.gitignore | 2 + tests/acceptance.suite.yml | 13 ++++++ tests/functional.suite.yml | 13 ++++++ tests/unit.suite.yml | 10 +++++ tests/unit/ConfigurationTest.php | 58 ++++++++++++++++++++++++++ 17 files changed, 297 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/php.yml create mode 100644 codeception.yml create mode 100644 tests/_data/.gitkeep create mode 100644 tests/_output/.gitignore create mode 100644 tests/_support/AcceptanceTester.php create mode 100644 tests/_support/FunctionalTester.php create mode 100644 tests/_support/Helper/Acceptance.php create mode 100644 tests/_support/Helper/Functional.php create mode 100644 tests/_support/Helper/Unit.php create mode 100644 tests/_support/UnitTester.php create mode 100644 tests/_support/_generated/.gitignore create mode 100644 tests/acceptance.suite.yml create mode 100644 tests/functional.suite.yml create mode 100644 tests/unit.suite.yml create mode 100644 tests/unit/ConfigurationTest.php diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml new file mode 100644 index 0000000..e0c2c60 --- /dev/null +++ b/.github/workflows/php.yml @@ -0,0 +1,61 @@ +name: build + +on: + push: + branches: [ stable, development ] + pull_request: + branches: [ stable, development ] + +jobs: + build: + runs-on: ubuntu-latest + continue-on-error: ${{ matrix.experimental }} + strategy: + max-parallel: 2 + fail-fast: false + matrix: + php: [7.4, 8.0] + experimental: [false] + + steps: + - uses: actions/checkout@v2 + + - name: Setup PHP Action + uses: shivammathur/setup-php@2.16.0 + with: + php-version: ${{ matrix.php }} + coverage: xdebug + + - name: Validate composer.json and composer.lock + run: composer validate --strict + + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v2 + with: + path: vendor + key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php- + + - name: Install dependencies with Composer + uses: ramsey/composer-install@v1 + + - name: Run unit tests + run: php vendor/bin/codecept run unit + + - name: Run Codecept coverage + run: php vendor/bin/codecept run --coverage --coverage-xml --coverage-phpunit + + - name: Download artifacts + uses: actions/download-artifact@v2 + + - name: Codecov + uses: codecov/codecov-action@v2.1.0 + with: + token: ${{ secrets.CODECOV_TOKEN }} + directory: ./tests/_output + files: ./tests/_output/coverage.xml + flags: unittests + verbose: true + fail_ci_if_error: true diff --git a/README.md b/README.md index 008e254..2757557 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,13 @@ # php-configuration +![release](https://img.shields.io/github/v/release/mepihindeveloper/php-configuration?label=version) +[![Packagist Version](https://img.shields.io/packagist/v/mepihindeveloper/php-configuration)](https://packagist.org/packages/mepihindeveloper/php-configuration) +[![PHP Version Require](http://poser.pugx.org/mepihindeveloper/php-configuration/require/php)](https://packagist.org/packages/mepihindeveloper/php-configuration) +![license](https://img.shields.io/github/license/mepihindeveloper/php-configuration) + +![build](https://github.com/mepihindeveloper/php-configuration/actions/workflows/php.yml/badge.svg?branch=development) +[![codecov](https://codecov.io/gh/mepihindeveloper/php-configuration/branch/development/graph/badge.svg?token=36PP7VKHKG)](https://codecov.io/gh/mepihindeveloper/php-configuration) + Компонент для работы с конфигурацией (настройками) приложения, модулей и компонентов # Структура diff --git a/codeception.yml b/codeception.yml new file mode 100644 index 0000000..0ea767f --- /dev/null +++ b/codeception.yml @@ -0,0 +1,16 @@ +paths: + tests: tests + output: tests/_output + data: tests/_data + support: tests/_support + envs: tests/_envs +actor_suffix: Tester +extensions: + enabled: + - Codeception\Extension\RunFailed +coverage: + enabled: true + include: + - src/* + exclude: + - src/interfaces/* \ No newline at end of file diff --git a/composer.json b/composer.json index 10ccbe1..554d70a 100644 --- a/composer.json +++ b/composer.json @@ -25,5 +25,10 @@ } }, "minimum-stability": "dev", - "prefer-stable": true + "prefer-stable": true, + "require-dev": { + "codeception/codeception": "^4.1", + "codeception/module-phpbrowser": "^1.0.0", + "codeception/module-asserts": "^1.0.0" + } } diff --git a/tests/_data/.gitkeep b/tests/_data/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/_output/.gitignore b/tests/_output/.gitignore new file mode 100644 index 0000000..c96a04f --- /dev/null +++ b/tests/_output/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore \ No newline at end of file diff --git a/tests/_support/AcceptanceTester.php b/tests/_support/AcceptanceTester.php new file mode 100644 index 0000000..7359a12 --- /dev/null +++ b/tests/_support/AcceptanceTester.php @@ -0,0 +1,26 @@ + 'ru', + 'debug' => true, + 'database' => [ + 'host' => 'localhost', + 'user' => 'root', + 'password' => 123 + ] + ]; + + public function testGetSettings() { + $this->assertIsArray($this->configuration->getSettings()); + } + + public function testSetSettings() { + $this->configuration->setSettings(['message' => 'test']); + $this->assertArrayHasKey('message', $this->configuration->getSettings()); + } + + public function testHasKey() { + $this->assertTrue($this->configuration->hasKey('lang')); + } + + public function testHasNotKey() { + $this->assertFalse($this->configuration->hasKey('message')); + } + + public function testGetSettingsByKey() { + $this->assertSame('ru', $this->configuration->getSettingsByKey('lang')); + } + + public function testGetSettingsByKeyWithException() { + $this->expectException(InvalidArgumentException::class); + $this->configuration->getSettingsByKey('message'); + } + + protected function _before() { + $this->configuration = new Configuration($this->settings); + } + + // tests + + protected function _after() { + $this->configuration = null; + } +} \ No newline at end of file From a29269945e71c3a0a83740729d295e400bc560ed Mon Sep 17 00:00:00 2001 From: mepihindeveloper Date: Fri, 14 Jan 2022 12:37:50 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D0=BE=D1=82=D1=81=D1=83=D1=82=D1=81=D1=82=D0=B2?= =?UTF-8?q?=D1=83=D1=8E=D1=89=D0=B8=D0=B5=20=D0=BF=D0=B0=D0=BF=D0=BA=D0=B8?= =?UTF-8?q?=20=D1=82=D0=B5=D1=81=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/acceptance/.gitkeep | 0 tests/functional/.gitkeep | 0 2 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 tests/acceptance/.gitkeep create mode 100644 tests/functional/.gitkeep diff --git a/tests/acceptance/.gitkeep b/tests/acceptance/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/tests/functional/.gitkeep b/tests/functional/.gitkeep new file mode 100644 index 0000000..e69de29