Skip to content

Commit

Permalink
Merge pull request #408 from dotkernel/issue-234
Browse files Browse the repository at this point in the history
Unit Tests, PSALM & PHPCS integrations
  • Loading branch information
arhimede authored Oct 26, 2023
2 parents 20ccfe5 + 96edb4b commit a4c17ae
Show file tree
Hide file tree
Showing 178 changed files with 5,203 additions and 2,410 deletions.
59 changes: 59 additions & 0 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
on:
- push

name: Run Codecov checks

jobs:
code-coverage:
name: Code Coverage

runs-on: ${{ matrix.os }}

strategy:
matrix:
os:
- ubuntu-latest

php:
- "8.1"
- "8.2"

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
coverage: pcov
ini-values: assert.exception=1, zend.assertions=1, error_reporting=-1, log_errors_max_len=0, display_errors=On
tools: composer:v2, cs2pr

- name: Determine composer cache directory
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v3
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php }}-composer-
- name: Install dependencies with composer
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Setup project
run: |
mv config/autoload/local.php.dist config/autoload/local.php
mv config/autoload/mail.local.php.dist config/autoload/mail.local.php
mv config/autoload/local.test.php.dist config/autoload/local.test.php
- name: Collect code coverage with PHPUnit
run: vendor/bin/phpunit --colors=always --coverage-clover clover.xml

- name: Send code coverage report to Codecov.io
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
47 changes: 47 additions & 0 deletions .github/workflows/cs-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
on:
- push

name: Run phpcs checks

jobs:
mutation:
name: PHP ${{ matrix.php }}-${{ matrix.os }}

runs-on: ${{ matrix.os }}

strategy:
matrix:
os:
- ubuntu-latest

php:
- "8.1"
- "8.2"

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
tools: composer:v2, cs2pr
coverage: none

- name: Determine composer cache directory
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v3
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php }}-composer-
- name: Install dependencies with composer
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run phpcs checks
run: vendor/bin/phpcs
53 changes: 53 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
on:
- push

name: Run PHPUnit tests

jobs:
mutation:
name: PHP ${{ matrix.php }}-${{ matrix.os }}

runs-on: ${{ matrix.os }}

strategy:
matrix:
os:
- ubuntu-latest

php:
- "8.1"
- "8.2"

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php }}"
tools: composer:v2, cs2pr
coverage: none

- name: Determine composer cache directory
run: echo "COMPOSER_CACHE_DIR=$(composer config cache-dir)" >> $GITHUB_ENV

- name: Cache dependencies installed with composer
uses: actions/cache@v3
with:
path: ${{ env.COMPOSER_CACHE_DIR }}
key: php${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: |
php${{ matrix.php }}-composer-
- name: Install dependencies with composer
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Setup project
run: |
mv config/autoload/local.php.dist config/autoload/local.php
mv config/autoload/mail.local.php.dist config/autoload/mail.local.php
mv config/autoload/local.test.php.dist config/autoload/local.test.php
- name: Run unit tests
run: vendor/bin/phpunit --testsuite=UnitTests --testdox --colors=always
6 changes: 3 additions & 3 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
on:
# - pull_request
- push

name: static analysis
Expand All @@ -17,6 +16,7 @@ jobs:

php:
- "8.1"
- "8.2"

steps:
- name: Checkout
Expand All @@ -40,7 +40,7 @@ jobs:
restore-keys: |
php${{ matrix.php }}-composer-
- name: Install dependencies with composer
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi
run: composer install --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Static analysis
run: vendor/bin/psalm --no-cache --output-format=github --show-info=false --threads=4
run: vendor/bin/psalm --no-cache --output-format=github --show-info=false --threads=4 --php-version="${{ matrix.php }}"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,4 @@ package-lock.json

public/uploads/user/*
!public/uploads/user/.gitkeep
config/autoload/local.test.php
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ Dotkernel web starter package suitable for frontend applications.


![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/frontend)

![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/frontend/4.0.0)

[![GitHub issues](https://img.shields.io/github/issues/dotkernel/frontend)](https://github.com/dotkernel/frontend/issues)
[![GitHub forks](https://img.shields.io/github/forks/dotkernel/frontend)](https://github.com/dotkernel/frontend/network)
[![GitHub stars](https://img.shields.io/github/stars/dotkernel/frontend)](https://github.com/dotkernel/frontend/stargazers)
[![GitHub license](https://img.shields.io/github/license/dotkernel/frontend)](https://github.com/dotkernel/frontend/blob/4.0/LICENSE.md)


![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/frontend/4.0.0)

[![Build Static](https://github.com/dotkernel/frontend/actions/workflows/static-analysis.yml/badge.svg?branch=4.0)](https://github.com/dotkernel/frontend/actions/workflows/static-analysis.yml)
[![Build Static](https://github.com/dotkernel/frontend/actions/workflows/run-tests.yml/badge.svg?branch=4.0)](https://github.com/dotkernel/frontend/actions/workflows/run-tests.yml)
[![codecov](https://codecov.io/gh/dotkernel/frontend/graph/badge.svg?token=BQS43UWAM4)](https://codecov.io/gh/dotkernel/frontend)

[![SymfonyInsight](https://insight.symfony.com/projects/a28dac55-3366-4020-9a49-53f6fcbeda4e/big.svg)](https://insight.symfony.com/projects/a28dac55-3366-4020-9a49-53f6fcbeda4e)

Expand Down
16 changes: 12 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"ext-curl": "*",
"ext-gettext": "*",
"ext-json": "*",
"dotkernel/dot-annotated-services": "^4.0",
"dotkernel/dot-annotated-services": "^4.1",
"dotkernel/dot-authorization": "^3.2",
"dotkernel/dot-controller": "^3.2",
"dotkernel/dot-data-fixtures": "^1.0",
Expand All @@ -61,7 +61,7 @@
"dotkernel/dot-session": "^5.2",
"dotkernel/dot-twigrenderer": "^3.2",
"friendsofphp/proxy-manager-lts": "^1.0",
"laminas/laminas-component-installer": "^2.8",
"laminas/laminas-component-installer": "^3.3",
"laminas/laminas-config-aggregator": "^1.8",
"laminas/laminas-form": "^3.13",
"laminas/laminas-i18n": "^2.17",
Expand All @@ -77,10 +77,10 @@
"laminas/laminas-coding-standard": "^2.5",
"laminas/laminas-development-mode": "^3.10",
"mezzio/mezzio-tooling": "^2.6",
"phpunit/phpunit": "^9.5",
"phpunit/phpunit": "^10.3.2",
"rector/rector": "^0.15.18",
"roave/security-advisories": "dev-master",
"vimeo/psalm": "^5.12"
"vimeo/psalm": "^5.15.0"
},
"autoload": {
"psr-4": {
Expand All @@ -91,6 +91,13 @@
"Frontend\\User\\": "src/User/src/"
}
},
"autoload-dev": {
"psr-4": {
"FrontendTest\\Common\\": "test/Common",
"FrontendTest\\Functional\\": "test/Functional/",
"FrontendTest\\Unit\\": "test/Unit"
}
},
"scripts": {
"post-create-project-cmd": [
"@development-enable"
Expand All @@ -107,6 +114,7 @@
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"serve": "php -S 0.0.0.0:8080 -t public/",
"static-analysis": "psalm --shepherd --stats",
"test": "phpunit --colors=always",
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml"
}
Expand Down
4 changes: 2 additions & 2 deletions config/autoload/app.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
declare(strict_types=1);

$app = [
'name' => 'DotKernel frontend V3'
'name' => 'DotKernel frontend V3',
];

return [
'app' => $app
'app' => $app,
];
30 changes: 15 additions & 15 deletions config/autoload/authentication.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,31 @@

declare(strict_types=1);

use Frontend\User\Entity\User;
use Frontend\App\Common\Message;
use Frontend\User\Entity\User;

return [
'doctrine' => [
'authentication' => [
'orm_default' => [
'object_manager' => 'doctrine.entitymanager.orm_default',
'identity_class' => User::class,
'identity_property' => 'identity',
'object_manager' => 'doctrine.entitymanager.orm_default',
'identity_class' => User::class,
'identity_property' => 'identity',
'credential_property' => 'password',
'messages' => [
'success' => 'Authenticated successfully.',
'not_found' => 'Identity not found.',
'messages' => [
'success' => 'Authenticated successfully.',
'not_found' => 'Identity not found.',
'invalid_credential' => 'Invalid credentials.',
],
'options' => [
'status' => [
'value' => User::STATUS_ACTIVE,
'message' => Message::USER_NOT_ACTIVATED
],
'options' => [
'status' => [
'value' => User::STATUS_ACTIVE,
'message' => Message::USER_NOT_ACTIVATED,
],
'isDeleted' => [
'value' => false,
'message' => Message::IS_DELETED
]
'value' => false,
'message' => Message::IS_DELETED,
],
],
],
],
Expand Down
43 changes: 20 additions & 23 deletions config/autoload/authorization-guards.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,40 @@

return [
'dot_authorization' => [
'protection_policy' => GuardInterface::POLICY_ALLOW,

'event_listeners' => [],

'protection_policy' => GuardInterface::POLICY_ALLOW,
'event_listeners' => [],
'guards_provider_manager' => [],
'guard_manager' => [],

'guards_provider' => [
'type' => 'ArrayGuards',
'guard_manager' => [],
'guards_provider' => [
'type' => 'ArrayGuards',
'options' => [
'guards' => [
[
'type' => 'ControllerPermission',
'type' => 'ControllerPermission',
'options' => [
'rules' => [
[
'route' => 'account',
'actions' => [
'route' => 'account',
'actions' => [
'avatar',
'details',
'changePassword',
'deleteAccount'
'deleteAccount',
],
'permissions' => ['authenticated']
'permissions' => ['authenticated'],
],
[
'route' => 'page',
'actions' => [
'premium-content'
'route' => 'page',
'actions' => [
'premium-content',
],
'permissions' => ['premium']
]
'permissions' => ['premium'],
],
],
]
]
]
]
],
],
],
],
],
]
],
];
Loading

0 comments on commit a4c17ae

Please sign in to comment.