From c368e8d47e39bca6597d533c9bcd6ff8416616e1 Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Mon, 22 Apr 2024 10:56:40 +0200 Subject: [PATCH 01/39] Upgrade dependencies --- composer.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 94b1936..7c03f07 100644 --- a/composer.json +++ b/composer.json @@ -11,16 +11,16 @@ } ], "require": { - "php": "^7.4|^8.0", + "php": "^8.1|^8.2|^8.3", "ext-json": "*", - "illuminate/support": "^7.0|^8.0", - "mollie/laravel-mollie": "^2.0", - "spatie/laravel-webhook-client": "^2.7.4" + "illuminate/support": "^9.0|^10.0|^11.0", + "mollie/laravel-mollie": "^3.0", + "spatie/laravel-webhook-client": "^3.0" }, "require-dev": { "laravel/legacy-factories": "^1.1", - "orchestra/testbench": "^5.0|^6.5", - "phpstan/phpstan": "^0.12.74", + "orchestra/testbench": "^7.8|^8.0", + "phpstan/phpstan": "^1.8", "phpunit/phpunit": "^9.5" }, "autoload": { From 686dba229b817266be7830a79ab1a55c380149ec Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Mon, 22 Apr 2024 10:56:48 +0200 Subject: [PATCH 02/39] Fix phpstan config --- phpstan.neon.dist | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 006c9a4..baae146 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -2,7 +2,7 @@ parameters: level: 6 paths: - src - excludes_analyse: + excludePaths: - ./**/Testing/* - ./**/*Test.php - ./**/*TestCase.php From 2aa2a321480618e697b1a35f5bc74e72db0fd5ba Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Mon, 22 Apr 2024 10:57:14 +0200 Subject: [PATCH 03/39] Add php cs fixer --- .php-cs-fixer.dist.php | 1 + composer.json | 1 + 2 files changed, 2 insertions(+) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 667dd56..e1bddc7 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -7,6 +7,7 @@ ->ignoreVCS(true); return (new PhpCsFixer\Config()) + ->setRiskyAllowed(true) ->setRules([ '@PSR2' => true, 'array_syntax' => ['syntax' => 'short'], diff --git a/composer.json b/composer.json index 7c03f07..9972f09 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,7 @@ "spatie/laravel-webhook-client": "^3.0" }, "require-dev": { + "friendsofphp/php-cs-fixer": "^3.54", "laravel/legacy-factories": "^1.1", "orchestra/testbench": "^7.8|^8.0", "phpstan/phpstan": "^1.8", From 84d144389e1ee31b8c1298858776ac64385b8ec9 Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Mon, 22 Apr 2024 10:59:00 +0200 Subject: [PATCH 04/39] Add rector --- composer.json | 3 ++- rector.php | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 rector.php diff --git a/composer.json b/composer.json index 9972f09..87ea05f 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,8 @@ "laravel/legacy-factories": "^1.1", "orchestra/testbench": "^7.8|^8.0", "phpstan/phpstan": "^1.8", - "phpunit/phpunit": "^9.5" + "phpunit/phpunit": "^9.5", + "rector/rector": "^1.0" }, "autoload": { "psr-4": { diff --git a/rector.php b/rector.php new file mode 100644 index 0000000..a1ea6b2 --- /dev/null +++ b/rector.php @@ -0,0 +1,20 @@ +parallel(); + $rectorConfig->paths([ + __DIR__ . '/src', + ]); + + $rectorConfig->sets([ + \Rector\Set\ValueObject\LevelSetList::UP_TO_PHP_81, + ]); + + $rectorConfig->skip([ + \Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector::class, + ]); +}; From e3693b066bfa504cd8a29665b517bb378b455012 Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Mon, 22 Apr 2024 10:59:15 +0200 Subject: [PATCH 05/39] Fix import --- src/Commands/ProcessMollieWebhook.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Commands/ProcessMollieWebhook.php b/src/Commands/ProcessMollieWebhook.php index 97ece94..cf13ead 100644 --- a/src/Commands/ProcessMollieWebhook.php +++ b/src/Commands/ProcessMollieWebhook.php @@ -11,7 +11,7 @@ use Craftzing\Laravel\MollieWebhooks\Orders\OrderId; use Craftzing\Laravel\MollieWebhooks\Payments\PaymentId; use Illuminate\Contracts\Events\Dispatcher; -use Spatie\WebhookClient\ProcessWebhookJob; +use Spatie\WebhookClient\Jobs\ProcessWebhookJob; final class ProcessMollieWebhook extends ProcessWebhookJob { @@ -36,7 +36,7 @@ public function handle(Dispatcher $events): void $this->handleOrderEvent(OrderId::fromString($id), $events); return; - } catch (InvalidResourceId $e) { + } catch (InvalidResourceId) { // The ID is not an OrderId, moving on to try and use it as a different Mollie resource ID. } From a819d329f5c1d90c9ce1d815f7746bac497c4464 Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Mon, 22 Apr 2024 10:59:37 +0200 Subject: [PATCH 06/39] Fix missing exception --- src/Exceptions/UnexpectedWebhookPayload.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Exceptions/UnexpectedWebhookPayload.php b/src/Exceptions/UnexpectedWebhookPayload.php index 37706f9..1883eac 100644 --- a/src/Exceptions/UnexpectedWebhookPayload.php +++ b/src/Exceptions/UnexpectedWebhookPayload.php @@ -4,9 +4,9 @@ namespace Craftzing\Laravel\MollieWebhooks\Exceptions; -use Spatie\WebhookClient\Exceptions\WebhookFailed as SpatieWebhookFailed; +use Exception; -final class UnexpectedWebhookPayload extends SpatieWebhookFailed +final class UnexpectedWebhookPayload extends Exception { public static function missingObjectIdentifier(): self { From 28bf1c049b3d73c98f350bc9bc33cdb5b0e8bcf3 Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Mon, 22 Apr 2024 10:59:50 +0200 Subject: [PATCH 07/39] Add missing config parameter --- src/Http/Requests/HandleMollieWebhooksRequest.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Http/Requests/HandleMollieWebhooksRequest.php b/src/Http/Requests/HandleMollieWebhooksRequest.php index 9f76e70..586b912 100644 --- a/src/Http/Requests/HandleMollieWebhooksRequest.php +++ b/src/Http/Requests/HandleMollieWebhooksRequest.php @@ -8,6 +8,7 @@ use Craftzing\Laravel\MollieWebhooks\Http\MollieSignatureValidator; use Illuminate\Http\Request; use Illuminate\Routing\Controller; +use Spatie\WebhookClient\Exceptions\InvalidConfig; use Spatie\WebhookClient\Models\WebhookCall; use Spatie\WebhookClient\WebhookConfig; use Spatie\WebhookClient\WebhookProcessor; @@ -16,6 +17,9 @@ final class HandleMollieWebhooksRequest extends Controller { + /** + * @throws InvalidConfig + */ public function __invoke(Request $request): Response { $webhookConfig = new WebhookConfig([ @@ -24,6 +28,7 @@ public function __invoke(Request $request): Response 'webhook_profile' => ProcessEverythingWebhookProfile::class, 'webhook_model' => WebhookCall::class, 'process_webhook_job' => ProcessMollieWebhook::class, + 'store_headers' => '*', ]); return (new WebhookProcessor($request, $webhookConfig))->process(); From cdb53a5217b9c2bd98a8a830ff98009511d7c203 Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Mon, 22 Apr 2024 11:00:06 +0200 Subject: [PATCH 08/39] Fix running migration from spatie package --- src/Testing/IntegrationTestCase.php | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Testing/IntegrationTestCase.php b/src/Testing/IntegrationTestCase.php index 7349645..2d7d68b 100644 --- a/src/Testing/IntegrationTestCase.php +++ b/src/Testing/IntegrationTestCase.php @@ -8,7 +8,6 @@ use Craftzing\Laravel\MollieWebhooks\MollieWebhooksServiceProvider; use Craftzing\Laravel\MollieWebhooks\Testing\Concerns\FakesEvents; use Craftzing\Laravel\MollieWebhooks\Testing\Concerns\FakesMollie; -use CreateWebhookCallsTable; use Illuminate\Database\Eloquent\Factory; use Illuminate\Foundation\Bootstrap\LoadEnvironmentVariables; use Illuminate\Support\Facades\Bus; @@ -30,10 +29,10 @@ public function setUp(): void protected function setUpDatabase(): void { - include_once __DIR__ . + $migration = include __DIR__ . '/../../vendor/spatie/laravel-webhook-client/database/migrations/create_webhook_calls_table.php.stub'; - (new CreateWebhookCallsTable())->up(); + $migration->up(); } protected function getEnvironmentSetUp($app): void @@ -68,11 +67,7 @@ protected function getPackageProviders($app): array return [MollieWebhooksServiceProvider::class]; } - /** - * @param object $class - * @return mixed - */ - public function handle(object $class) + public function handle(object $class): mixed { return $this->app->call([$class, 'handle']); } From 73f3e6bdfb68fe26b8fae3527d34fa183afc9de6 Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Mon, 22 Apr 2024 11:00:18 +0200 Subject: [PATCH 09/39] Add missing property in factory --- src/Testing/Factories/WebhookCallFactory.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Testing/Factories/WebhookCallFactory.php b/src/Testing/Factories/WebhookCallFactory.php index 05000ef..2b1f53e 100644 --- a/src/Testing/Factories/WebhookCallFactory.php +++ b/src/Testing/Factories/WebhookCallFactory.php @@ -3,11 +3,13 @@ declare(strict_types=1); use Carbon\CarbonImmutable; +use Illuminate\Database\Eloquent\Factory; use Spatie\WebhookClient\Models\WebhookCall; -/* @var \Illuminate\Database\Eloquent\Factory $factory */ +/* @var Factory $factory */ $factory->define(WebhookCall::class, fn () => [ 'name' => 'mollie', + 'url' => fake()->url(), 'payload' => [], 'created_at' => CarbonImmutable::now(), ]); From 52b7b71b6a58d9406b16eeaa275a96043c30e3bb Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Mon, 22 Apr 2024 11:01:20 +0200 Subject: [PATCH 10/39] Replace deprecated mollie api wrapper --- .../SubscribeToMollieOrderRefunds.php | 16 +++++++++------- .../SubscribeToMollieOrderStatusChanges.php | 19 +++++++++---------- .../SubscribeToMolliePaymentRefunds.php | 13 +++++++------ .../SubscribeToMolliePaymentStatusChanges.php | 19 +++++++++---------- src/Testing/Concerns/FakesMollie.php | 7 ------- src/Testing/Doubles/FakeMollieApiClient.php | 9 ++++++++- 6 files changed, 42 insertions(+), 41 deletions(-) diff --git a/src/Subscribers/SubscribeToMollieOrderRefunds.php b/src/Subscribers/SubscribeToMollieOrderRefunds.php index 935f5c3..8997644 100644 --- a/src/Subscribers/SubscribeToMollieOrderRefunds.php +++ b/src/Subscribers/SubscribeToMollieOrderRefunds.php @@ -10,20 +10,22 @@ use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\Queue\ShouldQueue; use Mollie\Api\Endpoints\OrderEndpoint; -use Mollie\Laravel\Wrappers\MollieApiWrapper; +use Mollie\Api\MollieApiClient; +use Mollie\Api\Resources\Refund; final class SubscribeToMollieOrderRefunds implements ShouldQueue { use DispatchesRefundEventsForResources; private OrderEndpoint $orders; - private OrderHistory $orderHistory; - public function __construct(MollieApiWrapper $mollie, Dispatcher $events, OrderHistory $orderHistory) - { - $this->orders = $mollie->orders(); + public function __construct( + MollieApiClient $mollie, + Dispatcher $events, + private readonly OrderHistory $orderHistory, + ) { + $this->orders = $mollie->orders; $this->events = $events; - $this->orderHistory = $orderHistory; } public function __invoke(MollieOrderWasUpdated $event): void @@ -31,7 +33,7 @@ public function __invoke(MollieOrderWasUpdated $event): void $orderId = $event->orderId; $order = $this->orders->get($orderId->value()); - /* @var \Mollie\Api\Resources\Refund $refund */ + /* @var Refund $refund */ foreach ($order->refunds() as $refund) { $refundId = RefundId::fromString($refund->id); $hasRefundWithStatusForPayment = $this->orderHistory->hasRefundWithStatusForOrder( diff --git a/src/Subscribers/SubscribeToMollieOrderStatusChanges.php b/src/Subscribers/SubscribeToMollieOrderStatusChanges.php index 2953909..7a4f657 100644 --- a/src/Subscribers/SubscribeToMollieOrderStatusChanges.php +++ b/src/Subscribers/SubscribeToMollieOrderStatusChanges.php @@ -14,20 +14,19 @@ use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\Queue\ShouldQueue; use Mollie\Api\Endpoints\OrderEndpoint; +use Mollie\Api\MollieApiClient; use Mollie\Api\Types\OrderStatus; -use Mollie\Laravel\Wrappers\MollieApiWrapper; final class SubscribeToMollieOrderStatusChanges implements ShouldQueue { - private OrderEndpoint $orders; - private Dispatcher $events; - private OrderHistory $orderHistory; - - public function __construct(MollieApiWrapper $mollie, Dispatcher $events, OrderHistory $orderHistory) - { - $this->orders = $mollie->orders(); - $this->events = $events; - $this->orderHistory = $orderHistory; + private readonly OrderEndpoint $orders; + + public function __construct( + MollieApiClient $mollie, + private readonly Dispatcher $events, + private readonly OrderHistory $orderHistory + ) { + $this->orders = $mollie->orders; } public function __invoke(MollieOrderWasUpdated $event): void diff --git a/src/Subscribers/SubscribeToMolliePaymentRefunds.php b/src/Subscribers/SubscribeToMolliePaymentRefunds.php index f05cc3e..89d7100 100644 --- a/src/Subscribers/SubscribeToMolliePaymentRefunds.php +++ b/src/Subscribers/SubscribeToMolliePaymentRefunds.php @@ -10,20 +10,21 @@ use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\Queue\ShouldQueue; use Mollie\Api\Endpoints\PaymentEndpoint; -use Mollie\Laravel\Wrappers\MollieApiWrapper; +use Mollie\Api\MollieApiClient; final class SubscribeToMolliePaymentRefunds implements ShouldQueue { use DispatchesRefundEventsForResources; private PaymentEndpoint $payments; - private PaymentHistory $paymentHistory; - public function __construct(MollieApiWrapper $mollie, Dispatcher $events, PaymentHistory $paymentHistory) - { - $this->payments = $mollie->payments(); + public function __construct( + MollieApiClient $mollie, + Dispatcher $events, + private readonly PaymentHistory $paymentHistory, + ) { + $this->payments = $mollie->payments; $this->events = $events; - $this->paymentHistory = $paymentHistory; } public function __invoke(MolliePaymentWasUpdated $event): void diff --git a/src/Subscribers/SubscribeToMolliePaymentStatusChanges.php b/src/Subscribers/SubscribeToMolliePaymentStatusChanges.php index 1c8429e..fb564f3 100644 --- a/src/Subscribers/SubscribeToMolliePaymentStatusChanges.php +++ b/src/Subscribers/SubscribeToMolliePaymentStatusChanges.php @@ -13,20 +13,19 @@ use Illuminate\Contracts\Events\Dispatcher; use Illuminate\Contracts\Queue\ShouldQueue; use Mollie\Api\Endpoints\PaymentEndpoint; +use Mollie\Api\MollieApiClient; use Mollie\Api\Types\PaymentStatus; -use Mollie\Laravel\Wrappers\MollieApiWrapper; final class SubscribeToMolliePaymentStatusChanges implements ShouldQueue { - private PaymentEndpoint $payments; - private Dispatcher $events; - private PaymentHistory $paymentHistory; - - public function __construct(MollieApiWrapper $mollie, Dispatcher $events, PaymentHistory $paymentHistory) - { - $this->payments = $mollie->payments(); - $this->events = $events; - $this->paymentHistory = $paymentHistory; + private readonly PaymentEndpoint $payments; + + public function __construct( + MollieApiClient $mollie, + private readonly Dispatcher $events, + private readonly PaymentHistory $paymentHistory, + ) { + $this->payments = $mollie->payments; } public function __invoke(MolliePaymentWasUpdated $event): void diff --git a/src/Testing/Concerns/FakesMollie.php b/src/Testing/Concerns/FakesMollie.php index ae009fa..e2d5c05 100644 --- a/src/Testing/Concerns/FakesMollie.php +++ b/src/Testing/Concerns/FakesMollie.php @@ -13,11 +13,9 @@ use Craftzing\Laravel\MollieWebhooks\Testing\Doubles\FakePayment; use Craftzing\Laravel\MollieWebhooks\Testing\Doubles\FakePaymentsEndpoint; use Craftzing\Laravel\MollieWebhooks\Testing\Doubles\FakeRefund; -use Illuminate\Contracts\Config\Repository; use Illuminate\Foundation\Application; use Illuminate\Support\Arr; use Illuminate\Support\Str; -use Mollie\Laravel\Wrappers\MollieApiWrapper; use function array_filter; use function env; @@ -46,11 +44,6 @@ protected function fakeMollie(): void $client = FakeMollieApiClient::fake($this->app); $client->payments = FakePaymentsEndpoint::fake($this->app); $client->orders = FakeOrdersEndpoint::fake($this->app); - - $this->swap( - MollieApiWrapper::class, - new MollieApiWrapper($this->app[Repository::class], $client), - ); } protected function generateOrderId(): OrderId diff --git a/src/Testing/Doubles/FakeMollieApiClient.php b/src/Testing/Doubles/FakeMollieApiClient.php index e7f857b..56acb68 100644 --- a/src/Testing/Doubles/FakeMollieApiClient.php +++ b/src/Testing/Doubles/FakeMollieApiClient.php @@ -6,14 +6,21 @@ use Exception; use Illuminate\Contracts\Foundation\Application; +use Mollie\Api\Exceptions\ApiException; use Mollie\Api\MollieApiClient; use stdClass; final class FakeMollieApiClient extends MollieApiClient { + /** + * @throws ApiException + */ public static function fake(Application $app): self { - return $app->instance(self::class, new self()); + $mollie = new self(); + $mollie->setApiKey($app['config']->get('mollie.key')); + + return $app->instance(MollieApiClient::class, $mollie); } public function performHttpCall($httpMethod, $apiMethod, $httpBody = null): stdClass From fb126d4e85ecef1861be06e46e047f2fc17abdd4 Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Mon, 22 Apr 2024 11:01:31 +0200 Subject: [PATCH 11/39] Upgrade code to php81 --- src/Events/MollieOrderWasUpdated.php | 24 ++++++++----------- src/Events/MolliePaymentWasUpdated.php | 24 ++++++++----------- src/Orders/WebhookCallOrderHistory.php | 9 +++---- src/Orders/WebhookCallOrderHistoryTest.php | 2 +- src/Payments/WebhookCallPaymentHistory.php | 9 +++---- .../WebhookCallPaymentHistoryTest.php | 2 +- .../LatestMollieWebhookCallByResourceId.php | 4 ++-- 7 files changed, 30 insertions(+), 44 deletions(-) diff --git a/src/Events/MollieOrderWasUpdated.php b/src/Events/MollieOrderWasUpdated.php index 9d29379..cf266a5 100644 --- a/src/Events/MollieOrderWasUpdated.php +++ b/src/Events/MollieOrderWasUpdated.php @@ -13,20 +13,16 @@ final class MollieOrderWasUpdated implements MollieResourceStatusWasUpdated { use SerializesModels; - /** - * @readonly - */ - public OrderId $orderId; - - /** - * @readonly - */ - public WebhookCall $webhookCall; - - public function __construct(OrderId $orderId, WebhookCall $webhookCall) - { - $this->orderId = $orderId; - $this->webhookCall = $webhookCall; + public function __construct( + /** + * @readonly + */ + public OrderId $orderId, + /** + * @readonly + */ + public WebhookCall $webhookCall + ) { } public function resourceId(): ResourceId diff --git a/src/Events/MolliePaymentWasUpdated.php b/src/Events/MolliePaymentWasUpdated.php index 4ccd9ac..049106f 100644 --- a/src/Events/MolliePaymentWasUpdated.php +++ b/src/Events/MolliePaymentWasUpdated.php @@ -13,20 +13,16 @@ final class MolliePaymentWasUpdated implements MollieResourceStatusWasUpdated { use SerializesModels; - /** - * @readonly - */ - public PaymentId $paymentId; - - /** - * @readonly - */ - public WebhookCall $webhookCall; - - public function __construct(PaymentId $paymentId, WebhookCall $webhookCall) - { - $this->paymentId = $paymentId; - $this->webhookCall = $webhookCall; + public function __construct( + /** + * @readonly + */ + public PaymentId $paymentId, + /** + * @readonly + */ + public WebhookCall $webhookCall + ) { } public function resourceId(): ResourceId diff --git a/src/Orders/WebhookCallOrderHistory.php b/src/Orders/WebhookCallOrderHistory.php index 0661bca..01547de 100644 --- a/src/Orders/WebhookCallOrderHistory.php +++ b/src/Orders/WebhookCallOrderHistory.php @@ -16,12 +16,9 @@ final class WebhookCallOrderHistory implements OrderHistory { use PersistsChangesToOngoingWebhookCallPayload; - private LatestMollieWebhookCallByResourceId $latestMollieWebhookCallByResourceId; - - public function __construct(LatestMollieWebhookCallByResourceId $latestMollieWebhookCallByResourceId) - { - $this->latestMollieWebhookCallByResourceId = $latestMollieWebhookCallByResourceId; - } + public function __construct( + private LatestMollieWebhookCallByResourceId $latestMollieWebhookCallByResourceId, + ) {} public function hasLatestStatusForOrder(OrderId $orderId, string $status, WebhookCall $ongoingWebhookCall): bool { diff --git a/src/Orders/WebhookCallOrderHistoryTest.php b/src/Orders/WebhookCallOrderHistoryTest.php index 9d0e721..92ced68 100644 --- a/src/Orders/WebhookCallOrderHistoryTest.php +++ b/src/Orders/WebhookCallOrderHistoryTest.php @@ -17,7 +17,7 @@ final class WebhookCallOrderHistoryTest extends IntegrationTestCase public function orderWebhookCallHistory(): Generator { foreach (FakeOrder::STATUSES as $orderStatus) { - yield from $this->resourceWebhookCallHistory($orderStatus, [$this, 'randomOrderStatusExcept']); + yield from $this->resourceWebhookCallHistory($orderStatus, $this->randomOrderStatusExcept(...)); } } diff --git a/src/Payments/WebhookCallPaymentHistory.php b/src/Payments/WebhookCallPaymentHistory.php index 9de2313..a8d56b0 100644 --- a/src/Payments/WebhookCallPaymentHistory.php +++ b/src/Payments/WebhookCallPaymentHistory.php @@ -16,12 +16,9 @@ final class WebhookCallPaymentHistory implements PaymentHistory { use PersistsChangesToOngoingWebhookCallPayload; - private LatestMollieWebhookCallByResourceId $latestMollieWebhookCallByResourceId; - - public function __construct(LatestMollieWebhookCallByResourceId $latestMollieWebhookCallByResourceId) - { - $this->latestMollieWebhookCallByResourceId = $latestMollieWebhookCallByResourceId; - } + public function __construct( + private LatestMollieWebhookCallByResourceId $latestMollieWebhookCallByResourceId, + ) {} public function hasLatestStatusForPayment( PaymentId $paymentId, diff --git a/src/Payments/WebhookCallPaymentHistoryTest.php b/src/Payments/WebhookCallPaymentHistoryTest.php index b222f87..a74fa44 100644 --- a/src/Payments/WebhookCallPaymentHistoryTest.php +++ b/src/Payments/WebhookCallPaymentHistoryTest.php @@ -17,7 +17,7 @@ final class WebhookCallPaymentHistoryTest extends IntegrationTestCase public function paymentWebhookCallHistory(): Generator { foreach (FakePayment::STATUSES as $paymentStatus) { - yield from $this->resourceWebhookCallHistory($paymentStatus, [$this, 'randomPaymentStatusExcept']); + yield from $this->resourceWebhookCallHistory($paymentStatus, $this->randomPaymentStatusExcept(...)); } } diff --git a/src/Queries/LatestMollieWebhookCallByResourceId.php b/src/Queries/LatestMollieWebhookCallByResourceId.php index ea4ab6f..012258f 100644 --- a/src/Queries/LatestMollieWebhookCallByResourceId.php +++ b/src/Queries/LatestMollieWebhookCallByResourceId.php @@ -22,8 +22,8 @@ public function find( ->where('id', '!=', $ignoreWebhookCall->getKey()) ->where('name', MollieSignatureValidator::NAME) ->where('payload', 'LIKE', "%\"id\":\"{$resourceId->value()}\"%") - ->when($payloadFragment, Closure::fromCallable([$this, 'filterByPayloadFragment'])) - ->where(Closure::fromCallable([$this, 'ignoreFailedWebhookCalls'])) + ->when($payloadFragment, ($this->filterByPayloadFragment(...))(...)) + ->where(($this->ignoreFailedWebhookCalls(...))(...)) ->orderBy('created_at', 'desc') ->orderBy('id', 'desc') ->first(); From 1bf9ffa1d8c1a3eafc316f77bbfbb3326d6720d1 Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Mon, 22 Apr 2024 11:46:40 +0200 Subject: [PATCH 12/39] Update workflow --- .github/workflows/quality-assurance.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/quality-assurance.yml b/.github/workflows/quality-assurance.yml index 0357202..4f52c32 100644 --- a/.github/workflows/quality-assurance.yml +++ b/.github/workflows/quality-assurance.yml @@ -9,13 +9,15 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest] - php: [8.0, 7.4] - laravel: [^8.0, ^7.0] + php: [8.1, 8.2, 8.3] + laravel: [^11.0, ^10.0, ^9.0] include: - - laravel: ^8.0 - testbench: ^6.0 - - laravel: ^7.0 - testbench: ^5.0 + - laravel: ^11.0 + testbench: ^8.0 + - laravel: ^10.0 + testbench: ^8.0 + - laravel: ^9.0 + testbench: ^7.8 name: P${{ matrix.php }} - L${{ matrix.laravel }} steps: - name: Checkout code From 74e5335f41e7d0e9760d8916be4ae17c918897bf Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Mon, 22 Apr 2024 11:53:10 +0200 Subject: [PATCH 13/39] Update checkout version in workflow --- .github/workflows/quality-assurance.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/quality-assurance.yml b/.github/workflows/quality-assurance.yml index 4f52c32..6c59fbb 100644 --- a/.github/workflows/quality-assurance.yml +++ b/.github/workflows/quality-assurance.yml @@ -21,7 +21,7 @@ jobs: name: P${{ matrix.php }} - L${{ matrix.laravel }} steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v4 - name: Setup PHP uses: shivammathur/setup-php@v2 From 898805c82867e38e4085821d6a644d32ac2501dc Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Mon, 22 Apr 2024 11:58:16 +0200 Subject: [PATCH 14/39] Remove versions --- .github/workflows/quality-assurance.yml | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/quality-assurance.yml b/.github/workflows/quality-assurance.yml index 6c59fbb..0fcf549 100644 --- a/.github/workflows/quality-assurance.yml +++ b/.github/workflows/quality-assurance.yml @@ -10,12 +10,8 @@ jobs: matrix: os: [ubuntu-latest] php: [8.1, 8.2, 8.3] - laravel: [^11.0, ^10.0, ^9.0] + laravel: [^9.0] include: - - laravel: ^11.0 - testbench: ^8.0 - - laravel: ^10.0 - testbench: ^8.0 - laravel: ^9.0 testbench: ^7.8 name: P${{ matrix.php }} - L${{ matrix.laravel }} From 6c7c9e06a14dc2afe4a0bab1d1e5b7a4b3dea1e0 Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Mon, 22 Apr 2024 09:58:44 +0000 Subject: [PATCH 15/39] Fix code style violations --- src/Orders/WebhookCallOrderHistory.php | 3 ++- src/Payments/WebhookCallPaymentHistory.php | 3 ++- src/Queries/LatestMollieWebhookCallByResourceId.php | 1 - 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Orders/WebhookCallOrderHistory.php b/src/Orders/WebhookCallOrderHistory.php index 01547de..a32ed4e 100644 --- a/src/Orders/WebhookCallOrderHistory.php +++ b/src/Orders/WebhookCallOrderHistory.php @@ -18,7 +18,8 @@ final class WebhookCallOrderHistory implements OrderHistory public function __construct( private LatestMollieWebhookCallByResourceId $latestMollieWebhookCallByResourceId, - ) {} + ) { + } public function hasLatestStatusForOrder(OrderId $orderId, string $status, WebhookCall $ongoingWebhookCall): bool { diff --git a/src/Payments/WebhookCallPaymentHistory.php b/src/Payments/WebhookCallPaymentHistory.php index a8d56b0..d306092 100644 --- a/src/Payments/WebhookCallPaymentHistory.php +++ b/src/Payments/WebhookCallPaymentHistory.php @@ -18,7 +18,8 @@ final class WebhookCallPaymentHistory implements PaymentHistory public function __construct( private LatestMollieWebhookCallByResourceId $latestMollieWebhookCallByResourceId, - ) {} + ) { + } public function hasLatestStatusForPayment( PaymentId $paymentId, diff --git a/src/Queries/LatestMollieWebhookCallByResourceId.php b/src/Queries/LatestMollieWebhookCallByResourceId.php index 012258f..f7e65be 100644 --- a/src/Queries/LatestMollieWebhookCallByResourceId.php +++ b/src/Queries/LatestMollieWebhookCallByResourceId.php @@ -4,7 +4,6 @@ namespace Craftzing\Laravel\MollieWebhooks\Queries; -use Closure; use Craftzing\Laravel\MollieWebhooks\Http\MollieSignatureValidator; use Craftzing\Laravel\MollieWebhooks\ResourceId; use Craftzing\Laravel\MollieWebhooks\WebhookPayloadFragment; From 251d619514eb57a3b14e6bb49844ce486623f57f Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Mon, 22 Apr 2024 12:04:30 +0200 Subject: [PATCH 16/39] Specify illuminate support version in workflow --- .github/workflows/quality-assurance.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/quality-assurance.yml b/.github/workflows/quality-assurance.yml index 0fcf549..61770d1 100644 --- a/.github/workflows/quality-assurance.yml +++ b/.github/workflows/quality-assurance.yml @@ -28,7 +28,7 @@ jobs: - name: Install dependencies run: | - composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update + composer require "laravel/framework:${{ matrix.laravel }}" "illuminate/support:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update composer update --prefer-dist --no-interaction - name: Run tests From ecfc5e0144d3c6c81179fc1d93cbd8efcdfee25a Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Mon, 22 Apr 2024 12:09:30 +0200 Subject: [PATCH 17/39] Drop support for laravel 9 --- .github/workflows/quality-assurance.yml | 6 +++--- composer.json | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/quality-assurance.yml b/.github/workflows/quality-assurance.yml index 61770d1..899ed50 100644 --- a/.github/workflows/quality-assurance.yml +++ b/.github/workflows/quality-assurance.yml @@ -10,9 +10,9 @@ jobs: matrix: os: [ubuntu-latest] php: [8.1, 8.2, 8.3] - laravel: [^9.0] + laravel: [^10.0] include: - - laravel: ^9.0 + - laravel: ^10.0 testbench: ^7.8 name: P${{ matrix.php }} - L${{ matrix.laravel }} steps: @@ -28,7 +28,7 @@ jobs: - name: Install dependencies run: | - composer require "laravel/framework:${{ matrix.laravel }}" "illuminate/support:${{ matrix.laravel }}" "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 87ea05f..5ef83ce 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "require": { "php": "^8.1|^8.2|^8.3", "ext-json": "*", - "illuminate/support": "^9.0|^10.0|^11.0", + "illuminate/support": "^10.0|^11.0", "mollie/laravel-mollie": "^3.0", "spatie/laravel-webhook-client": "^3.0" }, From 094e5c7e04f9ac1a02db6b53b75a6da7bcc17f7a Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Mon, 22 Apr 2024 12:11:03 +0200 Subject: [PATCH 18/39] Replace testbench version --- .github/workflows/quality-assurance.yml | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/quality-assurance.yml b/.github/workflows/quality-assurance.yml index 899ed50..c87342c 100644 --- a/.github/workflows/quality-assurance.yml +++ b/.github/workflows/quality-assurance.yml @@ -13,7 +13,7 @@ jobs: laravel: [^10.0] include: - laravel: ^10.0 - testbench: ^7.8 + testbench: ^8.0 name: P${{ matrix.php }} - L${{ matrix.laravel }} steps: - name: Checkout code diff --git a/composer.json b/composer.json index 5ef83ce..1ca6382 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ "require-dev": { "friendsofphp/php-cs-fixer": "^3.54", "laravel/legacy-factories": "^1.1", - "orchestra/testbench": "^7.8|^8.0", + "orchestra/testbench": "^8.0", "phpstan/phpstan": "^1.8", "phpunit/phpunit": "^9.5", "rector/rector": "^1.0" From 4becf549adb7679fd59390bfb63b3b0fad831121 Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Mon, 22 Apr 2024 12:12:57 +0200 Subject: [PATCH 19/39] Update action version --- .github/workflows/quality-assurance.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/quality-assurance.yml b/.github/workflows/quality-assurance.yml index c87342c..62ad948 100644 --- a/.github/workflows/quality-assurance.yml +++ b/.github/workflows/quality-assurance.yml @@ -35,7 +35,7 @@ jobs: run: vendor/bin/phpunit --verbose --coverage-clover=coverage.clover - name: Publish code coverage - uses: paambaati/codeclimate-action@v2.7.5 + uses: paambaati/codeclimate-action@v5.0.0 env: CC_TEST_REPORTER_ID: ${{ secrets.CODECLIMATE_TEST_REPORTER_ID }} with: From 3e88ba0ab707131ed1669ea4e7787aceac47e746 Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Mon, 22 Apr 2024 12:17:23 +0200 Subject: [PATCH 20/39] Remove phpstan restriction in workflow --- .github/workflows/quality-assurance.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/quality-assurance.yml b/.github/workflows/quality-assurance.yml index 62ad948..5b9a9fc 100644 --- a/.github/workflows/quality-assurance.yml +++ b/.github/workflows/quality-assurance.yml @@ -44,4 +44,3 @@ jobs: - name: Run PHPStan analysis run: vendor/bin/phpstan analyse --memory-limit=-1 - if: ${{ matrix.php == '7.4' }} From 37ba826408367ce1b6f9132e4da5db8f1b04575e Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Mon, 22 Apr 2024 12:22:16 +0200 Subject: [PATCH 21/39] Add missing command --- .github/workflows/quality-assurance.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/quality-assurance.yml b/.github/workflows/quality-assurance.yml index 5b9a9fc..a33678c 100644 --- a/.github/workflows/quality-assurance.yml +++ b/.github/workflows/quality-assurance.yml @@ -39,6 +39,7 @@ jobs: env: CC_TEST_REPORTER_ID: ${{ secrets.CODECLIMATE_TEST_REPORTER_ID }} with: + coverageCommand: vendor/bin/phpunit --verbose --coverage-clover=coverage.clover coverageLocations: ${{github.workspace}}/*.clover:clover debug: true From 6aeba16c2ce802654910aa5de544516bf8ce39a2 Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Mon, 22 Apr 2024 12:24:11 +0200 Subject: [PATCH 22/39] Add laravel 11 to matrix --- .github/workflows/quality-assurance.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/quality-assurance.yml b/.github/workflows/quality-assurance.yml index a33678c..3ee24c2 100644 --- a/.github/workflows/quality-assurance.yml +++ b/.github/workflows/quality-assurance.yml @@ -10,8 +10,10 @@ jobs: matrix: os: [ubuntu-latest] php: [8.1, 8.2, 8.3] - laravel: [^10.0] + laravel: [^10.0, ^11.0] include: + - laravel: ^11.0 + testbench: ^8.0 - laravel: ^10.0 testbench: ^8.0 name: P${{ matrix.php }} - L${{ matrix.laravel }} From 142bdfc25353735e87cd40b9c8d356d68022245c Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Mon, 22 Apr 2024 12:25:59 +0200 Subject: [PATCH 23/39] Change testbench version for laravel 11 --- .github/workflows/quality-assurance.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/quality-assurance.yml b/.github/workflows/quality-assurance.yml index 3ee24c2..59916df 100644 --- a/.github/workflows/quality-assurance.yml +++ b/.github/workflows/quality-assurance.yml @@ -13,7 +13,7 @@ jobs: laravel: [^10.0, ^11.0] include: - laravel: ^11.0 - testbench: ^8.0 + testbench: ^9.0 - laravel: ^10.0 testbench: ^8.0 name: P${{ matrix.php }} - L${{ matrix.laravel }} From 5dd31a7c2efff0e3aa58c6230e7a93dc27c47eac Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Mon, 22 Apr 2024 12:36:13 +0200 Subject: [PATCH 24/39] Drop php81 support --- .github/workflows/quality-assurance.yml | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/quality-assurance.yml b/.github/workflows/quality-assurance.yml index 59916df..960d777 100644 --- a/.github/workflows/quality-assurance.yml +++ b/.github/workflows/quality-assurance.yml @@ -9,7 +9,7 @@ jobs: fail-fast: true matrix: os: [ubuntu-latest] - php: [8.1, 8.2, 8.3] + php: [8.2, 8.3] laravel: [^10.0, ^11.0] include: - laravel: ^11.0 diff --git a/composer.json b/composer.json index 1ca6382..84ab541 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,7 @@ } ], "require": { - "php": "^8.1|^8.2|^8.3", + "php": "^8.2|^8.3", "ext-json": "*", "illuminate/support": "^10.0|^11.0", "mollie/laravel-mollie": "^3.0", From 0b37230784c949d6cfbb4809f4dcad0a270337b4 Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Mon, 22 Apr 2024 16:03:34 +0200 Subject: [PATCH 25/39] Add phpunit version to matrix --- .github/workflows/quality-assurance.yml | 4 +++- composer.json | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/quality-assurance.yml b/.github/workflows/quality-assurance.yml index 960d777..089576f 100644 --- a/.github/workflows/quality-assurance.yml +++ b/.github/workflows/quality-assurance.yml @@ -13,8 +13,10 @@ 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: @@ -30,7 +32,7 @@ jobs: - name: Install dependencies run: | - composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update + composer require "laravel/framework:${{ matrix.laravel }}" "phpunit/phpunit:${{ matrix.phpunit }}" "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 84ab541..e4c8fab 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", + "phpunit/phpunit": "^9.5|^10.0", "rector/rector": "^1.0" }, "autoload": { From efa3cc08f2fcbfe6d7e79b05b6b48a40956978e5 Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Mon, 22 Apr 2024 16:11:19 +0200 Subject: [PATCH 26/39] Replace verbose parameter with debug --- .github/workflows/quality-assurance.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/quality-assurance.yml b/.github/workflows/quality-assurance.yml index 089576f..bd42bab 100644 --- a/.github/workflows/quality-assurance.yml +++ b/.github/workflows/quality-assurance.yml @@ -36,7 +36,7 @@ jobs: composer update --prefer-dist --no-interaction - name: Run tests - run: vendor/bin/phpunit --verbose --coverage-clover=coverage.clover + run: vendor/bin/phpunit --debug --coverage-clover=coverage.clover - name: Publish code coverage uses: paambaati/codeclimate-action@v5.0.0 From d3ac62de8e8a169532ac9576ef19d09b99f15308 Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Mon, 22 Apr 2024 17:50:53 +0200 Subject: [PATCH 27/39] Upgrade phpunit --- .github/workflows/quality-assurance.yml | 4 +- composer.json | 2 +- phpunit.xml.dist | 51 ++++++++++--------- src/Commands/ProcessMollieWebhookTest.php | 14 ++--- .../HandleMollieWebhooksRequestTest.php | 4 +- src/Orders/OrderIdTest.php | 6 +-- src/Orders/WebhookCallOrderHistoryTest.php | 4 +- src/Payments/PaymentIdTest.php | 6 +-- .../WebhookCallPaymentHistoryTest.php | 4 +- ...atestMollieWebhookCallByResourceIdTest.php | 10 ++-- src/Refunds/RefundIdTest.php | 6 +-- .../SubscribeToMollieOrderRefundsTest.php | 2 +- ...ubscribeToMollieOrderStatusChangesTest.php | 16 +++--- .../SubscribeToMolliePaymentRefundsTest.php | 2 +- ...scribeToMolliePaymentStatusChangesTest.php | 14 ++--- src/Testing/Concerns/FakesMollie.php | 6 +-- .../ProvidesResourceWebhookCallHistory.php | 6 +-- src/Testing/Doubles/FakeOrder.php | 2 +- .../{TruthTest.php => HandleAssertions.php} | 4 +- src/Testing/PrefixedResourceIdTestCase.php | 46 ++++++++++------- src/WebhookPayloadFragmentTest.php | 4 +- 21 files changed, 111 insertions(+), 102 deletions(-) rename src/Testing/{TruthTest.php => HandleAssertions.php} (81%) 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' => [ [], From 1c683e930f88d698f97f477f2f2a006a63c6ccf7 Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Mon, 22 Apr 2024 18:08:37 +0200 Subject: [PATCH 28/39] Fix coverage command --- .github/workflows/quality-assurance.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/quality-assurance.yml b/.github/workflows/quality-assurance.yml index 851b217..30743ce 100644 --- a/.github/workflows/quality-assurance.yml +++ b/.github/workflows/quality-assurance.yml @@ -34,14 +34,14 @@ jobs: composer update --prefer-dist --no-interaction - name: Run tests - run: vendor/bin/phpunit --debug --coverage-clover=coverage.clover + run: vendor/bin/phpunit --coverage-clover=coverage.clover - name: Publish code coverage uses: paambaati/codeclimate-action@v5.0.0 env: CC_TEST_REPORTER_ID: ${{ secrets.CODECLIMATE_TEST_REPORTER_ID }} with: - coverageCommand: vendor/bin/phpunit --verbose --coverage-clover=coverage.clover + coverageCommand: vendor/bin/phpunit --debug --coverage-clover=coverage.clover coverageLocations: ${{github.workspace}}/*.clover:clover debug: true From 4482c649113033353846748d95bb86236450cd5f Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Mon, 22 Apr 2024 18:12:57 +0200 Subject: [PATCH 29/39] Remove debug parameter --- .github/workflows/quality-assurance.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/quality-assurance.yml b/.github/workflows/quality-assurance.yml index 30743ce..e29e36a 100644 --- a/.github/workflows/quality-assurance.yml +++ b/.github/workflows/quality-assurance.yml @@ -41,7 +41,7 @@ jobs: env: CC_TEST_REPORTER_ID: ${{ secrets.CODECLIMATE_TEST_REPORTER_ID }} with: - coverageCommand: vendor/bin/phpunit --debug --coverage-clover=coverage.clover + coverageCommand: vendor/bin/phpunit --coverage-clover=coverage.clover coverageLocations: ${{github.workspace}}/*.clover:clover debug: true From dac4cea713d8e9d7e39958a151d883efbc813907 Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Mon, 22 Apr 2024 16:14:11 +0000 Subject: [PATCH 30/39] Fix code style violations --- src/Commands/ProcessMollieWebhookTest.php | 2 +- src/Subscribers/SubscribeToMollieOrderStatusChangesTest.php | 2 +- src/Subscribers/SubscribeToMolliePaymentStatusChangesTest.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Commands/ProcessMollieWebhookTest.php b/src/Commands/ProcessMollieWebhookTest.php index ec433ac..79ce501 100644 --- a/src/Commands/ProcessMollieWebhookTest.php +++ b/src/Commands/ProcessMollieWebhookTest.php @@ -8,8 +8,8 @@ use Craftzing\Laravel\MollieWebhooks\Events\MolliePaymentWasUpdated; use Craftzing\Laravel\MollieWebhooks\Events\MollieResourceStatusWasUpdated; use Craftzing\Laravel\MollieWebhooks\Exceptions\UnexpectedWebhookPayload; -use Craftzing\Laravel\MollieWebhooks\Testing\IntegrationTestCase; use Craftzing\Laravel\MollieWebhooks\Testing\HandleAssertions; +use Craftzing\Laravel\MollieWebhooks\Testing\IntegrationTestCase; use Exception; use Generator; use Illuminate\Contracts\Queue\ShouldQueue; diff --git a/src/Subscribers/SubscribeToMollieOrderStatusChangesTest.php b/src/Subscribers/SubscribeToMollieOrderStatusChangesTest.php index 06d1636..b61ed41 100644 --- a/src/Subscribers/SubscribeToMollieOrderStatusChangesTest.php +++ b/src/Subscribers/SubscribeToMollieOrderStatusChangesTest.php @@ -15,8 +15,8 @@ use Craftzing\Laravel\MollieWebhooks\Testing\Doubles\FakeMollieWebhookCall; 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\HandleAssertions; +use Craftzing\Laravel\MollieWebhooks\Testing\IntegrationTestCase; use Generator; use Illuminate\Events\CallQueuedListener; use Illuminate\Support\Facades\Event; diff --git a/src/Subscribers/SubscribeToMolliePaymentStatusChangesTest.php b/src/Subscribers/SubscribeToMolliePaymentStatusChangesTest.php index 3b5275d..e198cdb 100644 --- a/src/Subscribers/SubscribeToMolliePaymentStatusChangesTest.php +++ b/src/Subscribers/SubscribeToMolliePaymentStatusChangesTest.php @@ -14,8 +14,8 @@ use Craftzing\Laravel\MollieWebhooks\Testing\Doubles\FakeMollieWebhookCall; 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\HandleAssertions; +use Craftzing\Laravel\MollieWebhooks\Testing\IntegrationTestCase; use Generator; use Illuminate\Events\CallQueuedListener; use Illuminate\Support\Facades\Event; From d0841be8f91cd53000ea8e0737a0d7904fbf402e Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Wed, 15 May 2024 11:18:20 +0200 Subject: [PATCH 31/39] Add php cs custom fixers --- .php-cs-fixer.dist.php | 3 +++ composer.json | 1 + 2 files changed, 4 insertions(+) diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index e1bddc7..47c353f 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -8,6 +8,7 @@ return (new PhpCsFixer\Config()) ->setRiskyAllowed(true) + ->registerCustomFixers(new PhpCsFixerCustomFixers\Fixers()) ->setRules([ '@PSR2' => true, 'array_syntax' => ['syntax' => 'short'], @@ -31,5 +32,7 @@ 'keep_multiple_spaces_after_comma' => true, ], 'void_return' => true, + PhpCsFixerCustomFixers\Fixer\MultilinePromotedPropertiesFixer::name() => true, + PhpCsFixerCustomFixers\Fixer\ConstructorEmptyBracesFixer::name() => true, ]) ->setFinder($finder); diff --git a/composer.json b/composer.json index 721e19b..da3dd63 100644 --- a/composer.json +++ b/composer.json @@ -19,6 +19,7 @@ }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.54", + "kubawerlos/php-cs-fixer-custom-fixers": "^3.21", "laravel/legacy-factories": "^1.1", "orchestra/testbench": "^8.0", "phpstan/phpstan": "^1.8", From 279761880a64e762a5f56155df5ea18465d78b1d Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Wed, 15 May 2024 11:20:11 +0200 Subject: [PATCH 32/39] Add style fix for constructors --- src/Events/MollieOrderWasUpdated.php | 3 +-- src/Events/MolliePaymentWasUpdated.php | 3 +-- src/Orders/WebhookCallOrderHistory.php | 3 +-- src/Payments/WebhookCallPaymentHistory.php | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Events/MollieOrderWasUpdated.php b/src/Events/MollieOrderWasUpdated.php index cf266a5..c7df93f 100644 --- a/src/Events/MollieOrderWasUpdated.php +++ b/src/Events/MollieOrderWasUpdated.php @@ -22,8 +22,7 @@ public function __construct( * @readonly */ public WebhookCall $webhookCall - ) { - } + ) {} public function resourceId(): ResourceId { diff --git a/src/Events/MolliePaymentWasUpdated.php b/src/Events/MolliePaymentWasUpdated.php index 049106f..94230c5 100644 --- a/src/Events/MolliePaymentWasUpdated.php +++ b/src/Events/MolliePaymentWasUpdated.php @@ -22,8 +22,7 @@ public function __construct( * @readonly */ public WebhookCall $webhookCall - ) { - } + ) {} public function resourceId(): ResourceId { diff --git a/src/Orders/WebhookCallOrderHistory.php b/src/Orders/WebhookCallOrderHistory.php index a32ed4e..01547de 100644 --- a/src/Orders/WebhookCallOrderHistory.php +++ b/src/Orders/WebhookCallOrderHistory.php @@ -18,8 +18,7 @@ final class WebhookCallOrderHistory implements OrderHistory public function __construct( private LatestMollieWebhookCallByResourceId $latestMollieWebhookCallByResourceId, - ) { - } + ) {} public function hasLatestStatusForOrder(OrderId $orderId, string $status, WebhookCall $ongoingWebhookCall): bool { diff --git a/src/Payments/WebhookCallPaymentHistory.php b/src/Payments/WebhookCallPaymentHistory.php index d306092..a8d56b0 100644 --- a/src/Payments/WebhookCallPaymentHistory.php +++ b/src/Payments/WebhookCallPaymentHistory.php @@ -18,8 +18,7 @@ final class WebhookCallPaymentHistory implements PaymentHistory public function __construct( private LatestMollieWebhookCallByResourceId $latestMollieWebhookCallByResourceId, - ) { - } + ) {} public function hasLatestStatusForPayment( PaymentId $paymentId, From 6009b74d0e7ee7dcd177a1ef6b9e771a94af40c0 Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Wed, 15 May 2024 11:53:50 +0200 Subject: [PATCH 33/39] Make properties readonly --- src/Events/ExposesOrderId.php | 20 -------------- src/Events/ExposesPaymentId.php | 20 -------------- src/Events/ExposesRefundId.php | 27 ------------------- .../MollieOrderStatusChangedToAuthorized.php | 6 ++++- .../MollieOrderStatusChangedToCanceled.php | 6 ++++- .../MollieOrderStatusChangedToCompleted.php | 6 ++++- .../MollieOrderStatusChangedToExpired.php | 6 ++++- src/Events/MollieOrderStatusChangedToPaid.php | 6 ++++- src/Events/MollieOrderWasUpdated.php | 10 ++----- .../MolliePaymentStatusChangedToCanceled.php | 6 ++++- .../MolliePaymentStatusChangedToExpired.php | 6 ++++- .../MolliePaymentStatusChangedToFailed.php | 6 ++++- .../MolliePaymentStatusChangedToPaid.php | 6 ++++- src/Events/MolliePaymentWasUpdated.php | 10 ++----- .../MollieRefundStatusChangedToFailed.php | 8 +++++- .../MollieRefundStatusChangedToPending.php | 8 +++++- .../MollieRefundStatusChangedToProcessing.php | 8 +++++- .../MollieRefundStatusChangedToQueued.php | 8 +++++- .../MollieRefundStatusChangedToRefunded.php | 8 +++++- src/HasIdPrefix.php | 8 +++--- src/Orders/WebhookCallOrderHistory.php | 2 +- src/Payments/WebhookCallPaymentHistory.php | 2 +- .../DispatchesRefundEventsForResources.php | 2 +- .../SubscribeToMollieOrderRefunds.php | 2 +- .../SubscribeToMolliePaymentRefunds.php | 2 +- 25 files changed, 93 insertions(+), 106 deletions(-) delete mode 100644 src/Events/ExposesOrderId.php delete mode 100644 src/Events/ExposesPaymentId.php delete mode 100644 src/Events/ExposesRefundId.php diff --git a/src/Events/ExposesOrderId.php b/src/Events/ExposesOrderId.php deleted file mode 100644 index ddb9876..0000000 --- a/src/Events/ExposesOrderId.php +++ /dev/null @@ -1,20 +0,0 @@ -orderId = $orderId; - } -} diff --git a/src/Events/ExposesPaymentId.php b/src/Events/ExposesPaymentId.php deleted file mode 100644 index 5841c7d..0000000 --- a/src/Events/ExposesPaymentId.php +++ /dev/null @@ -1,20 +0,0 @@ -paymentId = $paymentId; - } -} diff --git a/src/Events/ExposesRefundId.php b/src/Events/ExposesRefundId.php deleted file mode 100644 index c77a892..0000000 --- a/src/Events/ExposesRefundId.php +++ /dev/null @@ -1,27 +0,0 @@ -refundId = $refundId; - $this->resourceId = $resourceId; - } -} diff --git a/src/Events/MollieOrderStatusChangedToAuthorized.php b/src/Events/MollieOrderStatusChangedToAuthorized.php index 74d34da..9d5da32 100644 --- a/src/Events/MollieOrderStatusChangedToAuthorized.php +++ b/src/Events/MollieOrderStatusChangedToAuthorized.php @@ -4,7 +4,11 @@ namespace Craftzing\Laravel\MollieWebhooks\Events; +use Craftzing\Laravel\MollieWebhooks\Orders\OrderId; + final class MollieOrderStatusChangedToAuthorized { - use ExposesOrderId; + public function __construct( + public readonly OrderId $orderId, + ) {} } diff --git a/src/Events/MollieOrderStatusChangedToCanceled.php b/src/Events/MollieOrderStatusChangedToCanceled.php index dc230f1..8a9aad2 100644 --- a/src/Events/MollieOrderStatusChangedToCanceled.php +++ b/src/Events/MollieOrderStatusChangedToCanceled.php @@ -4,7 +4,11 @@ namespace Craftzing\Laravel\MollieWebhooks\Events; +use Craftzing\Laravel\MollieWebhooks\Orders\OrderId; + final class MollieOrderStatusChangedToCanceled { - use ExposesOrderId; + public function __construct( + public readonly OrderId $orderId, + ) {} } diff --git a/src/Events/MollieOrderStatusChangedToCompleted.php b/src/Events/MollieOrderStatusChangedToCompleted.php index 9cdbebd..d3ce770 100644 --- a/src/Events/MollieOrderStatusChangedToCompleted.php +++ b/src/Events/MollieOrderStatusChangedToCompleted.php @@ -4,7 +4,11 @@ namespace Craftzing\Laravel\MollieWebhooks\Events; +use Craftzing\Laravel\MollieWebhooks\Orders\OrderId; + final class MollieOrderStatusChangedToCompleted { - use ExposesOrderId; + public function __construct( + public readonly OrderId $orderId, + ) {} } diff --git a/src/Events/MollieOrderStatusChangedToExpired.php b/src/Events/MollieOrderStatusChangedToExpired.php index da25cdc..26f8e3b 100644 --- a/src/Events/MollieOrderStatusChangedToExpired.php +++ b/src/Events/MollieOrderStatusChangedToExpired.php @@ -4,7 +4,11 @@ namespace Craftzing\Laravel\MollieWebhooks\Events; +use Craftzing\Laravel\MollieWebhooks\Orders\OrderId; + final class MollieOrderStatusChangedToExpired { - use ExposesOrderId; + public function __construct( + public readonly OrderId $orderId, + ) {} } diff --git a/src/Events/MollieOrderStatusChangedToPaid.php b/src/Events/MollieOrderStatusChangedToPaid.php index cd0aaff..d4f331c 100644 --- a/src/Events/MollieOrderStatusChangedToPaid.php +++ b/src/Events/MollieOrderStatusChangedToPaid.php @@ -4,7 +4,11 @@ namespace Craftzing\Laravel\MollieWebhooks\Events; +use Craftzing\Laravel\MollieWebhooks\Orders\OrderId; + final class MollieOrderStatusChangedToPaid { - use ExposesOrderId; + public function __construct( + public readonly OrderId $orderId, + ) {} } diff --git a/src/Events/MollieOrderWasUpdated.php b/src/Events/MollieOrderWasUpdated.php index c7df93f..ac6ec37 100644 --- a/src/Events/MollieOrderWasUpdated.php +++ b/src/Events/MollieOrderWasUpdated.php @@ -14,14 +14,8 @@ final class MollieOrderWasUpdated implements MollieResourceStatusWasUpdated use SerializesModels; public function __construct( - /** - * @readonly - */ - public OrderId $orderId, - /** - * @readonly - */ - public WebhookCall $webhookCall + public readonly OrderId $orderId, + public readonly WebhookCall $webhookCall, ) {} public function resourceId(): ResourceId diff --git a/src/Events/MolliePaymentStatusChangedToCanceled.php b/src/Events/MolliePaymentStatusChangedToCanceled.php index cc803b0..d490674 100644 --- a/src/Events/MolliePaymentStatusChangedToCanceled.php +++ b/src/Events/MolliePaymentStatusChangedToCanceled.php @@ -4,7 +4,11 @@ namespace Craftzing\Laravel\MollieWebhooks\Events; +use Craftzing\Laravel\MollieWebhooks\Payments\PaymentId; + final class MolliePaymentStatusChangedToCanceled { - use ExposesPaymentId; + public function __construct( + public readonly PaymentId $paymentId, + ) {} } diff --git a/src/Events/MolliePaymentStatusChangedToExpired.php b/src/Events/MolliePaymentStatusChangedToExpired.php index dd29133..e599225 100644 --- a/src/Events/MolliePaymentStatusChangedToExpired.php +++ b/src/Events/MolliePaymentStatusChangedToExpired.php @@ -4,7 +4,11 @@ namespace Craftzing\Laravel\MollieWebhooks\Events; +use Craftzing\Laravel\MollieWebhooks\Payments\PaymentId; + final class MolliePaymentStatusChangedToExpired { - use ExposesPaymentId; + public function __construct( + public readonly PaymentId $paymentId, + ) {} } diff --git a/src/Events/MolliePaymentStatusChangedToFailed.php b/src/Events/MolliePaymentStatusChangedToFailed.php index fb38357..f3f527e 100644 --- a/src/Events/MolliePaymentStatusChangedToFailed.php +++ b/src/Events/MolliePaymentStatusChangedToFailed.php @@ -4,7 +4,11 @@ namespace Craftzing\Laravel\MollieWebhooks\Events; +use Craftzing\Laravel\MollieWebhooks\Payments\PaymentId; + final class MolliePaymentStatusChangedToFailed { - use ExposesPaymentId; + public function __construct( + public readonly PaymentId $paymentId, + ) {} } diff --git a/src/Events/MolliePaymentStatusChangedToPaid.php b/src/Events/MolliePaymentStatusChangedToPaid.php index 12ce358..af25b08 100644 --- a/src/Events/MolliePaymentStatusChangedToPaid.php +++ b/src/Events/MolliePaymentStatusChangedToPaid.php @@ -4,7 +4,11 @@ namespace Craftzing\Laravel\MollieWebhooks\Events; +use Craftzing\Laravel\MollieWebhooks\Payments\PaymentId; + final class MolliePaymentStatusChangedToPaid { - use ExposesPaymentId; + public function __construct( + public readonly PaymentId $paymentId, + ) {} } diff --git a/src/Events/MolliePaymentWasUpdated.php b/src/Events/MolliePaymentWasUpdated.php index 94230c5..31d5be1 100644 --- a/src/Events/MolliePaymentWasUpdated.php +++ b/src/Events/MolliePaymentWasUpdated.php @@ -14,14 +14,8 @@ final class MolliePaymentWasUpdated implements MollieResourceStatusWasUpdated use SerializesModels; public function __construct( - /** - * @readonly - */ - public PaymentId $paymentId, - /** - * @readonly - */ - public WebhookCall $webhookCall + public readonly PaymentId $paymentId, + public readonly WebhookCall $webhookCall, ) {} public function resourceId(): ResourceId diff --git a/src/Events/MollieRefundStatusChangedToFailed.php b/src/Events/MollieRefundStatusChangedToFailed.php index f4998f9..1aac2fc 100644 --- a/src/Events/MollieRefundStatusChangedToFailed.php +++ b/src/Events/MollieRefundStatusChangedToFailed.php @@ -4,7 +4,13 @@ namespace Craftzing\Laravel\MollieWebhooks\Events; +use Craftzing\Laravel\MollieWebhooks\Refunds\RefundId; +use Craftzing\Laravel\MollieWebhooks\ResourceId; + final class MollieRefundStatusChangedToFailed { - use ExposesRefundId; + public function __construct( + public readonly RefundId $refundId, + public readonly ResourceId $resourceId, + ) {} } diff --git a/src/Events/MollieRefundStatusChangedToPending.php b/src/Events/MollieRefundStatusChangedToPending.php index d8f14a6..31f1e51 100644 --- a/src/Events/MollieRefundStatusChangedToPending.php +++ b/src/Events/MollieRefundStatusChangedToPending.php @@ -4,7 +4,13 @@ namespace Craftzing\Laravel\MollieWebhooks\Events; +use Craftzing\Laravel\MollieWebhooks\Refunds\RefundId; +use Craftzing\Laravel\MollieWebhooks\ResourceId; + final class MollieRefundStatusChangedToPending { - use ExposesRefundId; + public function __construct( + public readonly RefundId $refundId, + public readonly ResourceId $resourceId, + ) {} } diff --git a/src/Events/MollieRefundStatusChangedToProcessing.php b/src/Events/MollieRefundStatusChangedToProcessing.php index 6c9db0b..3c12c3c 100644 --- a/src/Events/MollieRefundStatusChangedToProcessing.php +++ b/src/Events/MollieRefundStatusChangedToProcessing.php @@ -4,7 +4,13 @@ namespace Craftzing\Laravel\MollieWebhooks\Events; +use Craftzing\Laravel\MollieWebhooks\Refunds\RefundId; +use Craftzing\Laravel\MollieWebhooks\ResourceId; + final class MollieRefundStatusChangedToProcessing { - use ExposesRefundId; + public function __construct( + public readonly RefundId $refundId, + public readonly ResourceId $resourceId, + ) {} } diff --git a/src/Events/MollieRefundStatusChangedToQueued.php b/src/Events/MollieRefundStatusChangedToQueued.php index 738222a..90e6d17 100644 --- a/src/Events/MollieRefundStatusChangedToQueued.php +++ b/src/Events/MollieRefundStatusChangedToQueued.php @@ -4,7 +4,13 @@ namespace Craftzing\Laravel\MollieWebhooks\Events; +use Craftzing\Laravel\MollieWebhooks\Refunds\RefundId; +use Craftzing\Laravel\MollieWebhooks\ResourceId; + final class MollieRefundStatusChangedToQueued { - use ExposesRefundId; + public function __construct( + public readonly RefundId $refundId, + public readonly ResourceId $resourceId, + ) {} } diff --git a/src/Events/MollieRefundStatusChangedToRefunded.php b/src/Events/MollieRefundStatusChangedToRefunded.php index 8811f22..652d4cb 100644 --- a/src/Events/MollieRefundStatusChangedToRefunded.php +++ b/src/Events/MollieRefundStatusChangedToRefunded.php @@ -4,7 +4,13 @@ namespace Craftzing\Laravel\MollieWebhooks\Events; +use Craftzing\Laravel\MollieWebhooks\Refunds\RefundId; +use Craftzing\Laravel\MollieWebhooks\ResourceId; + final class MollieRefundStatusChangedToRefunded { - use ExposesRefundId; + public function __construct( + public readonly RefundId $refundId, + public readonly ResourceId $resourceId, + ) {} } diff --git a/src/HasIdPrefix.php b/src/HasIdPrefix.php index da45115..a7a8a7b 100644 --- a/src/HasIdPrefix.php +++ b/src/HasIdPrefix.php @@ -9,12 +9,12 @@ trait HasIdPrefix { - private string $value; - - private function __construct(string $value) + /** + * @throws InvalidResourceId + */ + private function __construct(private readonly string $value) { $this->failWhenPrefixIsInvalid($value); - $this->value = $value; } abstract protected function prefix(): string; diff --git a/src/Orders/WebhookCallOrderHistory.php b/src/Orders/WebhookCallOrderHistory.php index 01547de..aec1389 100644 --- a/src/Orders/WebhookCallOrderHistory.php +++ b/src/Orders/WebhookCallOrderHistory.php @@ -17,7 +17,7 @@ final class WebhookCallOrderHistory implements OrderHistory use PersistsChangesToOngoingWebhookCallPayload; public function __construct( - private LatestMollieWebhookCallByResourceId $latestMollieWebhookCallByResourceId, + private readonly LatestMollieWebhookCallByResourceId $latestMollieWebhookCallByResourceId, ) {} public function hasLatestStatusForOrder(OrderId $orderId, string $status, WebhookCall $ongoingWebhookCall): bool diff --git a/src/Payments/WebhookCallPaymentHistory.php b/src/Payments/WebhookCallPaymentHistory.php index a8d56b0..0fbc6f8 100644 --- a/src/Payments/WebhookCallPaymentHistory.php +++ b/src/Payments/WebhookCallPaymentHistory.php @@ -17,7 +17,7 @@ final class WebhookCallPaymentHistory implements PaymentHistory use PersistsChangesToOngoingWebhookCallPayload; public function __construct( - private LatestMollieWebhookCallByResourceId $latestMollieWebhookCallByResourceId, + private readonly LatestMollieWebhookCallByResourceId $latestMollieWebhookCallByResourceId, ) {} public function hasLatestStatusForPayment( diff --git a/src/Subscribers/DispatchesRefundEventsForResources.php b/src/Subscribers/DispatchesRefundEventsForResources.php index eac6c71..e3e985b 100644 --- a/src/Subscribers/DispatchesRefundEventsForResources.php +++ b/src/Subscribers/DispatchesRefundEventsForResources.php @@ -16,7 +16,7 @@ trait DispatchesRefundEventsForResources { - private Dispatcher $events; + private readonly Dispatcher $events; private function dispatchRefundEvents(ResourceId $resourceId, RefundId $refundId, Refund $refund): void { diff --git a/src/Subscribers/SubscribeToMollieOrderRefunds.php b/src/Subscribers/SubscribeToMollieOrderRefunds.php index 8997644..bc460e4 100644 --- a/src/Subscribers/SubscribeToMollieOrderRefunds.php +++ b/src/Subscribers/SubscribeToMollieOrderRefunds.php @@ -17,7 +17,7 @@ final class SubscribeToMollieOrderRefunds implements ShouldQueue { use DispatchesRefundEventsForResources; - private OrderEndpoint $orders; + private readonly OrderEndpoint $orders; public function __construct( MollieApiClient $mollie, diff --git a/src/Subscribers/SubscribeToMolliePaymentRefunds.php b/src/Subscribers/SubscribeToMolliePaymentRefunds.php index 89d7100..5457c38 100644 --- a/src/Subscribers/SubscribeToMolliePaymentRefunds.php +++ b/src/Subscribers/SubscribeToMolliePaymentRefunds.php @@ -16,7 +16,7 @@ final class SubscribeToMolliePaymentRefunds implements ShouldQueue { use DispatchesRefundEventsForResources; - private PaymentEndpoint $payments; + private readonly PaymentEndpoint $payments; public function __construct( MollieApiClient $mollie, From b28f7e19a5483c825241acf4304f6c4df8fc751f Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Wed, 15 May 2024 12:20:47 +0200 Subject: [PATCH 34/39] Make phpstan in pipeline conditional --- .github/workflows/quality-assurance.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/quality-assurance.yml b/.github/workflows/quality-assurance.yml index e29e36a..6ae1e9c 100644 --- a/.github/workflows/quality-assurance.yml +++ b/.github/workflows/quality-assurance.yml @@ -47,3 +47,4 @@ jobs: - name: Run PHPStan analysis run: vendor/bin/phpstan analyse --memory-limit=-1 + if: ${{ matrix.php == '8.2' }} From 666c6b953885d67be547495ad4a21568c69a5e34 Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Wed, 15 May 2024 12:23:06 +0200 Subject: [PATCH 35/39] Add style fix --- src/Subscribers/SubscribeToMollieOrderStatusChanges.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Subscribers/SubscribeToMollieOrderStatusChanges.php b/src/Subscribers/SubscribeToMollieOrderStatusChanges.php index 7a4f657..62b605a 100644 --- a/src/Subscribers/SubscribeToMollieOrderStatusChanges.php +++ b/src/Subscribers/SubscribeToMollieOrderStatusChanges.php @@ -24,7 +24,7 @@ final class SubscribeToMollieOrderStatusChanges implements ShouldQueue public function __construct( MollieApiClient $mollie, private readonly Dispatcher $events, - private readonly OrderHistory $orderHistory + private readonly OrderHistory $orderHistory, ) { $this->orders = $mollie->orders; } From b80f4331528c3c3ee3dc0addbe23f5a688036478 Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Wed, 15 May 2024 12:25:00 +0200 Subject: [PATCH 36/39] Simplify code --- src/Queries/LatestMollieWebhookCallByResourceId.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Queries/LatestMollieWebhookCallByResourceId.php b/src/Queries/LatestMollieWebhookCallByResourceId.php index f7e65be..22bf801 100644 --- a/src/Queries/LatestMollieWebhookCallByResourceId.php +++ b/src/Queries/LatestMollieWebhookCallByResourceId.php @@ -21,8 +21,8 @@ public function find( ->where('id', '!=', $ignoreWebhookCall->getKey()) ->where('name', MollieSignatureValidator::NAME) ->where('payload', 'LIKE', "%\"id\":\"{$resourceId->value()}\"%") - ->when($payloadFragment, ($this->filterByPayloadFragment(...))(...)) - ->where(($this->ignoreFailedWebhookCalls(...))(...)) + ->when($payloadFragment, $this->filterByPayloadFragment(...)) + ->where($this->ignoreFailedWebhookCalls(...)) ->orderBy('created_at', 'desc') ->orderBy('id', 'desc') ->first(); From 43533b40b6449923b538b4d34713061931caded4 Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Wed, 15 May 2024 12:26:46 +0200 Subject: [PATCH 37/39] Remove call to set api key method --- src/Testing/Doubles/FakeMollieApiClient.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Testing/Doubles/FakeMollieApiClient.php b/src/Testing/Doubles/FakeMollieApiClient.php index 56acb68..1698a94 100644 --- a/src/Testing/Doubles/FakeMollieApiClient.php +++ b/src/Testing/Doubles/FakeMollieApiClient.php @@ -17,10 +17,7 @@ final class FakeMollieApiClient extends MollieApiClient */ public static function fake(Application $app): self { - $mollie = new self(); - $mollie->setApiKey($app['config']->get('mollie.key')); - - return $app->instance(MollieApiClient::class, $mollie); + return $app->instance(MollieApiClient::class, new self()); } public function performHttpCall($httpMethod, $apiMethod, $httpBody = null): stdClass From 204f946b2c11846a759a9ed74fb43a314bf0f793 Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Wed, 15 May 2024 12:41:16 +0200 Subject: [PATCH 38/39] Update tests to phpunit 10 attributes --- rector.php | 2 +- src/Commands/ProcessMollieWebhookTest.php | 18 +++---- .../HandleMollieWebhooksRequestTest.php | 19 ++++---- src/MollieWebhooksServiceProviderTest.php | 13 ++--- src/Orders/WebhookCallOrderHistoryTest.php | 14 +++--- .../WebhookCallPaymentHistoryTest.php | 14 +++--- ...atestMollieWebhookCallByResourceIdTest.php | 28 ++++------- .../SubscribeToMollieOrderRefundsTest.php | 23 ++++----- ...ubscribeToMollieOrderStatusChangesTest.php | 47 +++++++------------ .../SubscribeToMolliePaymentRefundsTest.php | 23 ++++----- ...scribeToMolliePaymentStatusChangesTest.php | 41 ++++++---------- src/Testing/PrefixedResourceIdTestCase.php | 36 +++++--------- src/WebhookPayloadFragmentTest.php | 14 +++--- 13 files changed, 111 insertions(+), 181 deletions(-) diff --git a/rector.php b/rector.php index a1ea6b2..cdafade 100644 --- a/rector.php +++ b/rector.php @@ -11,7 +11,7 @@ ]); $rectorConfig->sets([ - \Rector\Set\ValueObject\LevelSetList::UP_TO_PHP_81, + \Rector\PHPUnit\Set\PHPUnitSetList::PHPUNIT_100, ]); $rectorConfig->skip([ diff --git a/src/Commands/ProcessMollieWebhookTest.php b/src/Commands/ProcessMollieWebhookTest.php index 79ce501..7ace53e 100644 --- a/src/Commands/ProcessMollieWebhookTest.php +++ b/src/Commands/ProcessMollieWebhookTest.php @@ -14,15 +14,15 @@ use Generator; use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Support\Facades\Event; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Spatie\WebhookClient\Models\WebhookCall; use function compact; final class ProcessMollieWebhookTest extends IntegrationTestCase { - /** - * @test - */ + #[Test] public function itShouldBeQueued(): void { $webhookCall = new WebhookCall([]); @@ -43,10 +43,8 @@ public static function invalidWebhookPayloads(): Generator ]; } - /** - * @test - * @dataProvider invalidWebhookPayloads - */ + #[Test] + #[DataProvider('invalidWebhookPayloads')] public function itFailsWhenTheWebhookPayloadIsInvalid(array $payload, Exception $exception): void { $this->expectExceptionObject($exception); @@ -69,10 +67,8 @@ public static function webhookPayloads(): Generator ]; } - /** - * @test - * @dataProvider webhookPayloads - */ + #[Test] + #[DataProvider('webhookPayloads')] public function itCanHandleIncomingWebhooks(callable $generatesResourceId, string $event): void { $resourceId = $generatesResourceId($this); diff --git a/src/Http/Requests/HandleMollieWebhooksRequestTest.php b/src/Http/Requests/HandleMollieWebhooksRequestTest.php index a64bd23..597908a 100644 --- a/src/Http/Requests/HandleMollieWebhooksRequestTest.php +++ b/src/Http/Requests/HandleMollieWebhooksRequestTest.php @@ -13,6 +13,9 @@ use Illuminate\Routing\Router; use Illuminate\Support\Facades\Bus; use Illuminate\Support\Str; +use PHPUnit\Framework\Attributes\Before; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use function json_encode; @@ -23,9 +26,7 @@ final class HandleMollieWebhooksRequestTest extends IntegrationTestCase private const URI = '/mollie/webhooks/handle'; - /** - * @before - */ + #[Before] public function registerWebhooksHandlerRoute(): void { $this->afterApplicationCreated(function (): void { @@ -52,10 +53,8 @@ public static function invalidPayloads(): Generator ]; } - /** - * @test - * @dataProvider invalidPayloads - */ + #[Test] + #[DataProvider('invalidPayloads')] public function itCanHandleIncomingMollieWebhooksWithAnInvalidPayload(array $payload): void { $response = $this->post(self::URI, $payload); @@ -75,10 +74,8 @@ public static function validPayloads(): Generator ]; } - /** - * @test - * @dataProvider validPayloads - */ + #[Test] + #[DataProvider('validPayloads')] public function itCanHandleIncomingMollieWebhooks(array $payload): void { $response = $this->post(self::URI, $payload); diff --git a/src/MollieWebhooksServiceProviderTest.php b/src/MollieWebhooksServiceProviderTest.php index ac390c3..c78b1a2 100644 --- a/src/MollieWebhooksServiceProviderTest.php +++ b/src/MollieWebhooksServiceProviderTest.php @@ -12,14 +12,13 @@ use Craftzing\Laravel\MollieWebhooks\Testing\IntegrationTestCase; use Illuminate\Routing\Route; use Illuminate\Routing\Router; +use PHPUnit\Framework\Attributes\Test; final class MollieWebhooksServiceProviderTest extends IntegrationTestCase { private const URI = 'mollie/webhooks/handle'; - /** - * @test - */ + #[Test] public function itExtendsTheRouterToEnableRegisteringARouteToHandleIncomingWebhooks(): void { $router = $this->app[Router::class]; @@ -33,9 +32,7 @@ public function itExtendsTheRouterToEnableRegisteringARouteToHandleIncomingWebho $this->assertSame(self::URI, $route->uri); } - /** - * @test - */ + #[Test] public function itBindsADefaultImplementationForThePaymentHistory(): void { $paymentHistory = $this->app[PaymentHistory::class]; @@ -43,9 +40,7 @@ public function itBindsADefaultImplementationForThePaymentHistory(): void $this->assertInstanceOf(WebhookCallPaymentHistory::class, $paymentHistory); } - /** - * @test - */ + #[Test] public function itBindsADefaultImplementationForTheOrderHistory(): void { $orderHistory = $this->app[OrderHistory::class]; diff --git a/src/Orders/WebhookCallOrderHistoryTest.php b/src/Orders/WebhookCallOrderHistoryTest.php index 8e8150a..efb7d7e 100644 --- a/src/Orders/WebhookCallOrderHistoryTest.php +++ b/src/Orders/WebhookCallOrderHistoryTest.php @@ -9,6 +9,8 @@ use Craftzing\Laravel\MollieWebhooks\Testing\Doubles\FakeOrder; use Craftzing\Laravel\MollieWebhooks\Testing\IntegrationTestCase; use Generator; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; final class WebhookCallOrderHistoryTest extends IntegrationTestCase { @@ -21,10 +23,8 @@ public static function orderWebhookCallHistory(): Generator } } - /** - * @test - * @dataProvider orderWebhookCallHistory - */ + #[Test] + #[DataProvider('orderWebhookCallHistory')] public function itCanCheckIfItHasALatestStatusForAnOrder( callable $resolveOrderStatus, bool $expectedToHaveSameLatestStatus @@ -48,10 +48,8 @@ public function itCanCheckIfItHasALatestStatusForAnOrder( } } - /** - * @test - * @dataProvider refundsWebhookCallHistory - */ + #[Test] + #[DataProvider('refundsWebhookCallHistory')] public function itCanCheckIfItHasARefundWithAStatusForAnOrder( callable $resolveRefundStatus, bool $expectedToHaveRefundWithStatus diff --git a/src/Payments/WebhookCallPaymentHistoryTest.php b/src/Payments/WebhookCallPaymentHistoryTest.php index d3e53cb..8c23be6 100644 --- a/src/Payments/WebhookCallPaymentHistoryTest.php +++ b/src/Payments/WebhookCallPaymentHistoryTest.php @@ -9,6 +9,8 @@ use Craftzing\Laravel\MollieWebhooks\Testing\Doubles\FakePayment; use Craftzing\Laravel\MollieWebhooks\Testing\IntegrationTestCase; use Generator; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; final class WebhookCallPaymentHistoryTest extends IntegrationTestCase { @@ -21,10 +23,8 @@ public static function paymentWebhookCallHistory(): Generator } } - /** - * @test - * @dataProvider paymentWebhookCallHistory - */ + #[Test] + #[DataProvider('paymentWebhookCallHistory')] public function itCanCheckIfItHasALatestStatusForAPayment( callable $resolveOrderStatus, bool $expectedToHaveSameLatestStatus @@ -52,10 +52,8 @@ public function itCanCheckIfItHasALatestStatusForAPayment( } } - /** - * @test - * @dataProvider refundsWebhookCallHistory - */ + #[Test] + #[DataProvider('refundsWebhookCallHistory')] public function itCanCheckIfItHasATransferredRefundForAPayment( callable $resolveRefundStatus, bool $expectedToHaveRefundWithStatus diff --git a/src/Queries/LatestMollieWebhookCallByResourceIdTest.php b/src/Queries/LatestMollieWebhookCallByResourceIdTest.php index cf68d62..6eedb06 100644 --- a/src/Queries/LatestMollieWebhookCallByResourceIdTest.php +++ b/src/Queries/LatestMollieWebhookCallByResourceIdTest.php @@ -10,6 +10,8 @@ use Craftzing\Laravel\MollieWebhooks\WebhookPayloadFragment; use Generator; use Illuminate\Foundation\Testing\WithFaker; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Spatie\WebhookClient\Models\WebhookCall; final class LatestMollieWebhookCallByResourceIdTest extends IntegrationTestCase @@ -33,10 +35,8 @@ public static function noResults(): Generator ]; } - /** - * @test - * @dataProvider noResults - */ + #[Test] + #[DataProvider('noResults')] public function itCanHandleNoResults(callable $addWebhookCallHistory): void { $resourceId = $this->generatePaymentId(); @@ -50,9 +50,7 @@ public function itCanHandleNoResults(callable $addWebhookCallHistory): void $this->assertNull($result); } - /** - * @test - */ + #[Test] public function itCanFindTheLatestMollieWebhookCallByResourceId(): void { $resourceId = $this->generatePaymentId(); @@ -74,9 +72,7 @@ public function itCanFindTheLatestMollieWebhookCallByResourceId(): void $this->assertTrue($result->is($latestWebhookCall)); } - /** - * @test - */ + #[Test] public function itIgnoresFailedWebhookCalls(): void { $resourceId = $this->generatePaymentId(); @@ -120,10 +116,8 @@ function (ResourceId $resourceId): WebhookCall { ]; } - /** - * @test - * @dataProvider webhookCallByFragment - */ + #[Test] + #[DataProvider('webhookCallByFragment')] public function itCanBeFilteredByPayloadFragmentKeys(callable $resolveExpectedWebhookCallFromHistory): void { $resourceId = $this->generatePaymentId(); @@ -142,10 +136,8 @@ public function itCanBeFilteredByPayloadFragmentKeys(callable $resolveExpectedWe $this->assertTrue($result->is($expectedWebhookCall)); } - /** - * @test - * @dataProvider webhookCallByFragment - */ + #[Test] + #[DataProvider('webhookCallByFragment')] public function itCanBeFilteredByAPayloadFragmentValues(callable $resolveExpectedWebhookCallFromHistory): void { $resourceId = $this->generatePaymentId(); diff --git a/src/Subscribers/SubscribeToMollieOrderRefundsTest.php b/src/Subscribers/SubscribeToMollieOrderRefundsTest.php index d1e6479..e79d9eb 100644 --- a/src/Subscribers/SubscribeToMollieOrderRefundsTest.php +++ b/src/Subscribers/SubscribeToMollieOrderRefundsTest.php @@ -16,6 +16,9 @@ use Illuminate\Events\CallQueuedListener; use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Queue; +use PHPUnit\Framework\Attributes\Before; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Spatie\WebhookClient\Models\WebhookCall; final class SubscribeToMollieOrderRefundsTest extends IntegrationTestCase @@ -24,9 +27,7 @@ final class SubscribeToMollieOrderRefundsTest extends IntegrationTestCase protected array $eventsToFake = FakeRefund::STATUS_EVENTS; - /** - * @before - */ + #[Before] public function fakeOrderHistory(): void { $this->afterApplicationCreated(function (): void { @@ -34,9 +35,7 @@ public function fakeOrderHistory(): void }); } - /** - * @test - */ + #[Test] public function itCanBeRegisteredAsAQueuedSubscriberForTheGenericOrderEvent(): void { $this->dontFakeEvents(); @@ -71,10 +70,8 @@ public static function orderHistory(): Generator ]; } - /** - * @test - * @dataProvider orderHistory - */ + #[Test] + #[DataProvider('orderHistory')] public function itDispatchesRefundStatusEventsWhenTheStatusIsNotInTheOrderHistory(callable $resolveRefunds): void { /** @var \Craftzing\Laravel\MollieWebhooks\Testing\Doubles\FakeRefund[] $refunds */ @@ -100,10 +97,8 @@ public function itDispatchesRefundStatusEventsWhenTheStatusIsNotInTheOrderHistor } } - /** - * @test - * @dataProvider orderHistory - */ + #[Test] + #[DataProvider('orderHistory')] public function itDoesNotDispatchRefundStatusEventsWhenTheStatusExistsInTheOrderHistory( callable $resolveRefunds ): void { diff --git a/src/Subscribers/SubscribeToMollieOrderStatusChangesTest.php b/src/Subscribers/SubscribeToMollieOrderStatusChangesTest.php index b61ed41..2f9a153 100644 --- a/src/Subscribers/SubscribeToMollieOrderStatusChangesTest.php +++ b/src/Subscribers/SubscribeToMollieOrderStatusChangesTest.php @@ -22,15 +22,16 @@ use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Queue; use Mollie\Api\Types\OrderStatus; +use PHPUnit\Framework\Attributes\Before; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Spatie\WebhookClient\Models\WebhookCall; final class SubscribeToMollieOrderStatusChangesTest extends IntegrationTestCase { private FakeOrderHistory $fakeOrderHistory; - /** - * @before - */ + #[Before] public function fakePaymentHistory(): void { $this->afterApplicationCreated(function (): void { @@ -38,9 +39,7 @@ public function fakePaymentHistory(): void }); } - /** - * @test - */ + #[Test] public function itCanBeRegisteredAsAQueuedSubscriberForTheGenericOrderEvent(): void { $this->dontFakeEvents(); @@ -70,10 +69,8 @@ function (FakeOrderHistory $fakeOrderHistory) use ($orderStatus): string { } } - /** - * @test - * @dataProvider orderHistory - */ + #[Test] + #[DataProvider('orderHistory')] public function itCanHandleWebhookCallsIndicatingAnOrderStatusChangedToPaid(callable $addOrderHistory): void { $paid = OrderStatus::STATUS_PAID; @@ -97,10 +94,8 @@ public function itCanHandleWebhookCallsIndicatingAnOrderStatusChangedToPaid(call } } - /** - * @test - * @dataProvider orderHistory - */ + #[Test] + #[DataProvider('orderHistory')] public function itCanHandleWebhookCallsIndicatingAnOrderStatusChangedToExpired(callable $addOrderHistory): void { $expired = OrderStatus::STATUS_EXPIRED; @@ -124,10 +119,8 @@ public function itCanHandleWebhookCallsIndicatingAnOrderStatusChangedToExpired(c } } - /** - * @test - * @dataProvider orderHistory - */ + #[Test] + #[DataProvider('orderHistory')] public function itCanHandleWebhookCallsIndicatingAnOrderStatusChangedToAuthorized(callable $addOrderHistory): void { $authorized = OrderStatus::STATUS_AUTHORIZED; @@ -151,10 +144,8 @@ public function itCanHandleWebhookCallsIndicatingAnOrderStatusChangedToAuthorize } } - /** - * @test - * @dataProvider orderHistory - */ + #[Test] + #[DataProvider('orderHistory')] public function itCanHandleWebhookCallsIndicatingAnOrderStatusChangedToCanceled(callable $addOrderHistory): void { $canceled = OrderStatus::STATUS_CANCELED; @@ -178,10 +169,8 @@ public function itCanHandleWebhookCallsIndicatingAnOrderStatusChangedToCanceled( } } - /** - * @test - * @dataProvider orderHistory - */ + #[Test] + #[DataProvider('orderHistory')] public function itCanHandleWebhookCallsIndicatingAnOrderStatusChangedToCompleted(callable $addOrderHistory): void { $completed = OrderStatus::STATUS_COMPLETED; @@ -225,10 +214,8 @@ public static function statusesThatDontFireEvents(): Generator ]; } - /** - * @test - * @dataProvider statusesThatDontFireEvents - */ + #[Test] + #[DataProvider('statusesThatDontFireEvents')] public function itCanHandleWebhookCallsWithoutAnOrderStatusThatWeListenTo(string $status): void { $webhookCall = $this->webhookCallIndicatingOrderStatusChangedTo($status); diff --git a/src/Subscribers/SubscribeToMolliePaymentRefundsTest.php b/src/Subscribers/SubscribeToMolliePaymentRefundsTest.php index 6dcbf3b..7b353f7 100644 --- a/src/Subscribers/SubscribeToMolliePaymentRefundsTest.php +++ b/src/Subscribers/SubscribeToMolliePaymentRefundsTest.php @@ -16,6 +16,9 @@ use Illuminate\Events\CallQueuedListener; use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Queue; +use PHPUnit\Framework\Attributes\Before; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Spatie\WebhookClient\Models\WebhookCall; final class SubscribeToMolliePaymentRefundsTest extends IntegrationTestCase @@ -24,9 +27,7 @@ final class SubscribeToMolliePaymentRefundsTest extends IntegrationTestCase protected array $eventsToFake = FakeRefund::STATUS_EVENTS; - /** - * @before - */ + #[Before] public function fakePaymentHistory(): void { $this->afterApplicationCreated(function (): void { @@ -34,9 +35,7 @@ public function fakePaymentHistory(): void }); } - /** - * @test - */ + #[Test] public function itCanBeRegisteredAsAQueuedSubscriberForTheGenericPaymentEvent(): void { $this->dontFakeEvents(); @@ -71,10 +70,8 @@ public static function paymentHistory(): Generator ]; } - /** - * @test - * @dataProvider paymentHistory - */ + #[Test] + #[DataProvider('paymentHistory')] public function itDispatchesRefundStatusEventsWhenTheStatusIsNotInThePaymentHistory(callable $resolveRefunds): void { /** @var \Craftzing\Laravel\MollieWebhooks\Testing\Doubles\FakeRefund[] $refunds */ @@ -100,10 +97,8 @@ public function itDispatchesRefundStatusEventsWhenTheStatusIsNotInThePaymentHist } } - /** - * @test - * @dataProvider paymentHistory - */ + #[Test] + #[DataProvider('paymentHistory')] public function itDoesNotDispatchRefundStatusEventsWhenTheStatusExistsInThePaymentHistory( callable $resolveRefunds ): void { diff --git a/src/Subscribers/SubscribeToMolliePaymentStatusChangesTest.php b/src/Subscribers/SubscribeToMolliePaymentStatusChangesTest.php index e198cdb..bb7d917 100644 --- a/src/Subscribers/SubscribeToMolliePaymentStatusChangesTest.php +++ b/src/Subscribers/SubscribeToMolliePaymentStatusChangesTest.php @@ -21,15 +21,16 @@ use Illuminate\Support\Facades\Event; use Illuminate\Support\Facades\Queue; use Mollie\Api\Types\PaymentStatus; +use PHPUnit\Framework\Attributes\Before; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use Spatie\WebhookClient\Models\WebhookCall; final class SubscribeToMolliePaymentStatusChangesTest extends IntegrationTestCase { private FakePaymentHistory $fakePaymentHistory; - /** - * @before - */ + #[Before] public function fakePaymentHistory(): void { $this->afterApplicationCreated(function (): void { @@ -37,9 +38,7 @@ public function fakePaymentHistory(): void }); } - /** - * @test - */ + #[Test] public function itCanBeRegisteredAsAQueuedSubscriberForTheGenericPaymentEvent(): void { $this->dontFakeEvents(); @@ -69,10 +68,8 @@ function (FakePaymentHistory $fakePaymentHistory) use ($paymentStatus): string { } } - /** - * @test - * @dataProvider paymentHistory - */ + #[Test] + #[DataProvider('paymentHistory')] public function itCanHandleWebhookCallsIndicatingAPaymentStatusChangedToPaid(callable $addPaymentHistory): void { $paid = PaymentStatus::STATUS_PAID; @@ -96,10 +93,8 @@ public function itCanHandleWebhookCallsIndicatingAPaymentStatusChangedToPaid(cal } } - /** - * @test - * @dataProvider paymentHistory - */ + #[Test] + #[DataProvider('paymentHistory')] public function itCanHandleWebhookCallsIndicatingAPaymentStatusChangedToExpired(callable $addPaymentHistory): void { $expired = PaymentStatus::STATUS_EXPIRED; @@ -123,10 +118,8 @@ public function itCanHandleWebhookCallsIndicatingAPaymentStatusChangedToExpired( } } - /** - * @test - * @dataProvider paymentHistory - */ + #[Test] + #[DataProvider('paymentHistory')] public function itCanHandleWebhookCallsIndicatingAPaymentStatusChangedToFailed(callable $addPaymentHistory): void { $failed = PaymentStatus::STATUS_FAILED; @@ -150,10 +143,8 @@ public function itCanHandleWebhookCallsIndicatingAPaymentStatusChangedToFailed(c } } - /** - * @test - * @dataProvider paymentHistory - */ + #[Test] + #[DataProvider('paymentHistory')] public function itCanHandleWebhookCallsIndicatingAPaymentStatusChangedToCanceled(callable $addPaymentHistory): void { $canceled = PaymentStatus::STATUS_CANCELED; @@ -201,10 +192,8 @@ public static function statusesThatDontFireEvents(): Generator ]; } - /** - * @test - * @dataProvider statusesThatDontFireEvents - */ + #[Test] + #[DataProvider('statusesThatDontFireEvents')] public function itCanHandleWebhookCallsWithoutAPaymentStatusThatWeListenTo(string $status): void { $webhookCall = $this->webhookCallIndicatingPaymentStatusChangedTo($status); diff --git a/src/Testing/PrefixedResourceIdTestCase.php b/src/Testing/PrefixedResourceIdTestCase.php index 3583172..4f1ce0b 100644 --- a/src/Testing/PrefixedResourceIdTestCase.php +++ b/src/Testing/PrefixedResourceIdTestCase.php @@ -7,6 +7,8 @@ use Craftzing\Laravel\MollieWebhooks\ResourceId; use Generator; use Illuminate\Support\Str; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use function call_user_func; @@ -29,10 +31,8 @@ public static function invalidMollieResourceIds(): Generator yield 'Value has an invalid prefix' => ['pa_' . Str::random(8)]; } - /** - * @test - * @dataProvider invalidMollieResourceIds - */ + #[Test] + #[DataProvider('invalidMollieResourceIds')] public function itCannotBeConstructedFromAnInvalidMollieResourceIdString(string $value): void { $this->expectExceptionObject( @@ -48,10 +48,8 @@ public static function validMollieResourceIds(): Generator yield 'Long identifier' => [fn (self $test): string => $test::expectedPrefix() . Str::random(8)]; } - /** - * @test - * @dataProvider validMollieResourceIds - */ + #[Test] + #[DataProvider('validMollieResourceIds')] public function itCanBeConstructedFromAValidMollieResourceIdString(callable $resolveValue): void { $value = $resolveValue($this); @@ -61,10 +59,8 @@ public function itCanBeConstructedFromAValidMollieResourceIdString(callable $res $this->assertInstanceOf(ResourceId::class, $resourceId); } - /** - * @test - * @dataProvider validMollieResourceIds - */ + #[Test] + #[DataProvider('validMollieResourceIds')] public function itCanBeCastedToAString(callable $resolveValue): void { $value = $resolveValue($this); @@ -74,10 +70,8 @@ public function itCanBeCastedToAString(callable $resolveValue): void $this->assertSame($value, (string) $resourceId); } - /** - * @test - * @dataProvider validMollieResourceIds - */ + #[Test] + #[DataProvider('validMollieResourceIds')] public function itCanReturnItsValue(callable $resolveValue): void { $value = $resolveValue($this); @@ -87,10 +81,8 @@ public function itCanReturnItsValue(callable $resolveValue): void $this->assertSame($value, $resourceId->value()); } - /** - * @test - * @dataProvider validMollieResourceIds - */ + #[Test] + #[DataProvider('validMollieResourceIds')] public function itCanBeSerialized(callable $resolveValue): void { $value = $resolveValue($this); @@ -102,9 +94,7 @@ public function itCanBeSerialized(callable $resolveValue): void $this->assertEquals($resourceId, unserialize($serializedResourceId, [$this::resourceIdClass()])); } - /** - * @test - */ + #[Test] public function itCanBeUsedAsAResourceId(): void { $resourceId = $this::resourceIdClass()::fromString($this::expectedPrefix() . Str::random(8)); diff --git a/src/WebhookPayloadFragmentTest.php b/src/WebhookPayloadFragmentTest.php index d2ccb94..281daeb 100644 --- a/src/WebhookPayloadFragmentTest.php +++ b/src/WebhookPayloadFragmentTest.php @@ -5,6 +5,8 @@ namespace Craftzing\Laravel\MollieWebhooks; use Generator; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\TestCase; use function array_filter; @@ -19,10 +21,8 @@ public static function keys(): Generator yield 'Multiple keys' => ['foo', 'bar', 'baz']; } - /** - * @test - * @dataProvider keys - */ + #[Test] + #[DataProvider('keys')] public function itCanBeConstructedFromKeys(string ...$keys): void { $keys = array_filter($keys); @@ -55,10 +55,8 @@ public static function values(): Generator ]; } - /** - * @test - * @dataProvider values - */ + #[Test] + #[DataProvider('values')] public function itCanBeConstructedFromValues(array $values): void { $values = array_filter($values); From 59c340efe33cffcd87af379a05764cab524f6e31 Mon Sep 17 00:00:00 2001 From: ppelgrims Date: Wed, 15 May 2024 13:15:35 +0200 Subject: [PATCH 39/39] Replace action --- .github/workflows/code-style.yml | 22 ---------------------- .github/workflows/quality-assurance.yml | 3 +++ 2 files changed, 3 insertions(+), 22 deletions(-) delete mode 100644 .github/workflows/code-style.yml diff --git a/.github/workflows/code-style.yml b/.github/workflows/code-style.yml deleted file mode 100644 index 47cb58f..0000000 --- a/.github/workflows/code-style.yml +++ /dev/null @@ -1,22 +0,0 @@ ---- -name: Code style -on: [push] - -jobs: - php-cs-fixer: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v2 - with: - ref: ${{ github.head_ref }} - - - name: Run PHP CS fixer - uses: docker://oskarstark/php-cs-fixer-ga - with: - args: --config=.php-cs-fixer.dist.php --allow-risky=yes - - - name: Commit changes - uses: stefanzweifel/git-auto-commit-action@v4 - with: - commit_message: Fix code style violations diff --git a/.github/workflows/quality-assurance.yml b/.github/workflows/quality-assurance.yml index 6ae1e9c..d141584 100644 --- a/.github/workflows/quality-assurance.yml +++ b/.github/workflows/quality-assurance.yml @@ -48,3 +48,6 @@ jobs: - name: Run PHPStan analysis run: vendor/bin/phpstan analyse --memory-limit=-1 if: ${{ matrix.php == '8.2' }} + + - name: Run PHP Coding Standards Fixer + run: vendor/bin/php-cs-fixer fix src --dry-run \ No newline at end of file