Skip to content

Commit

Permalink
Merge pull request #3 from Orkin/feature/update-php-8-1
Browse files Browse the repository at this point in the history
update to php 8.1
  • Loading branch information
neeckeloo authored Jun 9, 2022
2 parents e33e2bf + 21a6618 commit e69cb4b
Show file tree
Hide file tree
Showing 18 changed files with 153 additions and 33 deletions.
54 changes: 54 additions & 0 deletions .github/workflow/pr_open.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Pull Request - Open

on:
pull_request:
types: [opened, reopened, synchronize]

jobs:
phpcs:
name: Specification style formatting
runs-on: 'ubuntu-latest'
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Run php cs fixer
run: 'make test-phpcs'
phpunit:
name: (PHP ${{ matrix.php-versions }} on ${{ matrix.command-to-launch.name }})
runs-on: 'ubuntu-latest'
strategy:
matrix:
command-to-launch: [
{
name: 'psalm',
command: 'psalm',
},
{
name: 'Unit tests',
command: 'vendor/bin/phpunit --coverage-text',
}
]
php-versions: [ '8.1' ]
phpunit-versions: [ 'latest' ]
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
tools: vimeo/psalm, phpunit
coverage: xdebug
- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
- name: Cache composer dependencies
uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: ${{ runner.os }}-composer-
- name: Install Composer dependencies
run: composer install --no-progress --prefer-dist --optimize-autoloader
- name: Run test
run: ${{matrix.command-to-launch.command}}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@
/composer.phar
/composer.lock
php-cs-fixer
.phpunit.result.cache
.php-cs-fixer.cache
29 changes: 29 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

$finder = PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude('config')
->exclude('var')
->notPath('bin/console')
->notPath('public/index.php');

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'date_time_immutable' => true,
'linebreak_after_opening_tag' => true,
'mb_str_functions' => true,
'no_php4_constructor' => true,
'no_unreachable_default_argument_value' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'php_unit_strict' => false,
'phpdoc_order' => true,
'strict_comparison' => true,
'strict_param' => true,
'concat_space' => ['spacing' => 'one'],
'ordered_imports' => ['imports_order' => ['class', 'function', 'const'], 'sort_algorithm' => 'alpha'],
])
->setFinder($finder);
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test-phpcs:
docker run --rm --platform linux/amd64 -v $(PWD):/data cytopia/php-cs-fixer fix --dry-run --diff src
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
"description": "Implementation of the specification pattern in PHP",
"homepage": "https://github.com/RiskioFr/Specification",
"require": {
"php": "^7.0"
"php": "^8.1"
},
"require-dev": {
"phpunit/phpunit": "~5.3"
"phpunit/phpunit": "^9.5",
"vimeo/psalm": "^4.22"
},
"autoload": {
"psr-4": {
Expand Down
9 changes: 4 additions & 5 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,16 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./vendor/autoload.php">
<testsuites>
<testsuite name="Specification Test Suite">
<directory>./tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
</include>
</coverage>
</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="2"
resolveFromConfigFile="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>
9 changes: 6 additions & 3 deletions src/AndSpecification.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
<?php

declare(strict_types=1);

namespace Riskio\Specification;

class AndSpecification extends CompositeSpecification
{
protected $specifications;
protected array $specifications;

public function __construct(SpecificationInterface ...$specifications)
{
$this->specifications = $specifications;
}

public function isSatisfiedBy($object) : bool
public function isSatisfiedBy(mixed $object): bool
{
foreach ($this->specifications as $specification) {
if (! $specification->isSatisfiedBy($object)) {
if (!$specification->isSatisfiedBy($object)) {
return false;
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/CompositeSpecification.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php

declare(strict_types=1);

namespace Riskio\Specification;

abstract class CompositeSpecification implements SpecificationInterface
{
abstract public function isSatisfiedBy($object) : bool;
abstract public function isSatisfiedBy(mixed $object): bool;
}
5 changes: 4 additions & 1 deletion src/LeafSpecification.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php

declare(strict_types=1);

namespace Riskio\Specification;

abstract class LeafSpecification implements SpecificationInterface
{
abstract public function isSatisfiedBy($object) : bool;
abstract public function isSatisfiedBy(mixed $object): bool;
}
10 changes: 5 additions & 5 deletions src/NotSpecification.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?php

declare(strict_types=1);

namespace Riskio\Specification;

class NotSpecification implements SpecificationInterface
{
protected $specification;

public function __construct(SpecificationInterface $specification)
public function __construct(protected readonly SpecificationInterface $specification)
{
$this->specification = $specification;
}

public function isSatisfiedBy($object) : bool
public function isSatisfiedBy(mixed $object): bool
{
return !$this->specification->isSatisfiedBy($object);
}
Expand Down
7 changes: 5 additions & 2 deletions src/OrSpecification.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
<?php

declare(strict_types=1);

namespace Riskio\Specification;

class OrSpecification extends CompositeSpecification
{
protected $specifications;
protected array $specifications;

public function __construct(SpecificationInterface ...$specifications)
{
$this->specifications = $specifications;
}

public function isSatisfiedBy($object) : bool
public function isSatisfiedBy(mixed $object): bool
{
foreach ($this->specifications as $specification) {
if ($specification->isSatisfiedBy($object)) {
Expand Down
5 changes: 4 additions & 1 deletion src/SpecificationInterface.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php

declare(strict_types=1);

namespace Riskio\Specification;

interface SpecificationInterface
{
public function isSatisfiedBy($object) : bool;
public function isSatisfiedBy(mixed $object): bool;
}
9 changes: 5 additions & 4 deletions tests/AndSpecificationTest.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?php
namespace Riskio\SpecificationTest;

use PHPUnit\Framework\TestCase;
use Riskio\Specification\AndSpecification;
use Riskio\SpecificationTest\Fixtures\NotSatisfiedSpecification;
use Riskio\SpecificationTest\Fixtures\SatisfiedSpecification;

class AndSpecificationTest extends \PHPUnit_Framework_TestCase
class AndSpecificationTest extends TestCase
{
/**
* @test
*/
public function isSatisfiedBy_GivenBothSpecificationsSatisfied_ShouldReturnTrue()
public function isSatisfiedBy_GivenBothSpecificationsSatisfied_ShouldReturnTrue(): void
{
$spec = new AndSpecification(
new SatisfiedSpecification(),
Expand All @@ -25,7 +26,7 @@ public function isSatisfiedBy_GivenBothSpecificationsSatisfied_ShouldReturnTrue(
/**
* @test
*/
public function isSatisfiedBy_GivenOneSpecificationNotSatisfied_ShouldReturnFalse()
public function isSatisfiedBy_GivenOneSpecificationNotSatisfied_ShouldReturnFalse(): void
{
$spec = new AndSpecification(
new SatisfiedSpecification(),
Expand All @@ -41,7 +42,7 @@ public function isSatisfiedBy_GivenOneSpecificationNotSatisfied_ShouldReturnFals
/**
* @test
*/
public function isSatisfiedBy_GivenBothSpecificationsNotSatisfied_ShouldReturnFalse()
public function isSatisfiedBy_GivenBothSpecificationsNotSatisfied_ShouldReturnFalse(): void
{
$spec = new AndSpecification(
new NotSatisfiedSpecification(),
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/NotSatisfiedSpecification.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class NotSatisfiedSpecification implements SpecificationInterface
{
public function isSatisfiedBy($object) : bool
public function isSatisfiedBy(mixed $object): bool
{
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Fixtures/SatisfiedSpecification.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class SatisfiedSpecification implements SpecificationInterface
{
public function isSatisfiedBy($object) : bool
public function isSatisfiedBy(mixed $object): bool
{
return true;
}
Expand Down
7 changes: 4 additions & 3 deletions tests/NotSpecificationTest.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?php
namespace Riskio\SpecificationTest;

use PHPUnit\Framework\TestCase;
use Riskio\Specification\NotSpecification;
use Riskio\SpecificationTest\Fixtures\NotSatisfiedSpecification;
use Riskio\SpecificationTest\Fixtures\SatisfiedSpecification;

class NotSpecificationTest extends \PHPUnit_Framework_TestCase
class NotSpecificationTest extends TestCase
{
/**
* @test
*/
public function isSatisfiedBy_GivenSpecificationsSatisfied_ShouldReturnFalse()
public function isSatisfiedBy_GivenSpecificationsSatisfied_ShouldReturnFalse(): void
{
$spec = new NotSpecification(
new SatisfiedSpecification()
Expand All @@ -24,7 +25,7 @@ public function isSatisfiedBy_GivenSpecificationsSatisfied_ShouldReturnFalse()
/**
* @test
*/
public function isSatisfiedBy_GivenSpecificationNotSatisfied_ShouldReturnFalse()
public function isSatisfiedBy_GivenSpecificationNotSatisfied_ShouldReturnFalse(): void
{
$spec = new NotSpecification(
new NotSatisfiedSpecification()
Expand Down
9 changes: 5 additions & 4 deletions tests/OrSpecificationTest.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?php
namespace Riskio\SpecificationTest;

use PHPUnit\Framework\TestCase;
use Riskio\Specification\OrSpecification;
use Riskio\SpecificationTest\Fixtures\NotSatisfiedSpecification;
use Riskio\SpecificationTest\Fixtures\SatisfiedSpecification;

class OrSpecificationTest extends \PHPUnit_Framework_TestCase
class OrSpecificationTest extends TestCase
{
/**
* @test
*/
public function isSatisfiedBy_GivenBothSpecificationsSatisfied_ShouldReturnTrue()
public function isSatisfiedBy_GivenBothSpecificationsSatisfied_ShouldReturnTrue(): void
{
$spec = new OrSpecification(
new SatisfiedSpecification(),
Expand All @@ -25,7 +26,7 @@ public function isSatisfiedBy_GivenBothSpecificationsSatisfied_ShouldReturnTrue(
/**
* @test
*/
public function isSatisfiedBy_GivenOneSpecificationSatisfied_ShouldReturnTrue()
public function isSatisfiedBy_GivenOneSpecificationSatisfied_ShouldReturnTrue(): void
{
$spec = new OrSpecification(
new SatisfiedSpecification(),
Expand All @@ -40,7 +41,7 @@ public function isSatisfiedBy_GivenOneSpecificationSatisfied_ShouldReturnTrue()
/**
* @test
*/
public function isSatisfiedBy_GivenBothSpecificationsNotSatisfied_ShouldReturnFalse()
public function isSatisfiedBy_GivenBothSpecificationsNotSatisfied_ShouldReturnFalse(): void
{
$spec = new OrSpecification(
new NotSatisfiedSpecification(),
Expand Down

0 comments on commit e69cb4b

Please sign in to comment.