forked from laravel/framework
-
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.
Add
assertSentTo
shorthand (laravel#52083)
* Add `assertSentTo` shorthand * Add multiple example to test * Overload existing method * Add negative assertions
- Loading branch information
1 parent
435098a
commit ddda68e
Showing
2 changed files
with
161 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,6 +50,34 @@ public function testAssertSent() | |
$this->fake->assertSent(MailableStub::class); | ||
} | ||
|
||
public function testAssertSentTo() | ||
{ | ||
try { | ||
$this->fake->assertSent(MailableStub::class, '[email protected]'); | ||
$this->fail(); | ||
} catch (ExpectationFailedException $e) { | ||
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\MailableStub] mailable was not sent to address [[email protected]].', $e->getMessage()); | ||
} | ||
|
||
$this->fake->to('[email protected]')->send($this->mailable); | ||
|
||
$this->fake->assertSent(MailableStub::class, '[email protected]'); | ||
} | ||
|
||
public function testAssertSentToMultiple() | ||
{ | ||
$this->fake->to('[email protected]')->send($this->mailable); | ||
$this->fake->to('[email protected]')->send($this->mailable); | ||
|
||
$this->fake->to(['[email protected]', '[email protected]'])->send($this->mailable); | ||
|
||
$this->fake->assertSent(MailableStub::class, 3); | ||
$this->fake->assertSent( | ||
MailableStub::class, | ||
['[email protected]', '[email protected]', '[email protected]', '[email protected]'] | ||
); | ||
} | ||
|
||
public function testAssertSentWhenRecipientHasPreferredLocale() | ||
{ | ||
$user = new LocalizedRecipientStub; | ||
|
@@ -118,6 +146,30 @@ public function testAssertNotSentWithClosure() | |
$this->fake->assertNotSent($callback); | ||
} | ||
|
||
public function testAssertNotSentWithString() | ||
{ | ||
$this->fake->assertNotSent(MailableStub::class, '[email protected]'); | ||
|
||
$this->fake->to('[email protected]')->send($this->mailable); | ||
|
||
$this->expectException(ExpectationFailedException::class); | ||
$this->expectExceptionMessage('The unexpected ['.MailableStub::class.'] mailable was sent to address [[email protected]].'); | ||
|
||
$this->fake->assertNotSent(MailableStub::class, '[email protected]'); | ||
} | ||
|
||
public function testAssertNotSentWithArray() | ||
{ | ||
$this->fake->assertNotSent(MailableStub::class, ['[email protected]', '[email protected]']); | ||
|
||
$this->fake->to('[email protected]')->send($this->mailable); | ||
|
||
$this->expectException(ExpectationFailedException::class); | ||
$this->expectExceptionMessage('The unexpected ['.MailableStub::class.'] mailable was sent to address [[email protected]].'); | ||
|
||
$this->fake->assertNotSent(MailableStub::class, ['[email protected]', '[email protected]']); | ||
} | ||
|
||
public function testAssertSentTimes() | ||
{ | ||
$this->fake->to('[email protected]')->send($this->mailable); | ||
|
@@ -162,6 +214,34 @@ public function testAssertQueued() | |
$this->fake->assertQueued(MailableStub::class); | ||
} | ||
|
||
public function testAssertQueuedTo() | ||
{ | ||
try { | ||
$this->fake->assertQueued(MailableStub::class, '[email protected]'); | ||
$this->fail(); | ||
} catch (ExpectationFailedException $e) { | ||
$this->assertStringContainsString('The expected [Illuminate\Tests\Support\MailableStub] mailable was not queued to address [[email protected]].', $e->getMessage()); | ||
} | ||
|
||
$this->fake->to('[email protected]')->queue($this->mailable); | ||
|
||
$this->fake->assertQueued(MailableStub::class, '[email protected]'); | ||
} | ||
|
||
public function testAssertQueuedToMultiple() | ||
{ | ||
$this->fake->to('[email protected]')->queue($this->mailable); | ||
$this->fake->to('[email protected]')->queue($this->mailable); | ||
|
||
$this->fake->to(['[email protected]', '[email protected]'])->queue($this->mailable); | ||
|
||
$this->fake->assertQueued(MailableStub::class, 3); | ||
$this->fake->assertQueued( | ||
MailableStub::class, | ||
['[email protected]', '[email protected]', '[email protected]', '[email protected]'] | ||
); | ||
} | ||
|
||
public function testAssertQueuedTimes() | ||
{ | ||
$this->fake->to('[email protected]')->queue($this->mailable); | ||
|
@@ -177,6 +257,30 @@ public function testAssertQueuedTimes() | |
$this->fake->assertQueued(MailableStub::class, 2); | ||
} | ||
|
||
public function testAssertNotQueuedWithString() | ||
{ | ||
$this->fake->assertNotQueued(MailableStub::class, '[email protected]'); | ||
|
||
$this->fake->to('[email protected]')->queue($this->mailable); | ||
|
||
$this->expectException(ExpectationFailedException::class); | ||
$this->expectExceptionMessage('The unexpected ['.MailableStub::class.'] mailable was queued to address [[email protected]].'); | ||
|
||
$this->fake->assertNotQueued(MailableStub::class, '[email protected]'); | ||
} | ||
|
||
public function testAssertNotQueuedWithArray() | ||
{ | ||
$this->fake->assertNotQueued(MailableStub::class, ['[email protected]', '[email protected]']); | ||
|
||
$this->fake->to('[email protected]')->queue($this->mailable); | ||
|
||
$this->expectException(ExpectationFailedException::class); | ||
$this->expectExceptionMessage('The unexpected ['.MailableStub::class.'] mailable was queued to address [[email protected]].'); | ||
|
||
$this->fake->assertNotQueued(MailableStub::class, ['[email protected]', '[email protected]']); | ||
} | ||
|
||
public function testAssertQueuedCount() | ||
{ | ||
$this->fake->to('[email protected]')->queue($this->mailable); | ||
|