Skip to content

Commit

Permalink
Upgrade phpunit
Browse files Browse the repository at this point in the history
  • Loading branch information
ppelgrims committed Apr 22, 2024
1 parent efa3cc0 commit d3ac62d
Show file tree
Hide file tree
Showing 21 changed files with 111 additions and 102 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/quality-assurance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
51 changes: 27 additions & 24 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,26 +1,29 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" bootstrap="vendor/autoload.php" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory>./src/</directory>
</include>
<exclude>
<directory suffix="Test.php">src/</directory>
<directory suffix="TestCase.php">src/</directory>
<directory>src/Testing/</directory>
</exclude>
</coverage>
<testsuites>
<testsuite name="Laravel Mollie Webhooks">
<directory suffix="Test.php">src/</directory>
</testsuite>
</testsuites>
<php>
<server name="APP_ENV" value="testing"/>
<server name="BCRYPT_ROUNDS" value="4"/>
<server name="CACHE_DRIVER" value="array"/>
<server name="DB_CONNECTION" value="sqlite"/>
<server name="DB_DATABASE" value=":memory:"/>
<server name="QUEUE_CONNECTION" value="sync"/>
</php>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
colors="true"
bootstrap="vendor/autoload.php"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd">
<testsuites>
<testsuite name="Laravel Mollie Webhooks">
<directory suffix="Test.php">src/</directory>
</testsuite>
</testsuites>
<php>
<server name="APP_ENV" value="testing"/>
<server name="BCRYPT_ROUNDS" value="4"/>
<server name="CACHE_DRIVER" value="array"/>
<server name="DB_CONNECTION" value="sqlite"/>
<server name="DB_DATABASE" value=":memory:"/>
<server name="QUEUE_CONNECTION" value="sync"/>
</php>
<source>
<include>
<directory>./src/</directory>
</include>
<exclude>
<directory suffix="Test.php">src/</directory>
<directory suffix="TestCase.php">src/</directory>
<directory>src/Testing/</directory>
</exclude>
</source>
</phpunit>
14 changes: 7 additions & 7 deletions src/Commands/ProcessMollieWebhookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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' => [
[],
Expand All @@ -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,
];
}
Expand All @@ -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(),
Expand All @@ -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));
}),
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Requests/HandleMollieWebhooksRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function registerWebhooksHandlerRoute(): void
});
}

public function invalidPayloads(): Generator
public static function invalidPayloads(): Generator
{
yield 'Empty payload' => [
[],
Expand Down Expand Up @@ -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)],
Expand Down
6 changes: 3 additions & 3 deletions src/Orders/OrderIdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Orders/WebhookCallOrderHistoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(...));
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/Payments/PaymentIdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Payments/WebhookCallPaymentHistoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(...));
}
}

Expand Down
10 changes: 5 additions & 5 deletions src/Queries/LatestMollieWebhookCallByResourceIdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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]),
];
}

Expand All @@ -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();
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions src/Refunds/RefundIdTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Subscribers/SubscribeToMollieOrderRefundsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function itCanBeRegisteredAsAQueuedSubscriberForTheGenericOrderEvent(): v
});
}

public function orderHistory(): Generator
public static function orderHistory(): Generator
{
yield 'Order has no refunds' => [
fn (): array => [],
Expand Down
16 changes: 8 additions & 8 deletions src/Subscribers/SubscribeToMollieOrderStatusChangesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
}),
);
Expand All @@ -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);
}),
);
Expand All @@ -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);
}),
);
Expand All @@ -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);
}),
);
Expand All @@ -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);
}),
);
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/Subscribers/SubscribeToMolliePaymentRefundsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function itCanBeRegisteredAsAQueuedSubscriberForTheGenericPaymentEvent():
});
}

public function paymentHistory(): Generator
public static function paymentHistory(): Generator
{
yield 'Payment has no refunds' => [
fn (): array => [],
Expand Down
Loading

0 comments on commit d3ac62d

Please sign in to comment.