Skip to content

Commit

Permalink
Update tests to phpunit 10 attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
ppelgrims committed May 15, 2024
1 parent 43533b4 commit 204f946
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 181 deletions.
2 changes: 1 addition & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
]);

$rectorConfig->sets([
\Rector\Set\ValueObject\LevelSetList::UP_TO_PHP_81,
\Rector\PHPUnit\Set\PHPUnitSetList::PHPUNIT_100,
]);

$rectorConfig->skip([
Expand Down
18 changes: 7 additions & 11 deletions src/Commands/ProcessMollieWebhookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
19 changes: 8 additions & 11 deletions src/Http/Requests/HandleMollieWebhooksRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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 {
Expand All @@ -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);
Expand All @@ -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);
Expand Down
13 changes: 4 additions & 9 deletions src/MollieWebhooksServiceProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -33,19 +32,15 @@ public function itExtendsTheRouterToEnableRegisteringARouteToHandleIncomingWebho
$this->assertSame(self::URI, $route->uri);
}

/**
* @test
*/
#[Test]
public function itBindsADefaultImplementationForThePaymentHistory(): void
{
$paymentHistory = $this->app[PaymentHistory::class];

$this->assertInstanceOf(WebhookCallPaymentHistory::class, $paymentHistory);
}

/**
* @test
*/
#[Test]
public function itBindsADefaultImplementationForTheOrderHistory(): void
{
$orderHistory = $this->app[OrderHistory::class];
Expand Down
14 changes: 6 additions & 8 deletions src/Orders/WebhookCallOrderHistoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -21,10 +23,8 @@ public static function orderWebhookCallHistory(): Generator
}
}

/**
* @test
* @dataProvider orderWebhookCallHistory
*/
#[Test]
#[DataProvider('orderWebhookCallHistory')]
public function itCanCheckIfItHasALatestStatusForAnOrder(
callable $resolveOrderStatus,
bool $expectedToHaveSameLatestStatus
Expand All @@ -48,10 +48,8 @@ public function itCanCheckIfItHasALatestStatusForAnOrder(
}
}

/**
* @test
* @dataProvider refundsWebhookCallHistory
*/
#[Test]
#[DataProvider('refundsWebhookCallHistory')]
public function itCanCheckIfItHasARefundWithAStatusForAnOrder(
callable $resolveRefundStatus,
bool $expectedToHaveRefundWithStatus
Expand Down
14 changes: 6 additions & 8 deletions src/Payments/WebhookCallPaymentHistoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -21,10 +23,8 @@ public static function paymentWebhookCallHistory(): Generator
}
}

/**
* @test
* @dataProvider paymentWebhookCallHistory
*/
#[Test]
#[DataProvider('paymentWebhookCallHistory')]
public function itCanCheckIfItHasALatestStatusForAPayment(
callable $resolveOrderStatus,
bool $expectedToHaveSameLatestStatus
Expand Down Expand Up @@ -52,10 +52,8 @@ public function itCanCheckIfItHasALatestStatusForAPayment(
}
}

/**
* @test
* @dataProvider refundsWebhookCallHistory
*/
#[Test]
#[DataProvider('refundsWebhookCallHistory')]
public function itCanCheckIfItHasATransferredRefundForAPayment(
callable $resolveRefundStatus,
bool $expectedToHaveRefundWithStatus
Expand Down
28 changes: 10 additions & 18 deletions src/Queries/LatestMollieWebhookCallByResourceIdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -33,10 +35,8 @@ public static function noResults(): Generator
];
}

/**
* @test
* @dataProvider noResults
*/
#[Test]
#[DataProvider('noResults')]
public function itCanHandleNoResults(callable $addWebhookCallHistory): void
{
$resourceId = $this->generatePaymentId();
Expand All @@ -50,9 +50,7 @@ public function itCanHandleNoResults(callable $addWebhookCallHistory): void
$this->assertNull($result);
}

/**
* @test
*/
#[Test]
public function itCanFindTheLatestMollieWebhookCallByResourceId(): void
{
$resourceId = $this->generatePaymentId();
Expand All @@ -74,9 +72,7 @@ public function itCanFindTheLatestMollieWebhookCallByResourceId(): void
$this->assertTrue($result->is($latestWebhookCall));
}

/**
* @test
*/
#[Test]
public function itIgnoresFailedWebhookCalls(): void
{
$resourceId = $this->generatePaymentId();
Expand Down Expand Up @@ -120,10 +116,8 @@ function (ResourceId $resourceId): WebhookCall {
];
}

/**
* @test
* @dataProvider webhookCallByFragment
*/
#[Test]
#[DataProvider('webhookCallByFragment')]
public function itCanBeFilteredByPayloadFragmentKeys(callable $resolveExpectedWebhookCallFromHistory): void
{
$resourceId = $this->generatePaymentId();
Expand All @@ -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();
Expand Down
23 changes: 9 additions & 14 deletions src/Subscribers/SubscribeToMollieOrderRefundsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -24,19 +27,15 @@ final class SubscribeToMollieOrderRefundsTest extends IntegrationTestCase

protected array $eventsToFake = FakeRefund::STATUS_EVENTS;

/**
* @before
*/
#[Before]
public function fakeOrderHistory(): void
{
$this->afterApplicationCreated(function (): void {
$this->swap(OrderHistory::class, $this->fakeOrderHistory = new FakeOrderHistory());
});
}

/**
* @test
*/
#[Test]
public function itCanBeRegisteredAsAQueuedSubscriberForTheGenericOrderEvent(): void
{
$this->dontFakeEvents();
Expand Down Expand Up @@ -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 */
Expand All @@ -100,10 +97,8 @@ public function itDispatchesRefundStatusEventsWhenTheStatusIsNotInTheOrderHistor
}
}

/**
* @test
* @dataProvider orderHistory
*/
#[Test]
#[DataProvider('orderHistory')]
public function itDoesNotDispatchRefundStatusEventsWhenTheStatusExistsInTheOrderHistory(
callable $resolveRefunds
): void {
Expand Down
Loading

0 comments on commit 204f946

Please sign in to comment.