|
1 | 1 | <?php
|
2 | 2 |
|
3 | 3 | use Mockery\Mock;
|
| 4 | +use Illuminate\Support\Str; |
4 | 5 | use Illuminate\Support\Facades\Event;
|
5 | 6 | use Damms005\LaravelMultipay\Models\Payment;
|
| 7 | +use Damms005\LaravelMultipay\ValueObjects\ReQuery; |
6 | 8 | use Damms005\LaravelMultipay\Services\PaymentHandlers\Remita;
|
7 | 9 | use Damms005\LaravelMultipay\Contracts\PaymentHandlerInterface;
|
8 | 10 | use Damms005\LaravelMultipay\Services\PaymentHandlers\BasePaymentHandler;
|
9 | 11 | use Damms005\LaravelMultipay\Events\SuccessfulLaravelMultipayPaymentEvent;
|
10 |
| -use Damms005\LaravelMultipay\ValueObjects\ReQuery; |
11 | 12 |
|
12 | 13 | beforeEach(function () {
|
13 | 14 | $payment = createPayment();
|
|
40 | 41 | return $mock;
|
41 | 42 | });
|
42 | 43 |
|
43 |
| - app()->make(BasePaymentHandler::class)->reQueryUnsuccessfulPayment(new Payment()); |
| 44 | + app()->make(BasePaymentHandler::class)->reQueryUnsuccessfulPayment( |
| 45 | + Payment::factory()->create(['payment_processor_name' => Remita::getUniquePaymentHandlerName()]) |
| 46 | + ); |
44 | 47 | });
|
45 | 48 |
|
46 | 49 | it('fires success events for re-query of successful payments', function () {
|
47 |
| - app()->bind(PaymentHandlerInterface::class, function () { |
| 50 | + app()->bind(Remita::class, function () { |
48 | 51 | /** @var Mock<TObject> */
|
49 | 52 | $mock = mock(Remita::class);
|
50 | 53 | $mock->makePartial();
|
51 | 54 |
|
52 | 55 | $mock->expects('reQuery')->andReturn(
|
53 | 56 | new ReQuery(
|
54 |
| - payment: new Payment(['is_success' => true]), |
| 57 | + payment: Payment::factory()->create([ |
| 58 | + 'is_success' => true, |
| 59 | + 'transaction_reference' => Str::random(), |
| 60 | + 'payment_processor_name' => Remita::getUniquePaymentHandlerName(), |
| 61 | + ]), |
55 | 62 | responseDetails: ['status' => 'Successful'],
|
56 | 63 | ),
|
57 | 64 | );
|
|
60 | 67 | });
|
61 | 68 |
|
62 | 69 | Event::fake();
|
63 |
| - app()->make(BasePaymentHandler::class)->reQueryUnsuccessfulPayment(new Payment()); |
| 70 | + |
| 71 | + app() |
| 72 | + ->make(BasePaymentHandler::class) |
| 73 | + ->reQueryUnsuccessfulPayment( |
| 74 | + Payment::factory()->create(['payment_processor_name' => Remita::getUniquePaymentHandlerName()]) |
| 75 | + ); |
64 | 76 |
|
65 | 77 | Event::assertDispatched(SuccessfulLaravelMultipayPaymentEvent::class);
|
66 | 78 | });
|
|
85 | 97 |
|
86 | 98 | Event::fake();
|
87 | 99 |
|
88 |
| - app()->make(BasePaymentHandler::class)->reQueryUnsuccessfulPayment(new Payment()); |
| 100 | + app()->make(BasePaymentHandler::class)->reQueryUnsuccessfulPayment( |
| 101 | + Payment::factory()->create(['payment_processor_name' => Remita::getUniquePaymentHandlerName()]) |
| 102 | + ); |
89 | 103 |
|
90 | 104 | Event::assertNotDispatched(SuccessfulLaravelMultipayPaymentEvent::class);
|
91 | 105 | });
|
0 commit comments