diff --git a/tests/Unit/Services/LoanServiceTest.php b/tests/Unit/Services/LoanServiceTest.php index 6ddb4cd..b39d462 100644 --- a/tests/Unit/Services/LoanServiceTest.php +++ b/tests/Unit/Services/LoanServiceTest.php @@ -13,6 +13,7 @@ use Illuminate\Support\Carbon; use App\Models\ReceivedRepayment; use App\Models\ScheduledRepayment; +use Illuminate\Support\Collection; use PHPUnit\Framework\Attributes\Test; use App\Exceptions\AlreadyRepaidException; use PHPUnit\Framework\Attributes\DataProvider; @@ -249,19 +250,17 @@ public function can_pay_multiple_scheduled_payments_on_the_same_day(): void ); // 2. Act - $loan->scheduledRepayments()->each(callback: function (ScheduledRepayment $scheduledRepayment) use ($loan): void { - LoanFacade::repayLoan( - loan: $loan, - amount: $scheduledRepayment->amount, - currencyCode: $loan->currency_code, - receivedAt: now() - ); - }); + Collection::times(number: 6, callback: fn () => LoanFacade::repayLoan( + loan: $loan, + amount: 1000, + currencyCode: $loan->currency_code, + receivedAt: now() + )); // 3. Assert $this->assertEquals(expected: PaymentStatus::REPAID, actual: $loan->status); - $this->assertEquals(expected: 3, actual: $loan->receivedRepayments()->count()); + $this->assertEquals(expected: 6, actual: $loan->receivedRepayments()->count()); $loan->scheduledRepayments()->each(callback: function (ScheduledRepayment $scheduledRepayment): void { $this->assertEquals(expected: PaymentStatus::REPAID, actual: $scheduledRepayment->status);