Skip to content

Commit 004c4d5

Browse files
author
Andrei Onita
committed
implemented psalm, cs-check, static analysis & added tests
1 parent 032b1f3 commit 004c4d5

28 files changed

Lines changed: 369 additions & 296 deletions

.github/workflows/cs-tests.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
on:
2+
- push
3+
4+
name: Run phpcs checks
5+
6+
jobs:
7+
mutation:
8+
name: PHP ${{ matrix.php }}-${{ matrix.os }}
9+
10+
runs-on: ${{ matrix.os }}
11+
12+
strategy:
13+
matrix:
14+
os:
15+
- ubuntu-latest
16+
17+
php:
18+
- "8.1"
19+
- "8.2"
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v3
24+
25+
- name: Install PHP
26+
uses: shivammathur/setup-php@v2
27+
with:
28+
php-version: "${{ matrix.php }}"
29+
tools: composer:v2, cs2pr
30+
coverage: none
31+
32+
- name: Determine composer cache directory
33+
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV
34+
35+
- name: Cache dependencies installed with composer
36+
uses: actions/cache@v3
37+
with:
38+
path: ${{ env.COMPOSER_CACHE_DIR }}
39+
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
40+
restore-keys: |
41+
php${{ matrix.php }}-composer-
42+
- name: Install dependencies with composer
43+
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
44+
45+
- name: Run phpcs checks
46+
run: vendor/bin/phpcs
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
on:
2+
- push
3+
4+
name: Run static analysis
5+
6+
jobs:
7+
mutation:
8+
name: PHP ${{ matrix.php }}-${{ matrix.os }}
9+
10+
runs-on: ${{ matrix.os }}
11+
12+
strategy:
13+
matrix:
14+
os:
15+
- ubuntu-latest
16+
17+
php:
18+
- "8.1"
19+
- "8.2"
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v3
24+
25+
- name: Install PHP
26+
uses: shivammathur/setup-php@v2
27+
with:
28+
php-version: "${{ matrix.php }}"
29+
tools: composer:v2, cs2pr
30+
coverage: none
31+
32+
- name: Determine composer cache directory
33+
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV
34+
35+
- name: Cache dependencies installed with composer
36+
uses: actions/cache@v3
37+
with:
38+
path: ${{ env.COMPOSER_CACHE_DIR }}
39+
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
40+
restore-keys: |
41+
php${{ matrix.php }}-composer-
42+
- name: Install dependencies with composer
43+
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
44+
45+
- name: Run static analysis
46+
run: vendor/bin/psalm --no-cache --output-format=github --show-info=false --threads=4

.github/workflows/unit-test.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
on:
2+
- push
3+
4+
name: Run PHPUnit tests
5+
6+
jobs:
7+
mutation:
8+
name: PHP ${{ matrix.php }}-${{ matrix.os }}
9+
10+
runs-on: ${{ matrix.os }}
11+
12+
strategy:
13+
matrix:
14+
os:
15+
- ubuntu-latest
16+
17+
php:
18+
- "8.1"
19+
- "8.2"
20+
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v3
24+
25+
- name: Install PHP
26+
uses: shivammathur/setup-php@v2
27+
with:
28+
php-version: "${{ matrix.php }}"
29+
tools: composer:v2, cs2pr
30+
coverage: none
31+
32+
- name: Determine composer cache directory
33+
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV
34+
35+
- name: Cache dependencies installed with composer
36+
uses: actions/cache@v3
37+
with:
38+
path: ${{ env.COMPOSER_CACHE_DIR }}
39+
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
40+
restore-keys: |
41+
php${{ matrix.php }}-composer-
42+
43+
- name: Install dependencies with composer
44+
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
45+
46+
- name: Run PHPUnit tests
47+
run: vendor/bin/phpunit --colors=always

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
clover.xml
22
coveralls-upload.json
3-
phpunit.xml
3+
.phpunit.result.cache
4+
.phpcs-cache
45

56
# Created by .ignore support plugin (hsz.mobi)
67
### JetBrains template
@@ -36,4 +37,4 @@ composer.phar
3637

3738
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
3839
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
39-
composer.lock
40+
composer.lock

composer.json

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,17 @@
1818
}
1919
],
2020
"require": {
21-
"php": "^7.4 || ~8.0.0 || ~8.1.0",
21+
"php": "~8.1.0 || ~8.2.0",
2222
"psr/http-message": "^1.0.1",
2323
"laminas/laminas-servicemanager": "^3.11.2",
2424
"dotkernel/dot-event": "^3.2.0"
2525
},
2626
"require-dev": {
2727
"mezzio/mezzio-template": "^2.4.0",
2828
"mezzio/mezzio-helpers": "^5.8.0",
29-
"phpunit/phpunit": "^9.5.20",
30-
"squizlabs/php_codesniffer": "^3.6.2"
29+
"phpunit/phpunit": "^10.2",
30+
"vimeo/psalm": "^5.13",
31+
"laminas/laminas-coding-standard": "^2.5"
3132
},
3233
"autoload": {
3334
"psr-4": {
@@ -38,5 +39,21 @@
3839
"psr-4": {
3940
"DotTest\\Controller\\": "test/"
4041
}
42+
},
43+
"scripts": {
44+
"check": [
45+
"@cs-check",
46+
"@test"
47+
],
48+
"cs-check": "phpcs",
49+
"cs-fix": "phpcbf",
50+
"test": "phpunit --colors=always",
51+
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
52+
"static-analysis": "psalm --shepherd --stats"
53+
},
54+
"config": {
55+
"allow-plugins": {
56+
"dealerdirect/phpcodesniffer-composer-installer": true
57+
}
4158
}
4259
}

phpcs.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
4+
5+
<arg name="basepath" value="."/>
6+
<arg name="cache" value=".phpcs-cache"/>
7+
<arg name="colors"/>
8+
<arg name="extensions" value="php"/>
9+
<arg name="parallel" value="80"/>
10+
11+
<!-- Show progress -->
12+
<arg value="p"/>
13+
14+
<!-- Paths to check -->
15+
<file>src</file>
16+
<file>test</file>
17+
18+
<!-- Include all rules from the Laminas Coding Standard -->
19+
<rule ref="LaminasCodingStandard"/>
20+
</ruleset>

phpunit.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.2/phpunit.xsd" bootstrap="./vendor/autoload.php" colors="true">
3+
<testsuites>
4+
<testsuite name="dot-controller Test Suite">
5+
<directory>./test</directory>
6+
</testsuite>
7+
</testsuites>
8+
<coverage/>
9+
<source>
10+
<include>
11+
<directory suffix=".php">./src</directory>
12+
</include>
13+
</source>
14+
</phpunit>

psalm.xml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="4"
4+
resolveFromConfigFile="true"
5+
findUnusedCode="false"
6+
findUnusedBaselineEntry="true"
7+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
8+
xmlns="https://getpsalm.org/schema/config"
9+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
10+
>
11+
<projectFiles>
12+
<directory name="src" />
13+
<ignoreFiles>
14+
<directory name="vendor" />
15+
</ignoreFiles>
16+
</projectFiles>
17+
</psalm>

src/AbstractActionController.php

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
<?php
2-
/**
3-
* @see https://github.com/dotkernel/dot-controller/ for the canonical source repository
4-
* @copyright Copyright (c) 2017 Apidemia (https://www.apidemia.com)
5-
* @license https://github.com/dotkernel/dot-controller/blob/master/LICENSE.md MIT License
6-
*/
72

8-
declare(strict_types = 1);
3+
declare(strict_types=1);
94

105
namespace Dot\Controller;
116

127
use Dot\Controller\Event\ControllerEvent;
138
use Psr\Http\Message\ResponseInterface;
149

15-
/**
16-
* Class AbstractActionController
17-
* @package Dot\Controller
18-
*/
10+
use function array_merge;
11+
use function method_exists;
12+
use function strtolower;
13+
use function trim;
14+
1915
abstract class AbstractActionController extends AbstractController
2016
{
21-
/**
22-
* @return ResponseInterface
23-
*/
2417
public function dispatch(): ResponseInterface
2518
{
2619
$action = strtolower(trim($this->request->getAttribute('action', 'index')));
@@ -32,18 +25,18 @@ public function dispatch(): ResponseInterface
3225

3326
if (method_exists($this, $action)) {
3427
$r = $this->dispatchEvent(ControllerEvent::EVENT_CONTROLLER_BEFORE_DISPATCH, [
35-
'request' => $this->request,
36-
'handler' => $this->getHandler(),
28+
'request' => $this->request,
29+
'handler' => $this->getHandler(),
3730
'controller' => $this,
38-
'method' => $action
31+
'method' => $action,
3932
]);
4033
if ($r instanceof ResponseInterface) {
4134
return $r;
4235
}
4336

4437
$this->request = $r->getParam('request');
45-
$response = $this->$action();
46-
$params = array_merge($r->getParams(), ['response' => $response]);
38+
$response = $this->$action();
39+
$params = array_merge($r->getParams(), ['response' => $response]);
4740

4841
$r = $this->dispatchEvent(ControllerEvent::EVENT_CONTROLLER_AFTER_DISPATCH, $params);
4942
if ($r instanceof ResponseInterface) {

0 commit comments

Comments
 (0)