Skip to content

Commit

Permalink
test: ✅ add null check and update test mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
YouneselBarnoussi committed May 9, 2024
1 parent 9f25a3f commit d60305f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
4 changes: 2 additions & 2 deletions src/Http/Controllers/WebhookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function handleWebhook(Request $request)

$molliePayment = $this->getMolliePaymentById(
$request->get('id'),
owner: $payment->owner instanceof ProvidesOauthInformation ? $payment->owner : null,
owner: $payment?->owner instanceof ProvidesOauthInformation ? $payment?->owner : null,
);

if ($molliePayment) {
Expand All @@ -38,7 +38,7 @@ public function handleWebhook(Request $request)

/** @var UpdateMolliePayment $updateMolliePayment */
$updateMolliePayment = app()->make(UpdateMolliePayment::class);
$updateMolliePayment->execute($molliePayment, $payment->owner instanceof ProvidesOauthInformation ? $payment->owner : null);
$updateMolliePayment->execute($molliePayment, $payment?->owner instanceof ProvidesOauthInformation ? $payment?->owner : null);

break;
case PaymentStatus::STATUS_FAILED:
Expand Down
7 changes: 1 addition & 6 deletions src/Mollie/GetMollieRefund.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,14 @@

class GetMollieRefund extends BaseMollieInteraction implements Contract
{
/**
* @var \Mollie\Api\MollieApiClient
*/
protected Mollie $mollie;

/**
* @var \Laravel\Cashier\Mollie\Contracts\GetMolliePayment
*/
protected GetMolliePayment $getMolliePayment;

public function __construct(Mollie $mollie, GetMolliePayment $getMolliePayment)
{
$this->mollie = $mollie;
parent::__construct($mollie);
$this->getMolliePayment = $getMolliePayment;
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Refunds/RefundsBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function can_create_a_refund_for_a_complete_order(): void
'value' => '22.00',
'currency' => 'EUR',
],
])->once()->andReturn($mollieRefund);
], null)->once()->andReturn($mollieRefund);
});

$user = $this->getUser();
Expand Down
14 changes: 7 additions & 7 deletions tests/Traits/InteractsWithMocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ protected function withMockedGetMollieMandatePending(int $times = 1): void
'customerId' => 'cst_unique_customer_id',
'status' => 'pending',
]
]);
], null);
}

protected function withMockedGetMollieMandate(
Expand All @@ -165,7 +165,7 @@ protected function withMockedGetMollieMandate(
$mandate->method = 'directdebit';

$mock->shouldReceive('execute')
->with($data['customerId'], $data['mandateId'])
->with($data['customerId'], $data['mandateId'], null)
->times($times)
->andReturn($mandate);
}
Expand Down Expand Up @@ -194,7 +194,7 @@ protected function withMockedGetMollieCustomer(int $times = 1, array $customerId
$customer->id = $id;

$mock->shouldReceive('execute')
->with($id)
->with($id, null)
->times($times)
->andReturn($customer);
}
Expand All @@ -207,7 +207,7 @@ protected function withMockedGetMollieMethodMinimumAmount(int $times = 1, int $a
{
$this->mock(GetMollieMethodMinimumAmount::class, function ($mock) use ($times, $amount) {
return $mock->shouldReceive('execute')
->with('directdebit', 'EUR')
->with('directdebit', 'EUR', null)
->times($times)
->andReturn(new Money($amount, new Currency('EUR')));
});
Expand All @@ -219,7 +219,7 @@ protected function withMockedGetMollieMethodMaximumAmount(int $times = 1, ?int $

$this->mock(GetMollieMethodMaximumAmount::class, function ($mock) use ($times, $returnedValue) {
return $mock->shouldReceive('execute')
->with('directdebit', 'EUR')
->with('directdebit', 'EUR', null)
->times($times)
->andReturn($returnedValue);
});
Expand Down Expand Up @@ -279,7 +279,7 @@ protected function withMockedGetMolliePayment(int $times = 1, ?Payment $molliePa

$this->mock(GetMolliePayment::class, function ($mock) use ($times, $molliePayment) {
return $mock->shouldReceive('execute')
->with($molliePayment->id, [])
->with($molliePayment->id, [], null)
->times($times)
->andReturn($molliePayment);
});
Expand All @@ -289,7 +289,7 @@ protected function withMockedGetMolliePaymentThrowingException(int $times = 1, s
{
$this->mock(GetMolliePayment::class, function ($mock) use ($times, $wrongId) {
return $mock->shouldReceive('execute')
->with($wrongId, [])
->with($wrongId, [], null)
->times($times)
->andThrow(new ApiException);
});
Expand Down

0 comments on commit d60305f

Please sign in to comment.