Skip to content

Commit aa728b2

Browse files
Merge pull request #1
Реализованы тесты
2 parents 54bc605 + a292699 commit aa728b2

19 files changed

+297
-1
lines changed

.github/workflows/php.yml

+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: build
2+
3+
on:
4+
push:
5+
branches: [ stable, development ]
6+
pull_request:
7+
branches: [ stable, development ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
continue-on-error: ${{ matrix.experimental }}
13+
strategy:
14+
max-parallel: 2
15+
fail-fast: false
16+
matrix:
17+
php: [7.4, 8.0]
18+
experimental: [false]
19+
20+
steps:
21+
- uses: actions/checkout@v2
22+
23+
- name: Setup PHP Action
24+
uses: shivammathur/[email protected]
25+
with:
26+
php-version: ${{ matrix.php }}
27+
coverage: xdebug
28+
29+
- name: Validate composer.json and composer.lock
30+
run: composer validate --strict
31+
32+
- name: Cache Composer packages
33+
id: composer-cache
34+
uses: actions/cache@v2
35+
with:
36+
path: vendor
37+
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
38+
restore-keys: |
39+
${{ runner.os }}-php-
40+
41+
- name: Install dependencies with Composer
42+
uses: ramsey/composer-install@v1
43+
44+
- name: Run unit tests
45+
run: php vendor/bin/codecept run unit
46+
47+
- name: Run Codecept coverage
48+
run: php vendor/bin/codecept run --coverage --coverage-xml --coverage-phpunit
49+
50+
- name: Download artifacts
51+
uses: actions/download-artifact@v2
52+
53+
- name: Codecov
54+
uses: codecov/[email protected]
55+
with:
56+
token: ${{ secrets.CODECOV_TOKEN }}
57+
directory: ./tests/_output
58+
files: ./tests/_output/coverage.xml
59+
flags: unittests
60+
verbose: true
61+
fail_ci_if_error: true

README.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
# php-configuration
22

3+
![release](https://img.shields.io/github/v/release/mepihindeveloper/php-configuration?label=version)
4+
[![Packagist Version](https://img.shields.io/packagist/v/mepihindeveloper/php-configuration)](https://packagist.org/packages/mepihindeveloper/php-configuration)
5+
[![PHP Version Require](http://poser.pugx.org/mepihindeveloper/php-configuration/require/php)](https://packagist.org/packages/mepihindeveloper/php-configuration)
6+
![license](https://img.shields.io/github/license/mepihindeveloper/php-configuration)
7+
8+
![build](https://github.com/mepihindeveloper/php-configuration/actions/workflows/php.yml/badge.svg?branch=development)
9+
[![codecov](https://codecov.io/gh/mepihindeveloper/php-configuration/branch/development/graph/badge.svg?token=36PP7VKHKG)](https://codecov.io/gh/mepihindeveloper/php-configuration)
10+
311
Компонент для работы с конфигурацией (настройками) приложения, модулей и компонентов
412

513
# Структура

codeception.yml

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
paths:
2+
tests: tests
3+
output: tests/_output
4+
data: tests/_data
5+
support: tests/_support
6+
envs: tests/_envs
7+
actor_suffix: Tester
8+
extensions:
9+
enabled:
10+
- Codeception\Extension\RunFailed
11+
coverage:
12+
enabled: true
13+
include:
14+
- src/*
15+
exclude:
16+
- src/interfaces/*

composer.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,10 @@
2525
}
2626
},
2727
"minimum-stability": "dev",
28-
"prefer-stable": true
28+
"prefer-stable": true,
29+
"require-dev": {
30+
"codeception/codeception": "^4.1",
31+
"codeception/module-phpbrowser": "^1.0.0",
32+
"codeception/module-asserts": "^1.0.0"
33+
}
2934
}

tests/_data/.gitkeep

Whitespace-only changes.

tests/_output/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

tests/_support/AcceptanceTester.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
4+
/**
5+
* Inherited Methods
6+
* @method void wantToTest($text)
7+
* @method void wantTo($text)
8+
* @method void execute($callable)
9+
* @method void expectTo($prediction)
10+
* @method void expect($prediction)
11+
* @method void amGoingTo($argumentation)
12+
* @method void am($role)
13+
* @method void lookForwardTo($achieveValue)
14+
* @method void comment($description)
15+
* @method void pause()
16+
*
17+
* @SuppressWarnings(PHPMD)
18+
*/
19+
class AcceptanceTester extends \Codeception\Actor
20+
{
21+
use _generated\AcceptanceTesterActions;
22+
23+
/**
24+
* Define custom actions here
25+
*/
26+
}

tests/_support/FunctionalTester.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
4+
/**
5+
* Inherited Methods
6+
* @method void wantToTest($text)
7+
* @method void wantTo($text)
8+
* @method void execute($callable)
9+
* @method void expectTo($prediction)
10+
* @method void expect($prediction)
11+
* @method void amGoingTo($argumentation)
12+
* @method void am($role)
13+
* @method void lookForwardTo($achieveValue)
14+
* @method void comment($description)
15+
* @method void pause()
16+
*
17+
* @SuppressWarnings(PHPMD)
18+
*/
19+
class FunctionalTester extends \Codeception\Actor
20+
{
21+
use _generated\FunctionalTesterActions;
22+
23+
/**
24+
* Define custom actions here
25+
*/
26+
}

tests/_support/Helper/Acceptance.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
namespace Helper;
3+
4+
// here you can define custom actions
5+
// all public methods declared in helper class will be available in $I
6+
7+
class Acceptance extends \Codeception\Module
8+
{
9+
10+
}

tests/_support/Helper/Functional.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
namespace Helper;
3+
4+
// here you can define custom actions
5+
// all public methods declared in helper class will be available in $I
6+
7+
class Functional extends \Codeception\Module
8+
{
9+
10+
}

tests/_support/Helper/Unit.php

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
namespace Helper;
3+
4+
// here you can define custom actions
5+
// all public methods declared in helper class will be available in $I
6+
7+
class Unit extends \Codeception\Module
8+
{
9+
10+
}

tests/_support/UnitTester.php

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
4+
/**
5+
* Inherited Methods
6+
* @method void wantToTest($text)
7+
* @method void wantTo($text)
8+
* @method void execute($callable)
9+
* @method void expectTo($prediction)
10+
* @method void expect($prediction)
11+
* @method void amGoingTo($argumentation)
12+
* @method void am($role)
13+
* @method void lookForwardTo($achieveValue)
14+
* @method void comment($description)
15+
* @method void pause()
16+
*
17+
* @SuppressWarnings(PHPMD)
18+
*/
19+
class UnitTester extends \Codeception\Actor
20+
{
21+
use _generated\UnitTesterActions;
22+
23+
/**
24+
* Define custom actions here
25+
*/
26+
}

tests/_support/_generated/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*
2+
!.gitignore

tests/acceptance.suite.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Codeception Test Suite Configuration
2+
#
3+
# Suite for acceptance tests.
4+
# Perform tests in browser using the WebDriver or PhpBrowser.
5+
# If you need both WebDriver and PHPBrowser tests - create a separate suite.
6+
7+
actor: AcceptanceTester
8+
modules:
9+
enabled:
10+
- PhpBrowser:
11+
url: http://localhost/myapp
12+
- \Helper\Acceptance
13+
step_decorators: ~

tests/acceptance/.gitkeep

Whitespace-only changes.

tests/functional.suite.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Codeception Test Suite Configuration
2+
#
3+
# Suite for functional tests
4+
# Emulate web requests and make application process them
5+
# Include one of framework modules (Symfony2, Yii2, Laravel5, Phalcon4) to use it
6+
# Remove this suite if you don't use frameworks
7+
8+
actor: FunctionalTester
9+
modules:
10+
enabled:
11+
# add a framework module here
12+
- \Helper\Functional
13+
step_decorators: ~

tests/functional/.gitkeep

Whitespace-only changes.

tests/unit.suite.yml

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Codeception Test Suite Configuration
2+
#
3+
# Suite for unit or integration tests.
4+
5+
actor: UnitTester
6+
modules:
7+
enabled:
8+
- Asserts
9+
- \Helper\Unit
10+
step_decorators: ~

tests/unit/ConfigurationTest.php

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
3+
use Codeception\Test\Unit;
4+
use mepihindeveloper\components\Configuration;
5+
6+
class ConfigurationTest extends Unit {
7+
8+
/**
9+
* @var UnitTester
10+
*/
11+
protected $tester;
12+
protected ?Configuration $configuration;
13+
protected array $settings = [
14+
'lang' => 'ru',
15+
'debug' => true,
16+
'database' => [
17+
'host' => 'localhost',
18+
'user' => 'root',
19+
'password' => 123
20+
]
21+
];
22+
23+
public function testGetSettings() {
24+
$this->assertIsArray($this->configuration->getSettings());
25+
}
26+
27+
public function testSetSettings() {
28+
$this->configuration->setSettings(['message' => 'test']);
29+
$this->assertArrayHasKey('message', $this->configuration->getSettings());
30+
}
31+
32+
public function testHasKey() {
33+
$this->assertTrue($this->configuration->hasKey('lang'));
34+
}
35+
36+
public function testHasNotKey() {
37+
$this->assertFalse($this->configuration->hasKey('message'));
38+
}
39+
40+
public function testGetSettingsByKey() {
41+
$this->assertSame('ru', $this->configuration->getSettingsByKey('lang'));
42+
}
43+
44+
public function testGetSettingsByKeyWithException() {
45+
$this->expectException(InvalidArgumentException::class);
46+
$this->configuration->getSettingsByKey('message');
47+
}
48+
49+
protected function _before() {
50+
$this->configuration = new Configuration($this->settings);
51+
}
52+
53+
// tests
54+
55+
protected function _after() {
56+
$this->configuration = null;
57+
}
58+
}

0 commit comments

Comments
 (0)