-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NotificationFake can assert preferred locale (#26205)
When a notifiable implements the HasLocalePreference interface, make the NotificationFake store the locale for assertions. Add a similar feature test for MailFake that already supports the same assertion capabilities.
- Loading branch information
1 parent
6debff6
commit 2aa4c6e
Showing
3 changed files
with
48 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
use Illuminate\Support\Testing\Fakes\MailFake; | ||
use PHPUnit\Framework\ExpectationFailedException; | ||
use PHPUnit\Framework\Constraint\ExceptionMessage; | ||
use Illuminate\Contracts\Translation\HasLocalePreference; | ||
|
||
class SupportTestingMailFakeTest extends TestCase | ||
{ | ||
|
@@ -42,6 +43,17 @@ public function testAssertSent() | |
$this->fake->assertSent(MailableStub::class); | ||
} | ||
|
||
public function testAssertSentWhenRecipientHasPreferredLocale() | ||
{ | ||
$user = new LocalizedRecipientStub; | ||
|
||
$this->fake->to($user)->send($this->mailable); | ||
|
||
$this->fake->assertSent(MailableStub::class, function ($mail) use ($user) { | ||
return $mail->hasTo($user) && $mail->locale === 'au'; | ||
}); | ||
} | ||
|
||
public function testAssertNotSent() | ||
{ | ||
$this->fake->assertNotSent(MailableStub::class); | ||
|
@@ -164,3 +176,13 @@ public function build() | |
->withLastName('Otwell'); | ||
} | ||
} | ||
|
||
class LocalizedRecipientStub implements HasLocalePreference | ||
{ | ||
public $email = '[email protected]'; | ||
|
||
public function preferredLocale() | ||
{ | ||
return 'au'; | ||
} | ||
} |
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