Skip to content

Commit b8f0ce8

Browse files
authored
Merge pull request #15 from dotkernel/issue-13
Issue #13: Implemented unit tests, cs-check, static analysis.
2 parents e39a4eb + 1377bf2 commit b8f0ce8

26 files changed

+1041
-212
lines changed

.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-tests.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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
### Composer template
33
composer.phar
44
/vendor/
5+
.phpcs-cache
6+
.phpunit.result.cache
57

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

OSSMETADATA

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
osslifecycle=active
1+
osslifecycle=active

README.md

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,38 @@
11
# dot-cli
22

33
![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/dot-cli)
4-
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-cli/3.2.0)
4+
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/dot-cli/3.4.0)
55

66
[![GitHub issues](https://img.shields.io/github/issues/dotkernel/dot-cli)](https://github.com/dotkernel/dot-cli/issues)
77
[![GitHub forks](https://img.shields.io/github/forks/dotkernel/dot-cli)](https://github.com/dotkernel/dot-cli/network)
88
[![GitHub stars](https://img.shields.io/github/stars/dotkernel/dot-cli)](https://github.com/dotkernel/dot-cli/stargazers)
99
[![GitHub license](https://img.shields.io/github/license/dotkernel/dot-cli)](https://github.com/dotkernel/dot-cli/blob/3.0/LICENSE)
1010

11+
[![Build Static](https://github.com/dotkernel/dot-cli/actions/workflows/static-analysis.yml/badge.svg?branch=3.0)](https://github.com/dotkernel/dot-cli/actions/workflows/static-analysis.yml)
12+
13+
[![SymfonyInsight](https://insight.symfony.com/projects/b9489f03-14e3-441f-aefd-e3b549b4917e/big.svg)](https://insight.symfony.com/projects/b9489f03-14e3-441f-aefd-e3b549b4917e)
14+
1115
DotKernel component to build console applications based on [laminas-cli](https://github.com/laminas/laminas-cli).
1216

1317
### Requirements
14-
- PHP >= 7.4
15-
- laminas/laminas-servicemanager >= 3.6,
16-
- laminas/laminas-cli >= 1.0
18+
- PHP >= 8.1
19+
- laminas/laminas-servicemanager >= 3.11,
20+
- laminas/laminas-cli >= 1.4
1721

1822

1923
### Setup
2024
#### 1. Install package
2125
Run the following command in your application's root directory:
22-
```bash
23-
$ composer require dotkernel/dot-cli
24-
```
26+
27+
composer require dotkernel/dot-cli
2528

2629
#### 2. Register ConfigProvider
27-
Open your application's `config/config.php` and add `Dot\Cli\ConfigProvider::class,` under the _DK packages_ comment.
30+
Open your application's `config/config.php` and the following line under the _DK packages_ comment:
31+
32+
Dot\Cli\ConfigProvider::class,
2833

2934
#### 3. Copy bootstrap file
30-
Locate in this package the following file `bin/cli.php` then copy it to your application's `bin/` directory.
35+
Locate file `bin/cli.php` in this package, then copy it to your application's `bin/` directory.
3136
This is the bootstrap file you will use to execute your commands with.
3237

3338
#### 4. Copy config file
@@ -37,9 +42,9 @@ This is the config file you will add your commands to.
3742

3843
### Testing
3944
Using the command line, go to your application's root directory, then type the following command:
40-
```bash
41-
$ php /bin/cli.php
42-
```
45+
46+
php /bin/cli.php
47+
4348
The output should look similar to this, containing information on how to start using dot-cli:
4449
```text
4550
DotKernel CLI 1.0.0

composer.json

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,42 @@
1717
"email": "[email protected]"
1818
}
1919
],
20+
"config": {
21+
"sort-packages": true,
22+
"allow-plugins": {
23+
"dealerdirect/phpcodesniffer-composer-installer": true
24+
}
25+
},
2026
"require": {
21-
"php": "~7.4.0 || ~8.0.0 || ~8.1.0",
27+
"php": "~8.1.0 || ~8.2.0",
2228
"laminas/laminas-cli": "^1.4.0",
2329
"laminas/laminas-servicemanager": "^3.11.1"
2430
},
25-
"require-dev": {
26-
"phpunit/phpunit": "^9.5",
27-
"squizlabs/php_codesniffer": "^3.5"
28-
},
2931
"autoload": {
3032
"psr-4": {
3133
"Dot\\Cli\\": "src"
3234
}
35+
},
36+
"require-dev": {
37+
"laminas/laminas-coding-standard": "^2.5",
38+
"mikey179/vfsstream": "^1.6",
39+
"phpunit/phpunit": "^10.2",
40+
"vimeo/psalm": "^5.13"
41+
},
42+
"autoload-dev": {
43+
"psr-4": {
44+
"DotTest\\Cli\\": "test/"
45+
}
46+
},
47+
"scripts": {
48+
"check": [
49+
"@cs-check",
50+
"@test"
51+
],
52+
"cs-check": "phpcs",
53+
"cs-fix": "phpcbf",
54+
"test": "phpunit --colors=always",
55+
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
56+
"static-analysis": "psalm --shepherd --stats"
3357
}
3458
}

config/autoload/cli.global.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
use Dot\Cli\Command\DemoCommand;
46
use Dot\Cli\FileLockerInterface;
57

6-
/**
7-
* Documentation: https://docs.laminas.dev/laminas-cli/
8-
*/
98
return [
10-
'dot_cli' => [
11-
'version' => '1.0.0',
12-
'name' => 'DotKernel CLI',
9+
'dot_cli' => [
10+
'version' => '1.0.0',
11+
'name' => 'DotKernel CLI',
1312
'commands' => [
1413
DemoCommand::getDefaultName() => DemoCommand::class,
15-
]
14+
],
1615
],
1716
FileLockerInterface::class => [
1817
'enabled' => true,
1918
'dirPath' => getcwd() . '/data/lock',
20-
]
19+
],
2120
];

phpcs.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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>bin</file>
16+
<file>config</file>
17+
<file>src</file>
18+
<file>test</file>
19+
20+
<!-- Include all rules from the Laminas Coding Standard -->
21+
<rule ref="LaminasCodingStandard"/>
22+
</ruleset>

phpunit.xml

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

0 commit comments

Comments
 (0)