Skip to content

Commit

Permalink
Add github actions workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
nicholasruunu committed Jun 20, 2024
1 parent 73fc505 commit 2ee10b2
Show file tree
Hide file tree
Showing 16 changed files with 117 additions and 43 deletions.
8 changes: 4 additions & 4 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/spec export-ignore
.coveralls.yml export-ignore
.editorconfig export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.travis.yml export-ignore
.php_cs export-ignore
phpspec.yml.dist export-ignore
.php-cs-fixer.php export-ignore
phpspec.yml export-ignore
rector.php export-ignore
phpstan.neon export-ignore
42 changes: 42 additions & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: PHP Composer

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

permissions:
contents: read

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Validate composer.json and composer.lock
run: docker compose run composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v3
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.json') }}-${{ GITHUB_REF_NAME }}
restore-keys: |
${{ runner.os }}-php-
- name: Install packages
run: docker compose run composer install

- name: Run test suite
run: docker compose run phpspec

- name: Run static analyzer
run: docker compose run phpstan

- name: Run code style checker
run: docker compose run php-cs-fixer --dry-run
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
build/
vendor/
composer.lock
.php-cs-fixer.cache
17 changes: 17 additions & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

$finder = PhpCsFixer\Finder::create()
->exclude(['vendor', 'build'])
->in(__DIR__);

return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_class_elements' => true,
'strict_comparison' => true,
'strict_param' => true,
])
->setFinder($finder);
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
The MIT License (MIT)

Copyright (c) 2015 Rik Bruil
Copyright (c) 2024 Nicholas Ruunu

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -19,4 +20,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

9 changes: 4 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
{
"name": "Nicholas Ruunu",
"email": "nicholas@ruu.nu"
},
{
"name": "Rik Bruil",
"email": "rik.bruil@gmail.com"
}
],
"minimum-stability": "stable",
Expand All @@ -26,7 +22,9 @@
},
"require-dev": {
"phpspec/phpspec": "^7.5",
"rector/rector": "^1.1"
"rector/rector": "^1.1",
"phpstan/phpstan": "^1.11",
"friendsofphp/php-cs-fixer": "^3.59"
},
"extra": {
"branch-alias": {
Expand All @@ -35,6 +33,7 @@
},
"scripts": {
"test": "vendor/bin/phpspec run",
"static-analyzer": "vendor/bin/phpstan",
"fix-style": "vendor/bin/php-cs-fixer fix"
}
}
25 changes: 25 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
services:
php: &php
image: php:8.2-cli-alpine
volumes:
- .:/app
working_dir: /app

phpspec:
<<: *php
entrypoint: vendor/bin/phpspec
command: run

phpstan:
<<: *php
entrypoint: vendor/bin/phpstan

php-cs-fixer:
<<: *php
entrypoint: vendor/bin/php-cs-fixer fix

composer:
image: composer:latest
volumes:
- .:/app
working_dir: /app
File renamed without changes.
4 changes: 4 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
level: max
paths:
- src
14 changes: 6 additions & 8 deletions rector.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<?php

use Rector\Config\RectorConfig;
use Rector\Doctrine\Set\DoctrineSetList;
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector;

return RectorConfig::configure()->withPaths([
__DIR__ . '/src',
__DIR__ . '/spec',
])->withPhpSets(php83: true)->withAttributesSets(
symfony: true,
doctrine: true,
)
__DIR__.'/src',
__DIR__.'/spec',
])->withPhpSets(php83: true)->withAttributesSets(
symfony: true,
doctrine: true,
)
// here we can define, what prepared sets of rules will be applied
->withPreparedSets(
deadCode: true,
Expand Down
13 changes: 5 additions & 8 deletions spec/CompositeSpecificationSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ public function let(): void

public function it_is_initializable(): void
{
$this->shouldHaveType(\Purist\Specification\CompositeSpecification::class);
$this->shouldHaveType(CompositeSpecification::class);
}

public function it_should_return_and_specification(SpecificationInterface $specification): void
{
$specification->isSatisfiedBy('foo')->willReturn(true);

$and = $this->andX($specification);
$and->shouldHaveType(\Purist\Specification\AndX::class);
$and->shouldHaveType(AndX::class);
$and->isSatisfiedBy('foo')->shouldReturn(true);
}

Expand All @@ -35,7 +35,7 @@ public function it_should_return_or_specification(SpecificationInterface $specif
$specification->isSatisfiedBy('foo')->willReturn(false);

$or = $this->orX($specification);
$or->shouldHaveType(\Purist\Specification\OrX::class);
$or->shouldHaveType(OrX::class);
$or->isSatisfiedBy('foo')->shouldReturn(true);
}

Expand All @@ -44,19 +44,16 @@ public function it_should_return_not_specification(SpecificationInterface $speci
$specification->isSatisfiedBy('foo')->willReturn(true);

$not = $this->not($specification);
$not->shouldHaveType(\Purist\Specification\Not::class);
$not->shouldHaveType(Not::class);
$not->isSatisfiedBy('foo')->shouldReturn(false);
}
}

readonly class DummySpec extends CompositeSpecification
{
/**
* {@inheritDoc}
*/
#[\Override]
public function isSatisfiedBy($value): bool
{
return $value === 'foo';
return 'foo' === $value;
}
}
6 changes: 3 additions & 3 deletions spec/NotSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public function it_should_have_correct_types(SpecificationInterface $specificati
{
$this->beConstructedWith($specification);

$this->shouldHaveType(\Purist\Specification\Not::class);
$this->shouldHaveType(\Purist\Specification\SpecificationInterface::class);
$this->shouldHaveType(\Purist\Specification\CompositeSpecification::class);
$this->shouldHaveType(Not::class);
$this->shouldHaveType(SpecificationInterface::class);
$this->shouldHaveType(CompositeSpecification::class);
}

public function it_should_pass_if_child_fails(SpecificationInterface $specification): void
Expand Down
5 changes: 1 addition & 4 deletions src/AndX.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

namespace Purist\Specification;

readonly final class AndX extends CompositeSpecification
final readonly class AndX extends CompositeSpecification
{
public function __construct(private SpecificationInterface $x, private SpecificationInterface $y)
{
}

/**
* {@inheritDoc}
*/
#[\Override]
public function isSatisfiedBy(mixed $value): bool
{
Expand Down
2 changes: 1 addition & 1 deletion src/CompositeSpecification.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Purist\Specification;

readonly abstract class CompositeSpecification implements CompositeSpecificationInterface
abstract readonly class CompositeSpecification implements CompositeSpecificationInterface
{
#[\Override]
public function andX(SpecificationInterface $specification): AndX
Expand Down
5 changes: 1 addition & 4 deletions src/Not.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

namespace Purist\Specification;

readonly final class Not extends CompositeSpecification
final readonly class Not extends CompositeSpecification
{
public function __construct(private SpecificationInterface $wrapped)
{
}

/**
* {@inheritDoc}
*/
#[\Override]
public function isSatisfiedBy(mixed $value): bool
{
Expand Down
7 changes: 2 additions & 5 deletions src/OrX.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@

namespace Purist\Specification;

readonly final class OrX extends CompositeSpecification
final readonly class OrX extends CompositeSpecification
{
public function __construct(private SpecificationInterface $x, private SpecificationInterface $y)
{
}

/**
* {@inheritDoc}
*/
#[\Override]
public function isSatisfiedBy(mixed $value) : bool
public function isSatisfiedBy(mixed $value): bool
{
return $this->x->isSatisfiedBy($value) || $this->y->isSatisfiedBy($value);
}
Expand Down

0 comments on commit 2ee10b2

Please sign in to comment.