-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f7956b7
commit db99724
Showing
4 changed files
with
84 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
tests/Feature/Console/Commands/SendPaymentRemindersCommandTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
namespace Tests\Feature\Console\Commands; | ||
|
||
use App\Console\Commands\SendPaymentRemindersCommand; | ||
use App\Models\Booking; | ||
use App\Notifications\PaymentReminderNotification; | ||
use Carbon\Carbon; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Illuminate\Notifications\AnonymousNotifiable; | ||
use Illuminate\Support\Facades\Log; | ||
use Illuminate\Support\Facades\Notification; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use Tests\TestCase; | ||
use Tests\Traits\GeneratesTestData; | ||
|
||
#[CoversClass(Booking::class)] | ||
#[CoversClass(PaymentReminderNotification::class)] | ||
#[CoversClass(SendPaymentRemindersCommand::class)] | ||
class SendPaymentRemindersCommandTest extends TestCase | ||
{ | ||
use GeneratesTestData; | ||
use RefreshDatabase; | ||
|
||
public function testCommandRunsWithNoOverdueBookings(): void | ||
{ | ||
$this->artisan('app:send-payment-reminders') | ||
->expectsOutput('There are no booking options with unpaid bookings to check.') | ||
->assertSuccessful(); | ||
} | ||
|
||
public function testCommandSendsPaymentReminders(): void | ||
{ | ||
Notification::fake(); | ||
Log::shouldReceive('info')->once(); | ||
|
||
$booking = $this->fakeUnpaidBooking(); | ||
|
||
$this->artisan('app:send-payment-reminders') | ||
->expectsOutputToContain("Sent reminder to {$booking->email} for booking {$booking->id}.") | ||
->assertSuccessful(); | ||
Notification::assertSentTo(new AnonymousNotifiable(), PaymentReminderNotification::class, static function ($notification) use ($booking) { | ||
return str_contains($notification->toMail($booking->bookedByUser)->render(), $booking->bookedByUser->greeting); | ||
}); | ||
Notification::assertCount(1); | ||
} | ||
|
||
public function testCommandOutputsLogDataDuringDryRun(): void | ||
{ | ||
Notification::fake(); | ||
Log::shouldReceive('info')->once(); | ||
|
||
$booking = $this->fakeUnpaidBooking(); | ||
|
||
$this->artisan('app:send-payment-reminders --dry-run') | ||
->expectsOutputToContain("Reminder to {$booking->email} for booking {$booking->id} not sent because it's a dry run.") | ||
->assertSuccessful(); | ||
Notification::assertNothingSent(); | ||
} | ||
|
||
private function fakeUnpaidBooking(): Booking | ||
{ | ||
$bookingOption = self::createBookingOptionForEvent(attributes: [ | ||
'price' => 5, | ||
'payment_due_days' => 10, | ||
]); | ||
return self::createBooking($bookingOption, [ | ||
'paid_at' => null, | ||
'deleted_at' => null, | ||
'booked_at' => Carbon::today()->subWeekDays(11), | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters