diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index d2eaeb3b..df92e679 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -131,3 +131,9 @@ parameters: identifier: trait.unused count: 1 path: src/Subscription/Subscriber/SubscriberUtil.php + + - + message: '#^Trait Patchlevel\\EventSourcing\\Test\\SubscriberUtilities is used zero times and is not analysed\.$#' + identifier: trait.unused + count: 1 + path: src/Test/SubscriberUtilities.php diff --git a/src/Test/AggregateAlreadySet.php b/src/Test/AggregateAlreadySet.php index 60ba6798..ca02c4b9 100644 --- a/src/Test/AggregateAlreadySet.php +++ b/src/Test/AggregateAlreadySet.php @@ -10,4 +10,4 @@ public function __construct() { parent::__construct('Aggregate already set. You should only return the aggregate if there is no given present.'); } -} \ No newline at end of file +} diff --git a/src/Test/AggregateRootTestCase.php b/src/Test/AggregateRootTestCase.php index 1c0cdb57..33da1509 100644 --- a/src/Test/AggregateRootTestCase.php +++ b/src/Test/AggregateRootTestCase.php @@ -11,7 +11,6 @@ use PHPUnit\Framework\Constraint\Exception as ExceptionConstraint; use PHPUnit\Framework\Constraint\ExceptionMessageIsOrContains; use PHPUnit\Framework\TestCase; -use RuntimeException; use Throwable; abstract class AggregateRootTestCase extends TestCase @@ -88,9 +87,11 @@ public function assert(): self throw new NoAggregateCreated(); } - if ($aggregate === null && $return instanceof AggregateRoot) { - $aggregate = $return; + if ($aggregate !== null || !($return instanceof AggregateRoot)) { + continue; } + + $aggregate = $return; } } catch (Throwable $throwable) { $this->handleException($throwable); diff --git a/src/Test/AggregateTestError.php b/src/Test/AggregateTestError.php index 2ed22edd..f952eee4 100644 --- a/src/Test/AggregateTestError.php +++ b/src/Test/AggregateTestError.php @@ -8,8 +8,4 @@ abstract class AggregateTestError extends RuntimeException { - public function __construct(string $message = "", int $code = 0, ?Throwable $previous = null) - { - parent::__construct($message, $code, $previous); - } -} \ No newline at end of file +} diff --git a/src/Test/NoAggregateCreated.php b/src/Test/NoAggregateCreated.php index 3d65bdc1..19b123f6 100644 --- a/src/Test/NoAggregateCreated.php +++ b/src/Test/NoAggregateCreated.php @@ -10,4 +10,4 @@ public function __construct() { parent::__construct('No aggregate set and no aggregate returned. Please provide given events or create the aggregate with the first action.'); } -} \ No newline at end of file +} diff --git a/src/Test/SubscriberUtilities.php b/src/Test/SubscriberUtilities.php index 5b40c899..851152c5 100644 --- a/src/Test/SubscriberUtilities.php +++ b/src/Test/SubscriberUtilities.php @@ -30,9 +30,11 @@ public function executeSetup(object ...$subscribers): self foreach ($subscriberAccessors as $subscriberAccessor) { $setupMethod = $subscriberAccessor->setupMethod(); - if ($setupMethod) { - $setupMethod(); + if (!$setupMethod) { + continue; } + + $setupMethod(); } return $this; @@ -60,9 +62,11 @@ public function executeTeardown(object ...$subscribers): self foreach ($subscriberAccessors as $subscriberAccessor) { $teardownMethod = $subscriberAccessor->teardownMethod(); - if ($teardownMethod) { - $teardownMethod(); + if (!$teardownMethod) { + continue; } + + $teardownMethod(); } return $this; @@ -77,6 +81,7 @@ public function reset(): void /** * @param array $subscribers + * * @return iterable */ private function createSubscriberAccessors(array $subscribers): iterable diff --git a/tests/Unit/Test/AggregateRootTestCaseTest.php b/tests/Unit/Test/AggregateRootTestCaseTest.php index e3bb2d81..a6da155e 100644 --- a/tests/Unit/Test/AggregateRootTestCaseTest.php +++ b/tests/Unit/Test/AggregateRootTestCaseTest.php @@ -250,7 +250,7 @@ public function testWithDataProvider(array $givenEvents, array $whens, array $ex public function getTester(): AggregateRootTestCase { - return new class($this->name()) extends AggregateRootTestCase { + return new class ($this->name()) extends AggregateRootTestCase { protected function aggregateClass(): string { return Profile::class; diff --git a/tests/Unit/Test/SubscriberUtilitiesTest.php b/tests/Unit/Test/SubscriberUtilitiesTest.php index d6859384..d22fd920 100644 --- a/tests/Unit/Test/SubscriberUtilitiesTest.php +++ b/tests/Unit/Test/SubscriberUtilitiesTest.php @@ -18,7 +18,8 @@ final class SubscriberUtilitiesTest extends TestCase { public function testRun(): void { - $subscriber = new #[Projector('test')] class { + $subscriber = new #[Projector('test')] + class { public int $called = 0; #[Subscribe(ProfileCreated::class)] @@ -40,9 +41,11 @@ public function run(): void self::assertSame(1, $subscriber->called); } + public function testRunNotFound(): void { - $subscriber = new #[Projector('test')] class { + $subscriber = new #[Projector('test')] + class { public int $called = 0; public function run(): void @@ -66,7 +69,8 @@ public function run(): void public function testSetup(): void { - $subscriber = new #[Projector('test')] class { + $subscriber = new #[Projector('test')] + class { public int $called = 0; #[Setup] @@ -84,7 +88,8 @@ public function run(): void public function testSetupNotFound(): void { - $subscriber = new #[Projector('test')] class { + $subscriber = new #[Projector('test')] + class { public int $called = 0; public function run(): void @@ -101,7 +106,8 @@ public function run(): void public function testTeardown(): void { - $subscriber = new #[Projector('test')] class { + $subscriber = new #[Projector('test')] + class { public int $called = 0; #[Teardown] @@ -119,7 +125,8 @@ public function run(): void public function testTeardownNotFound(): void { - $subscriber = new #[Projector('test')] class { + $subscriber = new #[Projector('test')] + class { public int $called = 0; public function run(): void @@ -136,7 +143,7 @@ public function run(): void public function getTester(): TestCase { - return new class($this->name()) extends TestCase { + return new class ($this->name()) extends TestCase { use SubscriberUtilities; }; }