|
6 | 6 | use Damms005\LaravelMultipay\Models\Payment; |
7 | 7 | use Damms005\LaravelMultipay\ValueObjects\ReQuery; |
8 | 8 | use Damms005\LaravelMultipay\Services\PaymentHandlers\Remita; |
9 | | -use Damms005\LaravelMultipay\Contracts\PaymentHandlerInterface; |
10 | 9 | use Damms005\LaravelMultipay\Services\PaymentHandlers\BasePaymentHandler; |
11 | 10 | use Damms005\LaravelMultipay\Events\SuccessfulLaravelMultipayPaymentEvent; |
12 | 11 |
|
|
24 | 23 | // it("processes payment webhooks", function () {}); |
25 | 24 |
|
26 | 25 | 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( |
35 | 35 | new ReQuery( |
36 | 36 | payment: new Payment(), |
37 | 37 | responseDetails: ['status' => 'Successful'], |
38 | 38 | ), |
39 | 39 | ); |
40 | 40 |
|
41 | | - return $mock; |
42 | | - }); |
| 41 | + app()->bind(Remita::class, fn($app) => $mock); |
43 | 42 |
|
44 | 43 | app()->make(BasePaymentHandler::class)->reQueryUnsuccessfulPayment( |
45 | 44 | Payment::factory()->create(['payment_processor_name' => Remita::getUniquePaymentHandlerName()]) |
|
68 | 67 |
|
69 | 68 | Event::fake(); |
70 | 69 |
|
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 | + ); |
76 | 73 |
|
77 | 74 | Event::assertDispatched(SuccessfulLaravelMultipayPaymentEvent::class); |
78 | 75 | }); |
79 | 76 |
|
80 | 77 | 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) { |
82 | 79 | /** |
83 | 80 | * @var Mock<TObject> |
84 | 81 | */ |
85 | 82 | $mock = mock(Remita::class); |
86 | 83 | $mock->makePartial(); |
87 | 84 |
|
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 | + ); |
94 | 93 |
|
95 | 94 | return $mock; |
96 | 95 | }); |
|
0 commit comments