Skip to content
This repository was archived by the owner on Apr 8, 2024. It is now read-only.

Commit edff6a9

Browse files
authored
Merge pull request #24 from spinen/feature/checkForPriority
Feature/check for priority
2 parents e7df9cf + 7593fee commit edff6a9

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

readme.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ You mixin the assertions with the ```Spinen\MailAssertions\MailTracking``` trait
3737
* seeEmailDoesNotContain
3838
* seeEmailEquals
3939
* seeEmailFrom
40+
* seeEmailPriorityEquals
4041
* seeEmailReplyTo
4142
* seeEmailSubjectContains
4243
* seeEmailSubjectDoesNotContain

src/MailTracking.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,26 @@ protected function seeEmailFrom($sender, Swift_Message $message = null)
202202
return $this;
203203
}
204204

205+
/**
206+
* Assert that the last email had the given priority level.
207+
* The value is an integer where 1 is the highest priority and 5 is the lowest.
208+
*
209+
* @param integer $priority
210+
* @param Swift_Message|null $message
211+
*
212+
* @return PHPUnit_Framework_TestCase $this
213+
*/
214+
protected function seeEmailPriorityEquals($priority, Swift_Message $message = null)
215+
{
216+
$actual_priority = $this->getEmail($message)
217+
->getPriority();
218+
219+
$this->assertEquals($priority, $actual_priority,
220+
"The last email sent had a priority of $actual_priority but expected $priority.");
221+
222+
return $this;
223+
}
224+
205225
/**
206226
* Assert that the last email was set to reply to the given address.
207227
*

tests/MailTrackingTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,25 @@ public function it_checks_email_from_address()
215215
$this->mail_tracking->recordMail($message);
216216

217217
$this->assertEquals($this->mail_tracking, $this->callProtectedMethod('seeEmailFrom', ['from@domain.tld']));
218+
}
219+
220+
/**
221+
* @test
222+
* @group unit
223+
*/
224+
public function it_checks_email_priority()
225+
{
226+
$message = $this->makeMessage('subject', 'body', 'to@domain.tld', 'from@domain.tld');
227+
$message->setPriority(1);
228+
$this->mail_tracking->recordMail($message);
229+
230+
$this->assertEquals($this->mail_tracking, $this->callProtectedMethod('seeEmailPriorityEquals', [1]));
231+
232+
// The priority can't be set to anything greater than 5
233+
$message->setPriority(6);
234+
$this->mail_tracking->recordMail($message);
235+
236+
$this->assertEquals($this->mail_tracking, $this->callProtectedMethod('seeEmailPriorityEquals', [5]));
218237
}
219238

220239
/**
@@ -305,7 +324,7 @@ public function it_checks_email_to_address()
305324
* @test
306325
* @group unit
307326
*/
308-
public function it_knows_if_email_has_not_been_sent_or_not()
327+
public function it_knows_if_email_has_been_sent_or_not()
309328
{
310329
$this->assertEquals($this->mail_tracking, $this->callProtectedMethod('seeEmailWasNotSent'));
311330

0 commit comments

Comments
 (0)