Permalink
Browse files

Add ability to get subjects and make assertions against a group of th…

…em (#54)
  • Loading branch information...
1 parent 4a34156 commit a42277459092ae87f5ac11271f969625509f7f49 @davidhemphill davidhemphill committed with besologic Oct 12, 2016
Showing with 59 additions and 4 deletions.
  1. +5 −0 src/MailThief.php
  2. +9 −0 src/Testing/InteractsWithMail.php
  3. +26 −0 tests/InteractsWithMailTest.php
  4. +19 −4 tests/MailThiefTest.php
View
@@ -164,4 +164,9 @@ public function alwaysFrom($address, $name = null)
{
$this->from = ['address' => $address, 'name' => $name];
}
+
+ public function subjects()
+ {
+ return $this->messages->pluck('subject');
+ }
}
@@ -93,6 +93,15 @@ public function seeHeaders($name, $value = null)
return $this;
}
+ protected function seeInSubjects($subjects)
+ {
+ $subjects = (array) $subjects;
+
+ foreach ($subjects as $subject) {
+ $this->assertTrue(in_array($subject, $this->mailer->subjects()->all()));
+ }
+ }
+
protected function seeMessage()
{
$this->assertNotNull(
@@ -52,6 +52,32 @@ public function test_see_message_with_subject()
$this->seeMessageWithSubject('foo');
}
+ public function test_see_in_subjects()
+ {
+ $mailer = $this->mailer = $this->getMailThief();
+
+ collect(['foo@bar.tld', 'baz@qux.tld'])->each(function ($email) use ($mailer) {
+ $mailer->send('example-view', [], function ($m) use ($email) {
+ $m->subject("Message for {$email}");
+ });
+ });
+
+ $this->seeInSubjects("Message for baz@qux.tld");
+ }
+
+ public function test_see_in_subjects_with_array()
+ {
+ $mailer = $this->mailer = $this->getMailThief();
+
+ collect(['Taylor Otwell', 'Adam Wathan'])->each(function ($name) use ($mailer) {
+ $mailer->send('example-view', [], function ($m) use ($name) {
+ $m->subject("Message for {$name}");
+ });
+ });
+
+ $this->seeInSubjects(["Message for Taylor Otwell", "Message for Adam Wathan"]);
+ }
+
public function test_see_message_from()
{
$mailer = $this->mailer = $this->getMailThief();
@@ -102,7 +102,7 @@ public function test_from_overrides_previous_from()
public function test_global_from_is_respected()
{
$mailer = $this->getMailThief();
-
+
$mailer->alwaysFrom('john@example.com');
$mailer->send('example-view', [], function ($m) {
@@ -115,7 +115,7 @@ public function test_global_from_is_respected()
public function test_global_from_gets_overwritten_if_specified()
{
$mailer = $this->getMailThief();
-
+
$mailer->alwaysFrom('john@example.com');
$mailer->send('example-view', [], function ($m) {
@@ -226,7 +226,7 @@ public function test_queue_on_is_sent_immediately()
public function test_global_from_is_respected_when_email_is_queued()
{
$mailer = $this->getMailThief();
-
+
$mailer->alwaysFrom('john@example.com');
$mailer->queue('example-view', [], function ($m) {
@@ -272,7 +272,7 @@ public function test_later_messages_are_not_included_when_checking_to_see_if_an_
public function test_global_from_is_respected_when_email_set_to_later_with_a_delay()
{
$mailer = $this->getMailThief();
-
+
$mailer->alwaysFrom('john@example.com');
$mailer->later(10, 'example-view', [], function ($m) {
@@ -403,4 +403,19 @@ public function test_it_reads_values_from_the_config_helper_function()
$this->assertEquals(['foo@bar.tld' => 'First Last'], $mailer->lastMessage()->from->all());
}
+
+ public function test_it_gets_subjects()
+ {
+ $mailer = $this->getMailThief();
+
+ collect(['foo@bar.tld', 'baz@qux.tld'])->each(function ($email) use ($mailer) {
+ $mailer->send('example-view', [], function ($m) use ($email) {
+ $m->subject("Message for {$email}");
+ });
+ });
+
+ $messages = ["Message for foo@bar.tld", "Message for baz@qux.tld"];
+
+ $this->assertEquals($messages, $mailer->subjects()->all());
+ }
}

0 comments on commit a422774

Please sign in to comment.