Skip to content

Commit

Permalink
Merge pull request #10 from poprazvan17/3.0
Browse files Browse the repository at this point in the history
implemented phpUnit test, psalm, phpcs and static analysis
  • Loading branch information
arhimede authored Jul 25, 2023
2 parents a1baf2a + 8b65398 commit c2692d2
Show file tree
Hide file tree
Showing 21 changed files with 400 additions and 79 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/cs-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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 update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

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

name: Run static analysis

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 update --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Run static analysis
run: vendor/bin/psalm --no-cache --output-format=github --show-info=false --threads=4
47 changes: 47 additions & 0 deletions .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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: Run PHPUnit tests
run: vendor/bin/phpunit --colors=always
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ crashlytics.properties
crashlytics-build.properties
fabric.properties
# Created by .ignore support plugin (hsz.mobi)
.phpunit.result.cache
.phpcs-cache
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
Authorization base package defining interfaces for authorization services to be used with DotKernel applications.

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

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

[![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)

[![SymfonyInsight](https://insight.symfony.com/projects/014df510-1cf7-4876-b1a8-303fbef2f364/big.svg)](https://insight.symfony.com/projects/014df510-1cf7-4876-b1a8-303fbef2f364)


## Installation

Run the following command in you project directory
Expand Down
21 changes: 17 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@
"laminas-dependency"
],
"require": {
"php": "^7.4 || ~8.0.0 || ~8.1.0"
"php": "~8.1.0 || ~8.2.0"
},
"require-dev": {
"phpunit/phpunit": "^9.1",
"squizlabs/php_codesniffer": "^3.5"
"laminas/laminas-coding-standard": "^2.5",
"phpunit/phpunit": "10.2",
"vimeo/psalm": "^5.13"
},
"autoload": {
"psr-4": {
Expand All @@ -33,8 +34,20 @@
}
},
"config": {
"sort-packages": true,
"allow-plugins": {
"laminas/laminas-dependency-plugin": true
"dealerdirect/phpcodesniffer-composer-installer": true
}
},
"scripts": {
"check": [
"@cs-check",
"@test"
],
"cs-check": "phpcs",
"cs-fix": "phpcbf",
"test": "phpunit --colors=always",
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
"static-analysis": "psalm --shepherd --stats"
}
}
20 changes: 20 additions & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0"?>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

<arg name="basepath" value="."/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="80"/>

<!-- Show progress -->
<arg value="p"/>

<!-- Paths to check -->
<file>src</file>
<file>test</file>

<!-- Include all rules from the Laminas Coding Standard -->
<rule ref="LaminasCodingStandard"/>
</ruleset>
10 changes: 10 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="Dot Authorization Test Suite">
<directory>./test</directory>
</testsuite>
</testsuites>
</phpunit>
15 changes: 15 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
findUnusedBaselineEntry="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
</psalm>
19 changes: 2 additions & 17 deletions src/AuthorizationInterface.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,10 @@
<?php
/**
* @see https://github.com/dotkernel/dot-authorization/ for the canonical source repository
* @copyright Copyright (c) 2017 Apidemia (https://www.apidemia.com)
* @license https://github.com/dotkernel/dot-authorization/blob/master/LICENSE.md MIT License
*/

declare(strict_types = 1);
declare(strict_types=1);

namespace Dot\Authorization;

/**
* Interface AuthorizationInterface
* @package Dot\Authorization
*/
interface AuthorizationInterface
{
/**
* @param string $permission
* @param array $roles
* @param mixed|null $context
* @return bool
*/
public function isGranted(string $permission, array $roles = [], $context = null): bool;
public function isGranted(string $permission, array $roles = [], mixed $context = null): bool;
}
12 changes: 1 addition & 11 deletions src/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
<?php
/**
* @see https://github.com/dotkernel/dot-authorization/ for the canonical source repository
* @copyright Copyright (c) 2017 Apidemia (https://www.apidemia.com)
* @license https://github.com/dotkernel/dot-authorization/blob/master/LICENSE.md MIT License
*/

declare(strict_types = 1);
declare(strict_types=1);

namespace Dot\Authorization\Exception;

/**
* Interface ExceptionInterface
* @package Dot\Authorization\Exception
*/
interface ExceptionInterface
{

}
15 changes: 3 additions & 12 deletions src/Exception/ForbiddenException.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
<?php
/**
* @see https://github.com/dotkernel/dot-authorization/ for the canonical source repository
* @copyright Copyright (c) 2017 Apidemia (https://www.apidemia.com)
* @license https://github.com/dotkernel/dot-authorization/blob/master/LICENSE.md MIT License
*/

declare(strict_types = 1);
declare(strict_types=1);

namespace Dot\Authorization\Exception;

use Exception;

/**
* Class ForbiddenException
* @package Dot\Authorization\Exception
*/
class ForbiddenException extends \Exception implements ExceptionInterface
class ForbiddenException extends Exception implements ExceptionInterface
{
public function __construct($message = "", $code = 403, Exception $previous = null)
public function __construct(string $message = "", int $code = 403, ?Exception $previous = null)
{
parent::__construct($message, $code, $previous);
}
Expand Down
12 changes: 1 addition & 11 deletions src/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
<?php
/**
* @see https://github.com/dotkernel/dot-authorization/ for the canonical source repository
* @copyright Copyright (c) 2017 Apidemia (https://www.apidemia.com)
* @license https://github.com/dotkernel/dot-authorization/blob/master/LICENSE.md MIT License
*/

declare(strict_types = 1);
declare(strict_types=1);

namespace Dot\Authorization\Exception;

/**
* Class RuntimeException
* @package Dot\Authorization\Exception
*/
class RuntimeException extends \RuntimeException implements ExceptionInterface
{

}
11 changes: 1 addition & 10 deletions src/Identity/IdentityInterface.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
<?php
/**
* @see https://github.com/dotkernel/dot-authorization/ for the canonical source repository
* @copyright Copyright (c) 2017 Apidemia (https://www.apidemia.com)
* @license https://github.com/dotkernel/dot-authorization/blob/master/LICENSE.md MIT License
*/

declare(strict_types = 1);
declare(strict_types=1);

namespace Dot\Authorization\Identity;

use Dot\Authorization\Role\RoleInterface;

/**
* Interface IdentityInterface
* @package Dot\Authorization\Identity
*/
interface IdentityInterface
{
/**
Expand Down
14 changes: 1 addition & 13 deletions src/Role/RoleInterface.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,10 @@
<?php
/**
* @see https://github.com/dotkernel/dot-authorization/ for the canonical source repository
* @copyright Copyright (c) 2017 Apidemia (https://www.apidemia.com)
* @license https://github.com/dotkernel/dot-authorization/blob/master/LICENSE.md MIT License
*/

declare(strict_types = 1);
declare(strict_types=1);

namespace Dot\Authorization\Role;

/**
* Interface RoleInterface
* @package Dot\Authorization\Role
*/
interface RoleInterface
{
/**
* @return string
*/
public function getName(): string;
}
Loading

0 comments on commit c2692d2

Please sign in to comment.