Skip to content

Commit c2692d2

Browse files
authored
Merge pull request #10 from poprazvan17/3.0
implemented phpUnit test, psalm, phpcs and static analysis
2 parents a1baf2a + 8b65398 commit c2692d2

21 files changed

Lines changed: 400 additions & 79 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-tests.yaml

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
@@ -33,3 +33,5 @@ crashlytics.properties
3333
crashlytics-build.properties
3434
fabric.properties
3535
# Created by .ignore support plugin (hsz.mobi)
36+
.phpunit.result.cache
37+
.phpcs-cache

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@
33
Authorization base package defining interfaces for authorization services to be used with DotKernel applications.
44

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

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

13+
[![Build Static](https://github.com/dotkernel/dot-authorization/actions/workflows/static-analysis.yml/badge.svg?branch=3.0)](https://github.com/dotkernel/dot-authorization/actions/workflows/static-analysis.yml)
14+
15+
[![SymfonyInsight](https://insight.symfony.com/projects/014df510-1cf7-4876-b1a8-303fbef2f364/big.svg)](https://insight.symfony.com/projects/014df510-1cf7-4876-b1a8-303fbef2f364)
16+
17+
1318
## Installation
1419

1520
Run the following command in you project directory

composer.json

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@
1616
"laminas-dependency"
1717
],
1818
"require": {
19-
"php": "^7.4 || ~8.0.0 || ~8.1.0"
19+
"php": "~8.1.0 || ~8.2.0"
2020
},
2121
"require-dev": {
22-
"phpunit/phpunit": "^9.1",
23-
"squizlabs/php_codesniffer": "^3.5"
22+
"laminas/laminas-coding-standard": "^2.5",
23+
"phpunit/phpunit": "10.2",
24+
"vimeo/psalm": "^5.13"
2425
},
2526
"autoload": {
2627
"psr-4": {
@@ -33,8 +34,20 @@
3334
}
3435
},
3536
"config": {
37+
"sort-packages": true,
3638
"allow-plugins": {
37-
"laminas/laminas-dependency-plugin": true
39+
"dealerdirect/phpcodesniffer-composer-installer": true
3840
}
41+
},
42+
"scripts": {
43+
"check": [
44+
"@cs-check",
45+
"@test"
46+
],
47+
"cs-check": "phpcs",
48+
"cs-fix": "phpcbf",
49+
"test": "phpunit --colors=always",
50+
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
51+
"static-analysis": "psalm --shepherd --stats"
3952
}
4053
}

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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
4+
bootstrap="vendor/autoload.php">
5+
<testsuites>
6+
<testsuite name="Dot Authorization Test Suite">
7+
<directory>./test</directory>
8+
</testsuite>
9+
</testsuites>
10+
</phpunit>

psalm.xml

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

src/AuthorizationInterface.php

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

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

105
namespace Dot\Authorization;
116

12-
/**
13-
* Interface AuthorizationInterface
14-
* @package Dot\Authorization
15-
*/
167
interface AuthorizationInterface
178
{
18-
/**
19-
* @param string $permission
20-
* @param array $roles
21-
* @param mixed|null $context
22-
* @return bool
23-
*/
24-
public function isGranted(string $permission, array $roles = [], $context = null): bool;
9+
public function isGranted(string $permission, array $roles = [], mixed $context = null): bool;
2510
}

0 commit comments

Comments
 (0)