From d2fe75680d17b0de9b835def4e9c20c7648852d0 Mon Sep 17 00:00:00 2001 From: Yohan Giarelli Date: Thu, 9 Jan 2025 15:33:22 +0100 Subject: [PATCH] Udpdated psalm & PHPUnit to support PHP8.4 --- Dockerfile | 2 +- Makefile | 20 ++++++++++++-------- composer.json | 4 ++-- phpunit.xml.dist | 29 +++++++++++------------------ psalm.xml | 5 +++++ src/StateMachine.php | 5 +++-- tests/StateMachineTest.php | 24 +++++++++--------------- 7 files changed, 43 insertions(+), 46 deletions(-) diff --git a/Dockerfile b/Dockerfile index dbac542..a846a7f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -ARG PHP_VERSION=8.3 +ARG PHP_VERSION=8.4 FROM php:${PHP_VERSION}-alpine diff --git a/Makefile b/Makefile index e5107cb..0c5a92e 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/composer.json b/composer.json index aa95bf1..7b94a71 100644 --- a/composer.json +++ b/composer.json @@ -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": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 40aee0c..2044d9f 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,24 +1,17 @@ - - - src/ - - - - - tests/ - - + xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"> + + + src + + + + + tests/ + + diff --git a/psalm.xml b/psalm.xml index 7c0333d..4d5b24a 100644 --- a/psalm.xml +++ b/psalm.xml @@ -12,4 +12,9 @@ + + + + + diff --git a/src/StateMachine.php b/src/StateMachine.php index 702278f..7603f85 100644 --- a/src/StateMachine.php +++ b/src/StateMachine.php @@ -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)); } diff --git a/tests/StateMachineTest.php b/tests/StateMachineTest.php index 28cfb21..1cd0dd5 100644 --- a/tests/StateMachineTest.php +++ b/tests/StateMachineTest.php @@ -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);