Skip to content

Commit

Permalink
Udpdated psalm & PHPUnit to support PHP8.4
Browse files Browse the repository at this point in the history
yohang committed Jan 9, 2025

Verified

This commit was signed with the committer’s verified signature.
yohang Yohan Giarelli
1 parent 74b702e commit d2fe756
Showing 7 changed files with 43 additions and 46 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG PHP_VERSION=8.3
ARG PHP_VERSION=8.4

FROM php:${PHP_VERSION}-alpine

20 changes: 12 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -14,13 +14,17 @@ test_all_targets:
docker build -t yohang/finite:php-8.2-lowest --build-arg PHP_VERSION=8.2 --build-arg DEPENDENCIES=lowest .
docker build -t yohang/finite:php-8.3 --build-arg PHP_VERSION=8.3 .
docker build -t yohang/finite:php-8.3-lowest --build-arg PHP_VERSION=8.3 --build-arg DEPENDENCIES=lowest .
docker run -it --rm yohang/finite:php-8.1 php ./vendor/bin/phpunit
docker run -it --rm yohang/finite:php-8.1-lowest php ./vendor/bin/phpunit
docker run -it --rm yohang/finite:php-8.2 php ./vendor/bin/phpunit
docker run -it --rm yohang/finite:php-8.2-lowest php ./vendor/bin/phpunit
docker run -it --rm yohang/finite:php-8.3 php ./vendor/bin/phpunit
docker run -it --rm yohang/finite:php-8.3-lowest php ./vendor/bin/phpunit
docker build -t yohang/finite:php-8.4 --build-arg PHP_VERSION=8.4 .
docker build -t yohang/finite:php-8.4-lowest --build-arg PHP_VERSION=8.4 --build-arg DEPENDENCIES=lowest .
docker run -it --rm yohang/finite:php-8.1 php ./vendor/bin/phpunit --coverage-text
docker run -it --rm yohang/finite:php-8.1-lowest php ./vendor/bin/phpunit --coverage-text
docker run -it --rm yohang/finite:php-8.2 php ./vendor/bin/phpunit --coverage-text
docker run -it --rm yohang/finite:php-8.2-lowest php ./vendor/bin/phpunit --coverage-text
docker run -it --rm yohang/finite:php-8.3 php ./vendor/bin/phpunit --coverage-text
docker run -it --rm yohang/finite:php-8.3-lowest php ./vendor/bin/phpunit --coverage-text
docker run -it --rm yohang/finite:php-8.4 php ./vendor/bin/phpunit --coverage-text
docker run -it --rm yohang/finite:php-8.4-lowest php ./vendor/bin/phpunit --coverage-text

psalm:
docker build -t yohang/finite:php-8.3 --build-arg PHP_VERSION=8.3 .
docker run -it --rm yohang/finite:php-8.3 php ./vendor/bin/psalm --show-info=true
docker build -t yohang/finite:php-8.4 --build-arg PHP_VERSION=8.4 .
docker run -it --rm yohang/finite:php-8.4 php ./vendor/bin/psalm --show-info=true
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -24,10 +24,10 @@
"symfony/property-access": "^6.1|^7.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5.26",
"phpunit/phpunit": "^10.5.40",
"symfony/var-dumper": "^6.1|^7.0",
"twig/twig": "^3.4",
"vimeo/psalm": "^4.30"
"vimeo/psalm": "dev-master@dev"
},
"autoload": {
"psr-4": {
29 changes: 11 additions & 18 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
bootstrap="tests/bootstrap.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory>src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Finite Test Suite">
<directory>tests/</directory>
</testsuite>
</testsuites>
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd">
<source>
<include>
<directory>src</directory>
</include>
</source>
<testsuites>
<testsuite name="Finite Test Suite">
<directory>tests/</directory>
</testsuite>
</testsuites>
</phpunit>
5 changes: 5 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -12,4 +12,9 @@
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<PossiblyUnusedMethod errorLevel="suppress" />
<UnusedClass errorLevel="suppress" />
</issueHandlers>
</psalm>
5 changes: 3 additions & 2 deletions src/StateMachine.php
Original file line number Diff line number Diff line change
@@ -105,6 +105,7 @@ private function extractStateProperty(object $object, ?string $stateClass = null
}

$reflectionClass = new \ReflectionClass($object);
/** @psalm-suppress DocblockTypeContradiction */
do {
if (!$reflectionClass) {
throw new \InvalidArgumentException('Found no state on object ' . get_class($object));
@@ -135,7 +136,7 @@ private function extractStateProperty(object $object, ?string $stateClass = null
}

$reflectionEnum = new \ReflectionEnum($name);
/** @psalm-suppress RedundantConditionGivenDocblockType **/
/** @psalm-suppress RedundantCondition */
if (
null !== $stateClass &&
(
@@ -150,7 +151,7 @@ private function extractStateProperty(object $object, ?string $stateClass = null
return $property;
}
}
} while (null !== ($reflectionClass = $reflectionClass->getParentClass()));
} while ($reflectionClass = $reflectionClass->getParentClass());

throw new \InvalidArgumentException('Found no state on object ' . get_class($object));
}
24 changes: 9 additions & 15 deletions tests/StateMachineTest.php
Original file line number Diff line number Diff line change
@@ -4,8 +4,7 @@

use Finite\Event\CanTransitionEvent;
use Finite\Event\EventDispatcher;
use Finite\Event\PostTransitionEvent;
use Finite\Event\PreTransitionEvent;
use Finite\Event\TransitionEvent;
use Finite\StateMachine;
use Finite\Tests\E2E\Article;
use Finite\Tests\E2E\SimpleArticleState;
@@ -45,7 +44,7 @@ public function test_it_blocks_transition(): void
->expects($this->once())
->method('dispatch')
->with($this->isInstanceOf(CanTransitionEvent::class))
->willReturnCallback(fn (CanTransitionEvent $event) => $event->blockTransition());
->willReturnCallback(fn(CanTransitionEvent $event) => $event->blockTransition());


$stateMachine = new StateMachine($eventDispatcher);
@@ -58,21 +57,16 @@ public function test_it_applies_transition(): void
$object = new Article('Hi !');

$eventDispatcher = $this->getMockBuilder(EventDispatcher::class)->getMock();
$eventDispatcher
->expects($this->atLeastOnce())
->method('dispatch')
->with();

$matcher = $this->exactly(6);
$eventDispatcher
->expects($this->exactly(6))
->expects($matcher)
->method('dispatch')
->withConsecutive(
[$this->callback(fn (CanTransitionEvent $e) => SimpleArticleState::PUBLISH === $e->getTransitionName())],
[$this->callback(fn (PreTransitionEvent $e) => SimpleArticleState::PUBLISH === $e->getTransitionName())],
[$this->callback(fn (PostTransitionEvent $e) => SimpleArticleState::PUBLISH === $e->getTransitionName())],
[$this->callback(fn (CanTransitionEvent $e) => SimpleArticleState::REPORT === $e->getTransitionName())],
[$this->callback(fn (PreTransitionEvent $e) => SimpleArticleState::REPORT === $e->getTransitionName())],
[$this->callback(fn (PostTransitionEvent $e) => SimpleArticleState::REPORT === $e->getTransitionName())],
->willReturnCallback(
fn(TransitionEvent $e) => match ($matcher->numberOfInvocations()) {
1, 2, 3 => SimpleArticleState::PUBLISH === $e->getTransitionName(),
4, 5, 6 => SimpleArticleState::REPORT === $e->getTransitionName(),
}
);

$stateMachine = new StateMachine($eventDispatcher);

0 comments on commit d2fe756

Please sign in to comment.