Skip to content

Commit cdd4fef

Browse files
committed
attempt to fix tests p2
1 parent dceb8e3 commit cdd4fef

File tree

8 files changed

+26
-16
lines changed

8 files changed

+26
-16
lines changed

tests/Feature/Checkins/Ui/AccessoryCheckinTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function testEmailNotSentToUserIfSettingDisabled()
7777
'',
7878
));
7979

80-
Mail::assertSent(CheckoutAccessoryMail::class, function ($mail) use ($accessory, $user) {
80+
Mail::assertNotSent(CheckoutAccessoryMail::class, function ($mail) use ($accessory, $user) {
8181
return $mail->hasTo($user) && $mail->contains($accessory);
8282
});
8383
}

tests/Feature/Checkouts/Api/AccessoryCheckoutTest.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
namespace Tests\Feature\Checkouts\Api;
44

5+
use App\Mail\CheckoutAccessoryMail;
56
use App\Models\Accessory;
67
use App\Models\Actionlog;
78
use App\Models\User;
89
use App\Notifications\CheckoutAccessoryNotification;
10+
use Illuminate\Support\Facades\Mail;
911
use Illuminate\Support\Facades\Notification;
1012
use Tests\Concerns\TestsPermissionsRequirement;
1113
use Tests\TestCase;
@@ -146,7 +148,7 @@ public function testAccessoryCannotBeCheckedOutToInvalidUser()
146148

147149
public function testUserSentNotificationUponCheckout()
148150
{
149-
Notification::fake();
151+
Mail::fake();
150152

151153
$accessory = Accessory::factory()->requiringAcceptance()->create();
152154
$user = User::factory()->create();
@@ -157,7 +159,9 @@ public function testUserSentNotificationUponCheckout()
157159
'checkout_to_type' => 'user',
158160
]);
159161

160-
Notification::assertSentTo($user, CheckoutAccessoryNotification::class);
162+
Mail::assertSent(CheckoutAccessoryMail::class, function ($mail) use ($accessory, $user) {
163+
return $mail->hasTo($user) && $mail->contains($accessory);
164+
});
161165
}
162166

163167
public function testActionLogCreatedUponCheckout()

tests/Feature/Checkouts/Api/ConsumableCheckoutTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
namespace Tests\Feature\Checkouts\Api;
44

5+
use App\Mail\CheckoutConsumableMail;
56
use App\Models\Actionlog;
67
use App\Models\Consumable;
78
use App\Models\User;
89
use App\Notifications\CheckoutConsumableNotification;
10+
use Illuminate\Support\Facades\Mail;
911
use Illuminate\Support\Facades\Notification;
1012
use Tests\TestCase;
1113

@@ -51,7 +53,7 @@ public function testConsumableCanBeCheckedOut()
5153

5254
public function testUserSentNotificationUponCheckout()
5355
{
54-
Notification::fake();
56+
Mail::fake();
5557

5658
$consumable = Consumable::factory()->requiringAcceptance()->create();
5759

@@ -62,7 +64,7 @@ public function testUserSentNotificationUponCheckout()
6264
'assigned_to' => $user->id,
6365
]);
6466

65-
Notification::assertSentTo($user, CheckoutConsumableNotification::class);
67+
Mail::assertSentTo($user, CheckoutConsumableMail::class);
6668
}
6769

6870
public function testActionLogCreatedUponCheckout()

tests/Feature/Checkouts/Ui/AccessoryCheckoutTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public function testUserSentNotificationUponCheckout()
171171
]);
172172

173173
Mail::assertSent(CheckoutAccessoryMail::class, function ($mail) use ($accessory, $user) {
174-
return $mail->hasTo($user) && $mail->contains($accessory);
174+
return $mail->hasTo($user->email) && $mail->accessory->is($accessory);
175175
});
176176
}
177177

tests/Feature/Checkouts/Ui/ConsumableCheckoutTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public function testUserSentNotificationUponCheckout()
6666
]);
6767

6868
Mail::assertSent(CheckoutConsumableMail::class, function ($mail) use ($consumable, $user) {
69-
return $mail->hasTo($user) && $mail->consumables->contains($consumable);
69+
return $mail->hasTo($user->email) && $mail->consumable->is($consumable);
7070
});
7171
}
7272

tests/Feature/Importing/Api/ImportAssetsTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ public function importAsset(): void
140140
//Notes is never read.
141141
// $this->assertEquals($row['notes'], $newAsset->notes);
142142

143-
Mail::assertSent($assignee, CheckoutAssetMail::class);
143+
Mail::assertSent(CheckoutAssetMail::class, function ($mail) use ($assignee) {
144+
return $mail->hasTo($assignee->email);
145+
});
144146
}
145147

146148
#[Test]

tests/Feature/Notifications/Email/EmailNotificationsUponCheckinTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ protected function setUp(): void
1919
{
2020
parent::setUp();
2121

22-
Notification::fake();
22+
Mail::fake();
2323
}
2424

2525
public function testCheckInEmailSentToUserIfSettingEnabled()

tests/Unit/NotificationTest.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
<?php
22
namespace Tests\Unit;
33

4+
use App\Mail\CheckoutAssetMail;
45
use App\Models\User;
56
use App\Models\Asset;
67
use App\Models\AssetModel;
78
use App\Models\Category;
89
use Carbon\Carbon;
910
use App\Notifications\CheckoutAssetNotification;
11+
use Illuminate\Support\Facades\Mail;
1012
use Illuminate\Support\Facades\Notification;
1113
use Tests\TestCase;
1214

@@ -29,13 +31,13 @@ public function testAUserIsEmailedIfTheyCheckoutAnAssetWithEULA()
2931
'purchase_date' => Carbon::createFromDate(2017, 1, 1)->hour(0)->minute(0)->second(0)->format('Y-m-d')
3032
]);
3133

32-
Notification::fake();
34+
Mail::fake();
3335
$asset->checkOut($user, $admin->id);
34-
Notification::assertSentTo($user, CheckoutAssetNotification::class);
36+
Mail::assertSent($user, CheckoutAssetMail::class);
3537
}
3638
public function testDefaultEulaIsSentWhenSetInCategory()
3739
{
38-
Notification::fake();
40+
Mail::fake();
3941

4042
$this->settings->setEula('My Custom EULA Text');
4143

@@ -51,10 +53,10 @@ public function testDefaultEulaIsSentWhenSetInCategory()
5153

5254
$asset->checkOut($user, User::factory()->superuser()->create()->id);
5355

54-
Notification::assertSentTo($user, CheckoutAssetNotification::class, function ($notification) {
55-
$content = $notification->toMail()->render();
56-
57-
return str_contains($content, 'My Custom EULA Text') && !str_contains($content, 'EULA Text that should not be used');
56+
Mail::assertSent(CheckoutAssetMail::class, function ($mail) use ($user) {
57+
return $mail->hasTo($user->email) &&
58+
str_contains($mail->render(), 'My Custom EULA Text') &&
59+
!str_contains($mail->render(), 'EULA Text that should not be used');
5860
});
5961
}
6062
}

0 commit comments

Comments
 (0)