Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
Add ability to get subjects and make assertions against a group of th…
Browse files Browse the repository at this point in the history
…em (#54)
  • Loading branch information
davidhemphill authored and besologic committed Oct 12, 2016
1 parent 4a34156 commit a422774
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 4 deletions.
5 changes: 5 additions & 0 deletions src/MailThief.php
Expand Up @@ -164,4 +164,9 @@ public function alwaysFrom($address, $name = null)
{
$this->from = ['address' => $address, 'name' => $name];
}

public function subjects()
{
return $this->messages->pluck('subject');
}
}
9 changes: 9 additions & 0 deletions src/Testing/InteractsWithMail.php
Expand Up @@ -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(
Expand Down
26 changes: 26 additions & 0 deletions tests/InteractsWithMailTest.php
Expand Up @@ -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();
Expand Down
23 changes: 19 additions & 4 deletions tests/MailThiefTest.php
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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.