diff --git a/.github/workflows/quality-assurance.yml b/.github/workflows/quality-assurance.yml index bd42bab..851b217 100644 --- a/.github/workflows/quality-assurance.yml +++ b/.github/workflows/quality-assurance.yml @@ -13,10 +13,8 @@ jobs: laravel: [^10.0, ^11.0] include: - laravel: ^11.0 - phpunit: ^10.0 testbench: ^9.0 - laravel: ^10.0 - phpunit: ^9.5 testbench: ^8.0 name: P${{ matrix.php }} - L${{ matrix.laravel }} steps: @@ -32,7 +30,7 @@ jobs: - name: Install dependencies run: | - composer require "laravel/framework:${{ matrix.laravel }}" "phpunit/phpunit:${{ matrix.phpunit }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update + composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update composer update --prefer-dist --no-interaction - name: Run tests diff --git a/composer.json b/composer.json index e4c8fab..721e19b 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ "laravel/legacy-factories": "^1.1", "orchestra/testbench": "^8.0", "phpstan/phpstan": "^1.8", - "phpunit/phpunit": "^9.5|^10.0", + "phpunit/phpunit": "^10.0", "rector/rector": "^1.0" }, "autoload": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 67830fb..539ce2e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,26 +1,29 @@ - - - - ./src/ - - - src/ - src/ - src/Testing/ - - - - - src/ - - - - - - - - - - + + + + src/ + + + + + + + + + + + + + ./src/ + + + src/ + src/ + src/Testing/ + + diff --git a/src/Commands/ProcessMollieWebhookTest.php b/src/Commands/ProcessMollieWebhookTest.php index ee09c2c..ec433ac 100644 --- a/src/Commands/ProcessMollieWebhookTest.php +++ b/src/Commands/ProcessMollieWebhookTest.php @@ -9,7 +9,7 @@ use Craftzing\Laravel\MollieWebhooks\Events\MollieResourceStatusWasUpdated; use Craftzing\Laravel\MollieWebhooks\Exceptions\UnexpectedWebhookPayload; use Craftzing\Laravel\MollieWebhooks\Testing\IntegrationTestCase; -use Craftzing\Laravel\MollieWebhooks\Testing\TruthTest; +use Craftzing\Laravel\MollieWebhooks\Testing\HandleAssertions; use Exception; use Generator; use Illuminate\Contracts\Queue\ShouldQueue; @@ -30,7 +30,7 @@ public function itShouldBeQueued(): void $this->assertInstanceOf(ShouldQueue::class, new ProcessMollieWebhook($webhookCall)); } - public function invalidWebhookPayloads(): Generator + public static function invalidWebhookPayloads(): Generator { yield 'Missing a Mollie object identifier' => [ [], @@ -56,15 +56,15 @@ public function itFailsWhenTheWebhookPayloadIsInvalid(array $payload, Exception $this->handle(new ProcessMollieWebhook($webhookCall)); } - public function webhookPayloads(): Generator + public static function webhookPayloads(): Generator { yield 'order resource id' => [ - fn () => $this->generateOrderId(), + fn (self $test) => $test->generateOrderId(), MollieOrderWasUpdated::class, ]; yield 'payment resource id' => [ - fn () => $this->generatePaymentId(), + fn (self $test) => $test->generatePaymentId(), MolliePaymentWasUpdated::class, ]; } @@ -75,7 +75,7 @@ public function webhookPayloads(): Generator */ public function itCanHandleIncomingWebhooks(callable $generatesResourceId, string $event): void { - $resourceId = $generatesResourceId(); + $resourceId = $generatesResourceId($this); $webhookCall = new WebhookCall([ 'payload' => [ 'id' => $resourceId->value(), @@ -86,7 +86,7 @@ public function itCanHandleIncomingWebhooks(callable $generatesResourceId, strin Event::assertDispatched( $event, - new TruthTest(function (MollieResourceStatusWasUpdated $event) use ($resourceId, $webhookCall): void { + new HandleAssertions(function (MollieResourceStatusWasUpdated $event) use ($resourceId, $webhookCall): void { $this->assertSame($event->resourceId()->value(), $resourceId->value()); $this->assertTrue($event->webhookCall()->is($webhookCall)); }), diff --git a/src/Http/Requests/HandleMollieWebhooksRequestTest.php b/src/Http/Requests/HandleMollieWebhooksRequestTest.php index cd2ccd3..a64bd23 100644 --- a/src/Http/Requests/HandleMollieWebhooksRequestTest.php +++ b/src/Http/Requests/HandleMollieWebhooksRequestTest.php @@ -33,7 +33,7 @@ public function registerWebhooksHandlerRoute(): void }); } - public function invalidPayloads(): Generator + public static function invalidPayloads(): Generator { yield 'Empty payload' => [ [], @@ -68,7 +68,7 @@ public function itCanHandleIncomingMollieWebhooksWithAnInvalidPayload(array $pay Bus::assertDispatched(ProcessMollieWebhook::class); } - public function validPayloads(): Generator + public static function validPayloads(): Generator { yield 'Payload with a Mollie payment identifier' => [ ['id' => PaymentId::PREFIX . Str::random(8)], diff --git a/src/Orders/OrderIdTest.php b/src/Orders/OrderIdTest.php index 953e759..ade837d 100644 --- a/src/Orders/OrderIdTest.php +++ b/src/Orders/OrderIdTest.php @@ -9,17 +9,17 @@ final class OrderIdTest extends PrefixedResourceIdTestCase { - protected function resourceIdClass(): string + protected static function resourceIdClass(): string { return OrderId::class; } - protected function expectedPrefix(): string + protected static function expectedPrefix(): string { return 'ord_'; } - protected function expectedExceptionClass(): string + protected static function expectedExceptionClass(): string { return InvalidResourceId::class; } diff --git a/src/Orders/WebhookCallOrderHistoryTest.php b/src/Orders/WebhookCallOrderHistoryTest.php index 92ced68..8e8150a 100644 --- a/src/Orders/WebhookCallOrderHistoryTest.php +++ b/src/Orders/WebhookCallOrderHistoryTest.php @@ -14,10 +14,10 @@ final class WebhookCallOrderHistoryTest extends IntegrationTestCase { use ProvidesResourceWebhookCallHistory; - public function orderWebhookCallHistory(): Generator + public static function orderWebhookCallHistory(): Generator { foreach (FakeOrder::STATUSES as $orderStatus) { - yield from $this->resourceWebhookCallHistory($orderStatus, $this->randomOrderStatusExcept(...)); + yield from self::resourceWebhookCallHistory($orderStatus, self::randomOrderStatusExcept(...)); } } diff --git a/src/Payments/PaymentIdTest.php b/src/Payments/PaymentIdTest.php index c314c03..31a3d41 100644 --- a/src/Payments/PaymentIdTest.php +++ b/src/Payments/PaymentIdTest.php @@ -9,17 +9,17 @@ final class PaymentIdTest extends PrefixedResourceIdTestCase { - protected function resourceIdClass(): string + protected static function resourceIdClass(): string { return PaymentId::class; } - protected function expectedPrefix(): string + protected static function expectedPrefix(): string { return 'tr_'; } - protected function expectedExceptionClass(): string + protected static function expectedExceptionClass(): string { return InvalidResourceId::class; } diff --git a/src/Payments/WebhookCallPaymentHistoryTest.php b/src/Payments/WebhookCallPaymentHistoryTest.php index a74fa44..d3e53cb 100644 --- a/src/Payments/WebhookCallPaymentHistoryTest.php +++ b/src/Payments/WebhookCallPaymentHistoryTest.php @@ -14,10 +14,10 @@ final class WebhookCallPaymentHistoryTest extends IntegrationTestCase { use ProvidesResourceWebhookCallHistory; - public function paymentWebhookCallHistory(): Generator + public static function paymentWebhookCallHistory(): Generator { foreach (FakePayment::STATUSES as $paymentStatus) { - yield from $this->resourceWebhookCallHistory($paymentStatus, $this->randomPaymentStatusExcept(...)); + yield from self::resourceWebhookCallHistory($paymentStatus, self::randomPaymentStatusExcept(...)); } } diff --git a/src/Queries/LatestMollieWebhookCallByResourceIdTest.php b/src/Queries/LatestMollieWebhookCallByResourceIdTest.php index 7883c7e..cf68d62 100644 --- a/src/Queries/LatestMollieWebhookCallByResourceIdTest.php +++ b/src/Queries/LatestMollieWebhookCallByResourceIdTest.php @@ -16,7 +16,7 @@ final class LatestMollieWebhookCallByResourceIdTest extends IntegrationTestCase { use WithFaker; - public function noResults(): Generator + public static function noResults(): Generator { yield 'Webhook call history is empty' => [ fn () => null, @@ -27,9 +27,9 @@ public function noResults(): Generator ]; yield 'Webhook call history has no recent calls from Mollie for payload fragment' => [ - fn (ResourceId $resourceId) => FakeMollieWebhookCall::new() + fn (ResourceId $resourceId, self $test) => FakeMollieWebhookCall::new() ->forResourceId($resourceId) - ->create(['name' => $this->makeFaker()->name]), + ->create(['name' => $test->makeFaker()->name]), ]; } @@ -40,7 +40,7 @@ public function noResults(): Generator public function itCanHandleNoResults(callable $addWebhookCallHistory): void { $resourceId = $this->generatePaymentId(); - $addWebhookCallHistory($resourceId); + $addWebhookCallHistory($resourceId, $this); $ignoreWebhookCall = FakeMollieWebhookCall::new() ->forResourceId($resourceId) ->create(); @@ -97,7 +97,7 @@ public function itIgnoresFailedWebhookCalls(): void $this->assertTrue($result->is($latestWebhookCall)); } - public function webhookCallByFragment(): Generator + public static function webhookCallByFragment(): Generator { yield 'Webhook call history with multiple scenarios' => [ function (ResourceId $resourceId): WebhookCall { diff --git a/src/Refunds/RefundIdTest.php b/src/Refunds/RefundIdTest.php index 05ef729..105745a 100644 --- a/src/Refunds/RefundIdTest.php +++ b/src/Refunds/RefundIdTest.php @@ -9,17 +9,17 @@ final class RefundIdTest extends PrefixedResourceIdTestCase { - protected function resourceIdClass(): string + protected static function resourceIdClass(): string { return RefundId::class; } - protected function expectedPrefix(): string + protected static function expectedPrefix(): string { return 're_'; } - protected function expectedExceptionClass(): string + protected static function expectedExceptionClass(): string { return InvalidResourceId::class; } diff --git a/src/Subscribers/SubscribeToMollieOrderRefundsTest.php b/src/Subscribers/SubscribeToMollieOrderRefundsTest.php index 709bd80..d1e6479 100644 --- a/src/Subscribers/SubscribeToMollieOrderRefundsTest.php +++ b/src/Subscribers/SubscribeToMollieOrderRefundsTest.php @@ -49,7 +49,7 @@ public function itCanBeRegisteredAsAQueuedSubscriberForTheGenericOrderEvent(): v }); } - public function orderHistory(): Generator + public static function orderHistory(): Generator { yield 'Order has no refunds' => [ fn (): array => [], diff --git a/src/Subscribers/SubscribeToMollieOrderStatusChangesTest.php b/src/Subscribers/SubscribeToMollieOrderStatusChangesTest.php index eec3748..06d1636 100644 --- a/src/Subscribers/SubscribeToMollieOrderStatusChangesTest.php +++ b/src/Subscribers/SubscribeToMollieOrderStatusChangesTest.php @@ -16,7 +16,7 @@ use Craftzing\Laravel\MollieWebhooks\Testing\Doubles\FakeOrder; use Craftzing\Laravel\MollieWebhooks\Testing\Doubles\Orders\FakeOrderHistory; use Craftzing\Laravel\MollieWebhooks\Testing\IntegrationTestCase; -use Craftzing\Laravel\MollieWebhooks\Testing\TruthTest; +use Craftzing\Laravel\MollieWebhooks\Testing\HandleAssertions; use Generator; use Illuminate\Events\CallQueuedListener; use Illuminate\Support\Facades\Event; @@ -53,7 +53,7 @@ public function itCanBeRegisteredAsAQueuedSubscriberForTheGenericOrderEvent(): v }); } - public function orderHistory(): Generator + public static function orderHistory(): Generator { yield 'Order history does not have status for the order yet' => [ fn () => null, @@ -90,7 +90,7 @@ public function itCanHandleWebhookCallsIndicatingAnOrderStatusChangedToPaid(call } else { Event::assertDispatched( MollieOrderStatusChangedToPaid::class, - new TruthTest(function (MollieOrderStatusChangedToPaid $event) use ($orderId): void { + new HandleAssertions(function (MollieOrderStatusChangedToPaid $event) use ($orderId): void { $this->assertSame($orderId, $event->orderId); }), ); @@ -117,7 +117,7 @@ public function itCanHandleWebhookCallsIndicatingAnOrderStatusChangedToExpired(c } else { Event::assertDispatched( MollieOrderStatusChangedToExpired::class, - new TruthTest(function (MollieOrderStatusChangedToExpired $event) use ($orderId): void { + new HandleAssertions(function (MollieOrderStatusChangedToExpired $event) use ($orderId): void { $this->assertSame($orderId, $event->orderId); }), ); @@ -144,7 +144,7 @@ public function itCanHandleWebhookCallsIndicatingAnOrderStatusChangedToAuthorize } else { Event::assertDispatched( MollieOrderStatusChangedToAuthorized::class, - new TruthTest(function (MollieOrderStatusChangedToAuthorized $event) use ($orderId): void { + new HandleAssertions(function (MollieOrderStatusChangedToAuthorized $event) use ($orderId): void { $this->assertSame($orderId, $event->orderId); }), ); @@ -171,7 +171,7 @@ public function itCanHandleWebhookCallsIndicatingAnOrderStatusChangedToCanceled( } else { Event::assertDispatched( MollieOrderStatusChangedToCanceled::class, - new TruthTest(function (MollieOrderStatusChangedToCanceled $event) use ($orderId): void { + new HandleAssertions(function (MollieOrderStatusChangedToCanceled $event) use ($orderId): void { $this->assertSame($orderId, $event->orderId); }), ); @@ -198,7 +198,7 @@ public function itCanHandleWebhookCallsIndicatingAnOrderStatusChangedToCompleted } else { Event::assertDispatched( MollieOrderStatusChangedToCompleted::class, - new TruthTest(function (MollieOrderStatusChangedToCompleted $event) use ($orderId): void { + new HandleAssertions(function (MollieOrderStatusChangedToCompleted $event) use ($orderId): void { $this->assertSame($orderId, $event->orderId); }), ); @@ -214,7 +214,7 @@ private function webhookCallIndicatingOrderStatusChangedTo(string $status): Webh ->create(); } - public function statusesThatDontFireEvents(): Generator + public static function statusesThatDontFireEvents(): Generator { yield 'Call with status: `' . OrderStatus::STATUS_CREATED . '`' => [ OrderStatus::STATUS_CREATED, diff --git a/src/Subscribers/SubscribeToMolliePaymentRefundsTest.php b/src/Subscribers/SubscribeToMolliePaymentRefundsTest.php index e178a14..6dcbf3b 100644 --- a/src/Subscribers/SubscribeToMolliePaymentRefundsTest.php +++ b/src/Subscribers/SubscribeToMolliePaymentRefundsTest.php @@ -49,7 +49,7 @@ public function itCanBeRegisteredAsAQueuedSubscriberForTheGenericPaymentEvent(): }); } - public function paymentHistory(): Generator + public static function paymentHistory(): Generator { yield 'Payment has no refunds' => [ fn (): array => [], diff --git a/src/Subscribers/SubscribeToMolliePaymentStatusChangesTest.php b/src/Subscribers/SubscribeToMolliePaymentStatusChangesTest.php index a773c06..3b5275d 100644 --- a/src/Subscribers/SubscribeToMolliePaymentStatusChangesTest.php +++ b/src/Subscribers/SubscribeToMolliePaymentStatusChangesTest.php @@ -15,7 +15,7 @@ use Craftzing\Laravel\MollieWebhooks\Testing\Doubles\FakePayment; use Craftzing\Laravel\MollieWebhooks\Testing\Doubles\Payments\FakePaymentHistory; use Craftzing\Laravel\MollieWebhooks\Testing\IntegrationTestCase; -use Craftzing\Laravel\MollieWebhooks\Testing\TruthTest; +use Craftzing\Laravel\MollieWebhooks\Testing\HandleAssertions; use Generator; use Illuminate\Events\CallQueuedListener; use Illuminate\Support\Facades\Event; @@ -52,7 +52,7 @@ public function itCanBeRegisteredAsAQueuedSubscriberForTheGenericPaymentEvent(): }); } - public function paymentHistory(): Generator + public static function paymentHistory(): Generator { yield 'Payment history does not have status for the payment yet' => [ fn () => null, @@ -89,7 +89,7 @@ public function itCanHandleWebhookCallsIndicatingAPaymentStatusChangedToPaid(cal } else { Event::assertDispatched( MolliePaymentStatusChangedToPaid::class, - new TruthTest(function (MolliePaymentStatusChangedToPaid $event) use ($paymentId): void { + new HandleAssertions(function (MolliePaymentStatusChangedToPaid $event) use ($paymentId): void { $this->assertSame($paymentId, $event->paymentId); }), ); @@ -116,7 +116,7 @@ public function itCanHandleWebhookCallsIndicatingAPaymentStatusChangedToExpired( } else { Event::assertDispatched( MolliePaymentStatusChangedToExpired::class, - new TruthTest(function (MolliePaymentStatusChangedToExpired $event) use ($paymentId): void { + new HandleAssertions(function (MolliePaymentStatusChangedToExpired $event) use ($paymentId): void { $this->assertSame($paymentId, $event->paymentId); }), ); @@ -143,7 +143,7 @@ public function itCanHandleWebhookCallsIndicatingAPaymentStatusChangedToFailed(c } else { Event::assertDispatched( MolliePaymentStatusChangedToFailed::class, - new TruthTest(function (MolliePaymentStatusChangedToFailed $event) use ($paymentId): void { + new HandleAssertions(function (MolliePaymentStatusChangedToFailed $event) use ($paymentId): void { $this->assertSame($paymentId, $event->paymentId); }), ); @@ -170,7 +170,7 @@ public function itCanHandleWebhookCallsIndicatingAPaymentStatusChangedToCanceled } else { Event::assertDispatched( MolliePaymentStatusChangedToCanceled::class, - new TruthTest(function (MolliePaymentStatusChangedToCanceled $event) use ($paymentId): void { + new HandleAssertions(function (MolliePaymentStatusChangedToCanceled $event) use ($paymentId): void { $this->assertSame($paymentId, $event->paymentId); }), ); @@ -186,7 +186,7 @@ private function webhookCallIndicatingPaymentStatusChangedTo(string $status): We ->create(); } - public function statusesThatDontFireEvents(): Generator + public static function statusesThatDontFireEvents(): Generator { yield 'Call with status `' . PaymentStatus::STATUS_AUTHORIZED . '`' => [ PaymentStatus::STATUS_AUTHORIZED, diff --git a/src/Testing/Concerns/FakesMollie.php b/src/Testing/Concerns/FakesMollie.php index e2d5c05..0fa65d7 100644 --- a/src/Testing/Concerns/FakesMollie.php +++ b/src/Testing/Concerns/FakesMollie.php @@ -61,7 +61,7 @@ protected function generateRefundId(): RefundId return RefundId::fromString(RefundId::PREFIX . Str::random(random_int(4, 16))); } - protected function randomOrderStatusExcept(string $excludeStatus = ''): string + protected static function randomOrderStatusExcept(string $excludeStatus = ''): string { $statuses = array_filter( FakeOrder::STATUSES, @@ -71,7 +71,7 @@ protected function randomOrderStatusExcept(string $excludeStatus = ''): string return Arr::random($statuses); } - protected function randomPaymentStatusExcept(string $excludeStatus = ''): string + protected static function randomPaymentStatusExcept(string $excludeStatus = ''): string { $statuses = array_filter( FakePayment::STATUSES, @@ -81,7 +81,7 @@ protected function randomPaymentStatusExcept(string $excludeStatus = ''): string return Arr::random($statuses); } - protected function randomRefundStatusExcept(string $excludeStatus = ''): string + protected static function randomRefundStatusExcept(string $excludeStatus = ''): string { $statuses = array_filter( FakeRefund::STATUSES, diff --git a/src/Testing/Concerns/ProvidesResourceWebhookCallHistory.php b/src/Testing/Concerns/ProvidesResourceWebhookCallHistory.php index ac11d2b..574b361 100644 --- a/src/Testing/Concerns/ProvidesResourceWebhookCallHistory.php +++ b/src/Testing/Concerns/ProvidesResourceWebhookCallHistory.php @@ -16,7 +16,7 @@ trait ProvidesResourceWebhookCallHistory { - public function resourceWebhookCallHistory(string $resourceStatus, callable $resolveDifferentStatus): Generator + public static function resourceWebhookCallHistory(string $resourceStatus, callable $resolveDifferentStatus): Generator { yield "$resourceStatus - No webhook calls were made for the resource so far" => [ fn (): string => $resourceStatus, @@ -96,7 +96,7 @@ function (ResourceId $resourceId) use ($resourceStatus): string { ]; } - public function refundsWebhookCallHistory(string $refundStatus): Generator + public static function refundsWebhookCallHistory(): Generator { foreach (FakeRefund::STATUSES as $refundStatus) { yield "$refundStatus - No webhook calls were made for the resource" => [ @@ -131,7 +131,7 @@ function (ResourceId $resourceId, RefundId $refundId) use ($refundStatus): strin function (ResourceId $resourceId, RefundId $refundId) use ($refundStatus): string { $latestWebhookCall = FakeMollieWebhookCall::new() ->forResourceId($resourceId) - ->withRefundInPayload($refundId, $this->randomRefundStatusExcept($refundStatus)) + ->withRefundInPayload($refundId, self::randomRefundStatusExcept($refundStatus)) ->create(); return $refundStatus; diff --git a/src/Testing/Doubles/FakeOrder.php b/src/Testing/Doubles/FakeOrder.php index f38ac3c..3915fd6 100644 --- a/src/Testing/Doubles/FakeOrder.php +++ b/src/Testing/Doubles/FakeOrder.php @@ -53,7 +53,7 @@ public function id(): OrderId public function withStatus(string $status = ''): self { - $this->status = $status ?: $this->randomOrderStatusExcept(); + $this->status = $status ?: $this::randomOrderStatusExcept(); return $this; } diff --git a/src/Testing/TruthTest.php b/src/Testing/HandleAssertions.php similarity index 81% rename from src/Testing/TruthTest.php rename to src/Testing/HandleAssertions.php index 197f3b5..cd3f33a 100644 --- a/src/Testing/TruthTest.php +++ b/src/Testing/HandleAssertions.php @@ -6,7 +6,7 @@ use function call_user_func_array; -final class TruthTest +final class HandleAssertions { /** * @var callable @@ -18,7 +18,7 @@ public function __construct(callable $assertion) $this->assertion = $assertion; } - public function __invoke(...$arguments): bool + public function __invoke(mixed ...$arguments): bool { call_user_func_array($this->assertion, $arguments); diff --git a/src/Testing/PrefixedResourceIdTestCase.php b/src/Testing/PrefixedResourceIdTestCase.php index 482197a..3583172 100644 --- a/src/Testing/PrefixedResourceIdTestCase.php +++ b/src/Testing/PrefixedResourceIdTestCase.php @@ -17,13 +17,13 @@ abstract class PrefixedResourceIdTestCase extends TestCase { private const EXPECTED_PREFIX = 're_'; - abstract protected function resourceIdClass(): string; + abstract protected static function resourceIdClass(): string; - abstract protected function expectedPrefix(): string; + abstract protected static function expectedPrefix(): string; - abstract protected function expectedExceptionClass(): string; + abstract protected static function expectedExceptionClass(): string; - public function invalidMollieResourceIds(): Generator + public static function invalidMollieResourceIds(): Generator { yield 'Value has no prefix' => [Str::random(8)]; yield 'Value has an invalid prefix' => ['pa_' . Str::random(8)]; @@ -36,25 +36,27 @@ public function invalidMollieResourceIds(): Generator public function itCannotBeConstructedFromAnInvalidMollieResourceIdString(string $value): void { $this->expectExceptionObject( - call_user_func([$this->expectedExceptionClass(), 'missingExpectedPrefix'], $value, $this->expectedPrefix()) + call_user_func([$this::expectedExceptionClass(), 'missingExpectedPrefix'], $value, $this::expectedPrefix()) ); - $this->resourceIdClass()::fromString($value); + $this::resourceIdClass()::fromString($value); } - public function validMollieResourceIds(): Generator + public static function validMollieResourceIds(): Generator { - yield 'Short identifier' => [$this->expectedPrefix() . Str::random(4)]; - yield 'Long identifier' => [$this->expectedPrefix() . Str::random(8)]; + yield 'Short identifier' => [fn (self $test): string => $test::expectedPrefix() . Str::random(4)]; + yield 'Long identifier' => [fn (self $test): string => $test::expectedPrefix() . Str::random(8)]; } /** * @test * @dataProvider validMollieResourceIds */ - public function itCanBeConstructedFromAValidMollieResourceIdString(string $value): void + public function itCanBeConstructedFromAValidMollieResourceIdString(callable $resolveValue): void { - $resourceId = $this->resourceIdClass()::fromString($value); + $value = $resolveValue($this); + + $resourceId = $this::resourceIdClass()::fromString($value); $this->assertInstanceOf(ResourceId::class, $resourceId); } @@ -63,9 +65,11 @@ public function itCanBeConstructedFromAValidMollieResourceIdString(string $value * @test * @dataProvider validMollieResourceIds */ - public function itCanBeCastedToAString(string $value): void + public function itCanBeCastedToAString(callable $resolveValue): void { - $resourceId = $this->resourceIdClass()::fromString($value); + $value = $resolveValue($this); + + $resourceId = $this::resourceIdClass()::fromString($value); $this->assertSame($value, (string) $resourceId); } @@ -74,9 +78,11 @@ public function itCanBeCastedToAString(string $value): void * @test * @dataProvider validMollieResourceIds */ - public function itCanReturnItsValue(string $value): void + public function itCanReturnItsValue(callable $resolveValue): void { - $resourceId = $this->resourceIdClass()::fromString($value); + $value = $resolveValue($this); + + $resourceId = $this::resourceIdClass()::fromString($value); $this->assertSame($value, $resourceId->value()); } @@ -85,13 +91,15 @@ public function itCanReturnItsValue(string $value): void * @test * @dataProvider validMollieResourceIds */ - public function itCanBeSerialized(string $value): void + public function itCanBeSerialized(callable $resolveValue): void { - $resourceId = $this->resourceIdClass()::fromString($value); + $value = $resolveValue($this); + + $resourceId = $this::resourceIdClass()::fromString($value); $serializedResourceId = serialize($resourceId); - $this->assertEquals($resourceId, unserialize($serializedResourceId)); + $this->assertEquals($resourceId, unserialize($serializedResourceId, [$this::resourceIdClass()])); } /** @@ -99,7 +107,7 @@ public function itCanBeSerialized(string $value): void */ public function itCanBeUsedAsAResourceId(): void { - $resourceId = $this->resourceIdClass()::fromString($this->expectedPrefix() . Str::random(8)); + $resourceId = $this::resourceIdClass()::fromString($this::expectedPrefix() . Str::random(8)); $this->assertInstanceOf(ResourceId::class, $resourceId); } diff --git a/src/WebhookPayloadFragmentTest.php b/src/WebhookPayloadFragmentTest.php index 389d902..d2ccb94 100644 --- a/src/WebhookPayloadFragmentTest.php +++ b/src/WebhookPayloadFragmentTest.php @@ -12,7 +12,7 @@ final class WebhookPayloadFragmentTest extends TestCase { - public function keys(): Generator + public static function keys(): Generator { yield 'No keys' => ['']; yield 'Single key' => ['foo']; @@ -34,7 +34,7 @@ public function itCanBeConstructedFromKeys(string ...$keys): void $this->assertEmpty($payloadFragment->values()); } - public function values(): Generator + public static function values(): Generator { yield 'No values' => [ [],