Skip to content

Commit

Permalink
CS fix
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielBadura committed Jan 3, 2025
1 parent 1a000f8 commit 2830333
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 22 deletions.
6 changes: 6 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/Test/AggregateAlreadySet.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ public function __construct()
{
parent::__construct('Aggregate already set. You should only return the aggregate if there is no given present.');

Check warning on line 11 in src/Test/AggregateAlreadySet.php

View workflow job for this annotation

GitHub Actions / Mutation tests on diff (locked, 8.3, ubuntu-latest)

Escaped Mutant for Mutator "MethodCallRemoval": --- Original +++ New @@ @@ { public function __construct() { - parent::__construct('Aggregate already set. You should only return the aggregate if there is no given present.'); + } }
}
}
}
7 changes: 4 additions & 3 deletions src/Test/AggregateRootTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)) {

Check failure on line 90 in src/Test/AggregateRootTestCase.php

View workflow job for this annotation

GitHub Actions / Static Analysis by Deptrac (locked, 8.3, ubuntu-latest)

Patchlevel\EventSourcing\Test\AggregateRootTestCase must not depend on Patchlevel\EventSourcing\Aggregate\AggregateRoot (Test on Aggregate)
continue;
}

$aggregate = $return;
}
} catch (Throwable $throwable) {
$this->handleException($throwable);
Expand Down
6 changes: 1 addition & 5 deletions src/Test/AggregateTestError.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion src/Test/NoAggregateCreated.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.');

Check warning on line 11 in src/Test/NoAggregateCreated.php

View workflow job for this annotation

GitHub Actions / Mutation tests on diff (locked, 8.3, ubuntu-latest)

Escaped Mutant for Mutator "MethodCallRemoval": --- Original +++ New @@ @@ { public function __construct() { - parent::__construct('No aggregate set and no aggregate returned. Please provide given events or create the aggregate with the first action.'); + } }
}
}
}
13 changes: 9 additions & 4 deletions src/Test/SubscriberUtilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ public function executeSetup(object ...$subscribers): self
foreach ($subscriberAccessors as $subscriberAccessor) {
$setupMethod = $subscriberAccessor->setupMethod();

if ($setupMethod) {
$setupMethod();
if (!$setupMethod) {
continue;

Check warning on line 34 in src/Test/SubscriberUtilities.php

View workflow job for this annotation

GitHub Actions / Mutation tests on diff (locked, 8.3, ubuntu-latest)

Escaped Mutant for Mutator "Continue_": --- Original +++ New @@ @@ foreach ($subscriberAccessors as $subscriberAccessor) { $setupMethod = $subscriberAccessor->setupMethod(); if (!$setupMethod) { - continue; + break; } $setupMethod(); }
}

$setupMethod();
}

return $this;
Expand Down Expand Up @@ -60,9 +62,11 @@ public function executeTeardown(object ...$subscribers): self
foreach ($subscriberAccessors as $subscriberAccessor) {
$teardownMethod = $subscriberAccessor->teardownMethod();

if ($teardownMethod) {
$teardownMethod();
if (!$teardownMethod) {
continue;

Check warning on line 66 in src/Test/SubscriberUtilities.php

View workflow job for this annotation

GitHub Actions / Mutation tests on diff (locked, 8.3, ubuntu-latest)

Escaped Mutant for Mutator "Continue_": --- Original +++ New @@ @@ foreach ($subscriberAccessors as $subscriberAccessor) { $teardownMethod = $subscriberAccessor->teardownMethod(); if (!$teardownMethod) { - continue; + break; } $teardownMethod(); }
}

$teardownMethod();
}

return $this;
Expand All @@ -77,6 +81,7 @@ public function reset(): void

/**

Check failure on line 82 in src/Test/SubscriberUtilities.php

View workflow job for this annotation

GitHub Actions / Static Analysis by Deptrac (locked, 8.3, ubuntu-latest)

Patchlevel\EventSourcing\Test\SubscriberUtilities must not depend on Patchlevel\EventSourcing\Subscription\Subscriber\MetadataSubscriberAccessor (Test on Subscription)
* @param array<object> $subscribers
*
* @return iterable<MetadataSubscriberAccessor>
*/
private function createSubscriberAccessors(array $subscribers): iterable
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Test/AggregateRootTestCaseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Check failure on line 253 in tests/Unit/Test/AggregateRootTestCaseTest.php

View workflow job for this annotation

GitHub Actions / Static Analysis by Psalm (locked, 8.3, ubuntu-latest)

InternalMethod

tests/Unit/Test/AggregateRootTestCaseTest.php:253:16: InternalMethod: Constructor PHPUnit\Framework\TestCase::__construct is internal to PHPUnit but called from Patchlevel\EventSourcing\Tests\Unit\Test\AggregateRootTestCaseTest::getTester (see https://psalm.dev/175)
protected function aggregateClass(): string
{
return Profile::class;
Expand Down
21 changes: 14 additions & 7 deletions tests/Unit/Test/SubscriberUtilitiesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand All @@ -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
Expand All @@ -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]
Expand All @@ -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
Expand All @@ -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]
Expand All @@ -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
Expand All @@ -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;
};
}
Expand Down

0 comments on commit 2830333

Please sign in to comment.