Created
March 28, 2017 11:46
-
-
Save sebastiaanluca/514c72c95ae85ee188d698449a08c60c to your computer and use it in GitHub Desktop.
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
<?php | |
namespace App\Mail; | |
use Illuminate\Container\Container; | |
use Illuminate\Mail\Mailable as BaseMailable; | |
use PHPUnit\Framework\Assert; | |
class Mailable extends BaseMailable | |
{ | |
/** | |
* @return array | |
*/ | |
public function getRenderedBody() : array | |
{ | |
Container::getInstance()->call([$this, 'build']); | |
return $this->buildView(); | |
} | |
/** | |
* @param string $string | |
* | |
* @return $this | |
*/ | |
public function assertHtmlBodyContains(string $string) | |
{ | |
Assert::assertTrue( | |
str_contains($this->getRenderedBody()['html'], $string), | |
"The rendered HTML body does not contain \"$string\"." | |
); | |
return $this; | |
} | |
/** | |
* @param string $string | |
* | |
* @return $this | |
*/ | |
public function assertTextBodyContains(string $string) | |
{ | |
Assert::assertTrue( | |
str_contains($this->getRenderedBody()['text'], $string), | |
"The rendered text body does not contain \"$string\"." | |
); | |
return $this; | |
} | |
} |
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
<?php | |
public function testItCanMail() | |
{ | |
Mail::assertSent(MyMail::class, function (MyMail $mail) use ($url) { | |
return $mail->assertHtmlBodyContains($url) | |
->assertTextBodyContains($url) | |
->hasTo(config('app.mail_to')); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment