Skip to content

Commit 8b41792

Browse files
authored
Integrate Slim v3 and Codeception v4 (v1.0.0)
* Init library * Tests with coverage * Integration with phpstan * Integration with php-cs-fixer * Added CI workflow * Added static analysis workflow
1 parent 4d804c0 commit 8b41792

18 files changed

+857
-0
lines changed

.editorconfig

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# EditorConfig is awesome: https://editorconfig.org/
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
# Unix-style newlines with a newline ending for every file
7+
# Indent with 4 spaces
8+
[*]
9+
charset = utf-8
10+
end_of_line = lf
11+
indent_style = space
12+
indent_size = 4
13+
insert_final_newline = true
14+
trim_trailing_whitespace = true
15+
16+
[Makefile]
17+
indent_style = tab
18+
19+
[*.yml]
20+
indent_size = 2

.github/workflows/ci.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: CI
2+
3+
on: [ push, pull_request ]
4+
5+
jobs:
6+
build:
7+
name: Build
8+
runs-on: ubuntu-latest
9+
strategy:
10+
max-parallel: 10
11+
matrix:
12+
php: [ '7.2', '7.3', '7.4' ]
13+
14+
steps:
15+
- name: Set up PHP
16+
uses: shivammathur/setup-php@v2
17+
with:
18+
php-version: ${{ matrix.php }}
19+
coverage: none
20+
tools: composer:v2
21+
22+
- name: Checkout code
23+
uses: actions/checkout@v2
24+
25+
- name: Download dependencies
26+
run: composer update --no-interaction --prefer-dist
27+
28+
- name: Run tests
29+
run: make test

.github/workflows/static-analysis.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Static analysis
2+
3+
on: [ push, pull_request ]
4+
5+
jobs:
6+
phpstan:
7+
name: PHPStan
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v2
13+
14+
- name: PHPStan
15+
uses: docker://oskarstark/phpstan-ga:0.12.41
16+
env:
17+
REQUIRE_DEV: true
18+
with:
19+
args: analyze --no-progress
20+
21+
php-cs-fixer:
22+
name: PHP-CS-Fixer
23+
runs-on: ubuntu-latest
24+
25+
steps:
26+
- name: Checkout code
27+
uses: actions/checkout@v2
28+
29+
- name: PHP-CS-Fixer
30+
uses: docker://oskarstark/php-cs-fixer-ga:2.16.4
31+
with:
32+
args: --dry-run --diff-format udiff

.gitignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Files
2+
.php_cs
3+
.php_cs.cache
4+
/composer.lock
5+
/phpstan.neon
6+
!/test/output/.gitkeep
7+
8+
# Directories
9+
/test/output/*
10+
/test/support/_generated
11+
/vendor

.php_cs.dist

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<?php
2+
3+
return PhpCsFixer\Config::create()
4+
->setRiskyAllowed(true)
5+
->setRules(
6+
[
7+
'@PSR2' => true,
8+
'array_syntax' => ['syntax' => 'short'],
9+
'binary_operator_spaces' => [
10+
'default' => 'align_single_space_minimal',
11+
],
12+
'blank_line_before_statement' => [
13+
'statements' => ['break', 'continue', 'return', 'try'],
14+
],
15+
'braces' => [
16+
'allow_single_line_closure' => true,
17+
],
18+
'class_attributes_separation' => [
19+
'elements' => ['const', 'property', 'method'],
20+
],
21+
'declare_strict_types' => true,
22+
'no_alternative_syntax' => true,
23+
'no_leading_import_slash' => true,
24+
'no_multiline_whitespace_before_semicolons' => true,
25+
'no_short_echo_tag' => true,
26+
'no_spaces_inside_parenthesis' => true,
27+
'no_useless_else' => true,
28+
'not_operator_with_space' => false,
29+
'not_operator_with_successor_space' => false,
30+
'ordered_imports' => true,
31+
'phpdoc_add_missing_param_annotation' => true,
32+
'phpdoc_align' => [
33+
'align' => 'vertical',
34+
],
35+
'phpdoc_indent' => true,
36+
'phpdoc_no_package' => true,
37+
'phpdoc_order' => true,
38+
'phpdoc_scalar' => [
39+
'types' => ['boolean', 'double', 'integer', 'real', 'str'],
40+
],
41+
'phpdoc_separation' => true,
42+
'phpdoc_single_line_var_spacing' => true,
43+
'phpdoc_to_comment' => true,
44+
'phpdoc_trim' => true,
45+
'phpdoc_var_without_name' => true,
46+
'return_type_declaration' => [
47+
'space_before' => 'none',
48+
],
49+
'single_quote' => true,
50+
'ternary_operator_spaces' => true,
51+
'trailing_comma_in_multiline_array' => true,
52+
'trim_array_spaces' => true,
53+
'single_line_after_imports' => true,
54+
'unary_operator_spaces' => true,
55+
'visibility_required' => true,
56+
'yoda_style' => false,
57+
]
58+
)
59+
->setIndent(' ')
60+
->setUsingCache(false)
61+
->setFinder(
62+
PhpCsFixer\Finder::create()
63+
->in(__DIR__.'/src')
64+
->in(__DIR__.'/test')
65+
->name('*.php')
66+
);

Makefile

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
help:
2+
@echo "Please use \`make <target>' where <target> is one of"
3+
@echo " test to perform tests."
4+
@echo " coverage to perform tests with code coverage."
5+
@echo " static to run phpstan and php-cs-fixer check."
6+
@echo " static-phpstan to run phpstan."
7+
@echo " static-cs-check to run php-cs-fixer."
8+
@echo " static-cs-fix to run php-cs-fixer, writing the changes."
9+
10+
.PHONY: test
11+
test:
12+
vendor/bin/codecept build
13+
vendor/bin/codecept run
14+
15+
.PHONY: coverage
16+
coverage:
17+
vendor/bin/codecept build
18+
vendor/bin/codecept run --coverage --coverage-xml --coverage-html
19+
20+
.PHONY: static
21+
static: static-phpstan static-cs-check
22+
23+
static-phpstan:
24+
docker run --rm -it -e REQUIRE_DEV=true -v ${PWD}:/app -w /app oskarstark/phpstan-ga:0.12.41 analyze $(PHPSTAN_PARAMS)
25+
26+
static-cs-fix:
27+
docker run --rm -it -v ${PWD}:/app -w /app oskarstark/php-cs-fixer-ga:2.16.4 --diff-format udiff $(CS_PARAMS)
28+
29+
static-cs-check:
30+
$(MAKE) static-cs-fix CS_PARAMS="--dry-run"

README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# DoclerLabs - Codeception Slim Module
2+
3+
[![Build Status](https://img.shields.io/github/workflow/status/DoclerLabs/codeception-slim-module/CI?label=build&style=flat-square)](https://github.com/DoclerLabs/codeception-slim-module/actions?query=workflow%3ACI)
4+
[![PHPStan Level](https://img.shields.io/badge/PHPStan-level%208-brightgreen.svg?style=flat-square)](https://img.shields.io/badge/PHPStan-level%208-brightgreen.svg)
5+
6+
This module allows you to run functional tests inside [Slim 3 Microframework](http://www.slimframework.com/docs/v3/) without HTTP calls,
7+
so tests will be much faster and debug could be easier.
8+
9+
Inspiration comes from [herloct/codeception-slim-module](https://github.com/herloct/codeception-slim-module) library.
10+
11+
## Install
12+
13+
### Minimal requirements
14+
- php: `^7.2`
15+
- slim/slim: `^3.1`
16+
- codeception/codeception: `^4.0`
17+
18+
If you don't know Codeception, please check [Quickstart Guide](https://codeception.com/quickstart) first.
19+
20+
If you already have [Codeception](https://github.com/Codeception/Codeception) installed in your Slim application,
21+
you can add codeception-slim-module with a single composer command.
22+
23+
```shell
24+
composer require --dev docler-labs/codeception-slim-module
25+
```
26+
27+
### Configuration
28+
29+
**Example (`test/suite/functional.suite.yml`)**
30+
```yaml
31+
modules:
32+
enabled:
33+
- DoclerLabs\CodeceptionSlimModule\Module\Slim:
34+
application: path/to/application.php
35+
- REST:
36+
depends: DoclerLabs\CodeceptionSlimModule\Module\Slim
37+
```
38+
39+
The `application` property is a relative path to file which returns your `Slim\App` instance.
40+
Here is the minimum `application.php` content:
41+
42+
```php
43+
require __DIR__ . '/vendor/autoload.php';
44+
45+
use Slim\App;
46+
47+
$app = new App();
48+
49+
// Add routes and middlewares here.
50+
51+
return $app;
52+
```
53+
54+
## Testing your API endpoints
55+
56+
```php
57+
58+
class UserCest
59+
{
60+
public function getUserReturnsWithEmail(FunctionalTester $I): void
61+
{
62+
$I->haveHttpHeader('Content-Type', 'application/json');
63+
64+
$I->sendGET('/users/John');
65+
66+
$I->seeResponseCodeIs(200);
67+
$I->seeResponseContainsJson(
68+
[
69+
'email' => 'john.doe@example.com',
70+
]
71+
);
72+
}
73+
}
74+
```

codeception.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace: DoclerLabs\CodeceptionSlimModule\Test
2+
actor: Tester
3+
paths:
4+
tests: test/suite
5+
log: test/output
6+
output: test/output
7+
data: test/data
8+
support: test/support
9+
extensions:
10+
enabled:
11+
- Codeception\Extension\RunFailed
12+
coverage:
13+
enabled: true
14+
include:
15+
- src/*php

composer.json

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "docler-labs/codeception-slim-module",
3+
"description": "Codeception Module for Slim framework.",
4+
"keywords": [
5+
"codeception",
6+
"module",
7+
"slim"
8+
],
9+
"type": "library",
10+
"license": "MIT",
11+
"require": {
12+
"php": "^7.2",
13+
"codeception/codeception": "^4.0",
14+
"codeception/lib-innerbrowser": "^1.0",
15+
"slim/slim": "^3.1"
16+
},
17+
"require-dev": {
18+
"ext-json": "*",
19+
"codeception/module-asserts": "^1.2",
20+
"codeception/module-rest": "^1.2"
21+
},
22+
"autoload": {
23+
"psr-4": {
24+
"DoclerLabs\\CodeceptionSlimModule\\": "src"
25+
}
26+
},
27+
"autoload-dev": {
28+
"psr-4": {
29+
"DoclerLabs\\CodeceptionSlimModule\\Test\\": "test/support",
30+
"DoclerLabs\\CodeceptionSlimModule\\Test\\Functional\\": "test/suite/functional"
31+
}
32+
},
33+
"config": {
34+
"sort-packages": true
35+
}
36+
}

phpstan.neon.dist

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parameters:
2+
level: max
3+
checkMissingIterableValueType: false
4+
paths:
5+
- src
6+
fileExtensions:
7+
- php

0 commit comments

Comments
 (0)