Skip to content

Commit 4d7b98f

Browse files
committed
Fix tests
1 parent 8021503 commit 4d7b98f

File tree

2 files changed

+27
-28
lines changed

2 files changed

+27
-28
lines changed

src/Services/PaymentService.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,18 @@ public static function storePaymentAndShowUserBeforeProcessing(?int $user_id, fl
2121

2222
public static function getHandlerFqcn(string $uniqueName): BasePaymentHandler
2323
{
24-
$handler = BasePaymentHandler::getNamesOfPaymentHandlers()->filter(fn ($name) => $name === $uniqueName);
24+
$handlers = BasePaymentHandler::getNamesOfPaymentHandlers()->filter(fn($name) => $name === $uniqueName);
2525

26-
if ($handler->isEmpty()) {
26+
if ($handlers->isEmpty()) {
2727
throw new \Exception("No handler found with name '{$uniqueName}'");
2828
}
2929

30-
if ($handler->count() !== 1) {
30+
if ($handlers->count() !== 1) {
3131
throw new \Exception("Multiple handler found with name '{$uniqueName}'");
3232
}
3333

34-
return $handler
35-
->map(fn ($name, $key) => new $key())
34+
return $handlers
35+
->map(fn($name, $key) => new $key())
3636
->sole();
3737
}
3838

tests/PaymentRequeryTest.php

Lines changed: 22 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Damms005\LaravelMultipay\Models\Payment;
77
use Damms005\LaravelMultipay\ValueObjects\ReQuery;
88
use Damms005\LaravelMultipay\Services\PaymentHandlers\Remita;
9-
use Damms005\LaravelMultipay\Contracts\PaymentHandlerInterface;
109
use Damms005\LaravelMultipay\Services\PaymentHandlers\BasePaymentHandler;
1110
use Damms005\LaravelMultipay\Events\SuccessfulLaravelMultipayPaymentEvent;
1211

@@ -24,22 +23,22 @@
2423
// it("processes payment webhooks", function () {});
2524

2625
it('calls payment handler for payment re-query', function () {
27-
app()->bind(PaymentHandlerInterface::class, function ($app) {
28-
/**
29-
* @var Mock<TObject>
30-
*/
31-
$mock = mock(Remita::class);
32-
$mock->makePartial();
33-
34-
$mock->expects('reQuery')->andReturn(
26+
/**
27+
* @var Mock<TObject>
28+
*/
29+
$mock = mock(Remita::class);
30+
$mock->makePartial();
31+
32+
$mock->shouldReceive('reQuery')
33+
->once()
34+
->andReturn(
3535
new ReQuery(
3636
payment: new Payment(),
3737
responseDetails: ['status' => 'Successful'],
3838
),
3939
);
4040

41-
return $mock;
42-
});
41+
app()->bind(Remita::class, fn($app) => $mock);
4342

4443
app()->make(BasePaymentHandler::class)->reQueryUnsuccessfulPayment(
4544
Payment::factory()->create(['payment_processor_name' => Remita::getUniquePaymentHandlerName()])
@@ -68,29 +67,29 @@
6867

6968
Event::fake();
7069

71-
app()
72-
->make(BasePaymentHandler::class)
73-
->reQueryUnsuccessfulPayment(
74-
Payment::factory()->create(['payment_processor_name' => Remita::getUniquePaymentHandlerName()])
75-
);
70+
app()->make(BasePaymentHandler::class)->reQueryUnsuccessfulPayment(
71+
Payment::factory()->create(['payment_processor_name' => Remita::getUniquePaymentHandlerName()])
72+
);
7673

7774
Event::assertDispatched(SuccessfulLaravelMultipayPaymentEvent::class);
7875
});
7976

8077
it('does not fire success events for re-query of unsuccessful payments', function () {
81-
app()->bind(PaymentHandlerInterface::class, function ($app) {
78+
app()->bind(Remita::class, function ($app) {
8279
/**
8380
* @var Mock<TObject>
8481
*/
8582
$mock = mock(Remita::class);
8683
$mock->makePartial();
8784

88-
$mock->expects('reQuery')->andReturn(
89-
new ReQuery(
90-
payment: new Payment(['is_success' => false]),
91-
responseDetails: ['status' => 'Went South!'],
92-
),
93-
);
85+
$mock->shouldReceive('reQuery')
86+
->once()
87+
->andReturn(
88+
new ReQuery(
89+
payment: new Payment(['is_success' => false]),
90+
responseDetails: ['status' => 'Went South!'],
91+
),
92+
);
9493

9594
return $mock;
9695
});

0 commit comments

Comments
 (0)