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

Commit 166c4ce

Browse files
committed
Merge branch 'release/0.1.0'
2 parents 8834f56 + f556a3f commit 166c4ce

File tree

7 files changed

+121
-18
lines changed

7 files changed

+121
-18
lines changed

.travis.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ env:
1212
- setup=basic
1313

1414
matrix:
15-
allow_failures:
16-
- php: 7.0
1715
include:
18-
- php: 5.5.9
16+
- php: 5.6
1917
env: setup=lowest
20-
- php: 5.5.9
18+
- php: 5.6
2119
env: setup=stable
2220

2321
sudo: false

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.0.4
1+
0.1.0

composer.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
],
1818
"require": {
1919
"php": ">=5.5.0",
20-
"illuminate/support": "~5.1.10|5.2.*",
20+
"illuminate/support": "~5.1.10|5.2.*|5.3.*",
2121
"swiftmailer/swiftmailer": "~5.1"
2222
},
2323
"require-dev": {
24-
"mockery/mockery": "~0.9.1",
25-
"phpunit/phpunit": "~4.0",
26-
"psy/psysh": "~0.5.1",
27-
"satooshi/php-coveralls": "~0.6.1",
28-
"symfony/var-dumper": "~2.7|3.0.*"
24+
"mockery/mockery": "^0.9.1",
25+
"phpunit/phpunit": "~4.0|~5.0",
26+
"psy/psysh": "^0.5.1",
27+
"satooshi/php-coveralls": "^0.6.1",
28+
"symfony/var-dumper": "~2.7|~3.0"
2929
},
3030
"autoload": {
3131
"psr-4": {

readme.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,19 @@ You mixin the assertions with the ```Spinen\MailAssertions\MailTracking``` trait
3232
* seeEmailBcc
3333
* seeEmailCc
3434
* seeEmailContains
35+
* seeEmailContentTypeEquals
36+
* seeEmailCountEquals
3537
* seeEmailDoesNotContain
3638
* seeEmailEquals
3739
* seeEmailFrom
40+
* seeEmailPriorityEquals
3841
* seeEmailReplyTo
3942
* seeEmailSubjectContains
4043
* seeEmailSubjectDoesNotContain
4144
* seeEmailSubjectEquals
4245
* seeEmailTo
4346
* seeEmailWasNotSent
4447
* seeEmailWasSent
45-
* seeEmailsSent
4648

4749
NOTE: If there was more than 1 email sent, then the assertions look at the last email.
4850

src/MailTracking.php

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,24 @@ protected function seeEmailContains($excerpt, Swift_Message $message = null)
134134
return $this;
135135
}
136136

137+
/**
138+
* Assert that the last email's content type equals the given text.
139+
* For example, "text/plain" and "text/html" are valid content types for an email.
140+
*
141+
* @param string $content_type
142+
* @param Swift_Message|null $message
143+
*
144+
* @return PHPUnit_Framework_TestCase $this
145+
*/
146+
protected function seeEmailContentTypeEquals($content_type, Swift_Message $message = null)
147+
{
148+
$this->assertEquals($content_type, $this->getEmail($message)
149+
->getContentType(),
150+
"The last email sent did not contain the provided body.");
151+
152+
return $this;
153+
}
154+
137155
/**
138156
* Assert that the last email's body does not contain the given text.
139157
*
@@ -184,6 +202,26 @@ protected function seeEmailFrom($sender, Swift_Message $message = null)
184202
return $this;
185203
}
186204

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+
187225
/**
188226
* Assert that the last email was set to reply to the given address.
189227
*
@@ -207,8 +245,21 @@ protected function seeEmailReplyTo($reply_to, Swift_Message $message = null)
207245
* @param integer $count
208246
*
209247
* @return PHPUnit_Framework_TestCase $this
248+
* @deprecated in favor of seeEmailCountEquals
210249
*/
211250
protected function seeEmailsSent($count)
251+
{
252+
return $this->seeEmailCountEquals($count);
253+
}
254+
255+
/**
256+
* Assert that the given number of emails were sent.
257+
*
258+
* @param integer $count
259+
*
260+
* @return PHPUnit_Framework_TestCase $this
261+
*/
262+
protected function seeEmailCountEquals($count)
212263
{
213264
$emailsSent = count($this->emails);
214265

tests/MailRecorderTest.php

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
namespace Spinen\MailAssertions;
44

55
use Mockery;
6+
use PHPUnit_Framework_Error;
67
use PHPUnit_Framework_TestCase;
78
use StdClass;
89
use Swift_Events_SendEvent;
10+
use TypeError;
911

1012
/**
1113
* Class MailRecorderTest
@@ -32,7 +34,16 @@ public function it_can_be_constructed()
3234
*/
3335
public function it_cannot_be_constructed_without_a_PHPUnit_Framework_TestCase()
3436
{
35-
new MailRecorder();
37+
if (class_exists(TypeError::class)) {
38+
try {
39+
new MailRecorder();
40+
} catch (TypeError $e) {
41+
throw new PHPUnit_Framework_Error('Argument 1 passed to method must be an array, but not', 0,
42+
$e->getFile(), $e->getLine());
43+
}
44+
} else {
45+
new MailRecorder();
46+
}
3647
}
3748

3849
/**
@@ -42,7 +53,16 @@ public function it_cannot_be_constructed_without_a_PHPUnit_Framework_TestCase()
4253
*/
4354
public function it_cannot_be_constructed_with_class_other_than_a_PHPUnit_Framework_TestCase()
4455
{
45-
new MailRecorder(new StdClass());
56+
if (class_exists(TypeError::class)) {
57+
try {
58+
new MailRecorder(new StdClass());
59+
} catch (TypeError $e) {
60+
throw new PHPUnit_Framework_Error('Argument 1 passed to method must be an array, but not', 0,
61+
$e->getFile(), $e->getLine());
62+
}
63+
} else {
64+
new MailRecorder(new StdClass());
65+
}
4666
}
4767

4868
/**

tests/MailTrackingTest.php

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,19 @@ public function it_checks_email_cc_address()
156156
$this->assertEquals($this->mail_tracking, $this->callProtectedMethod('seeEmailCc', ['cc@domain.tld']));
157157
}
158158

159+
/**
160+
* @test
161+
* @group unit
162+
*/
163+
public function it_checks_email_content_type()
164+
{
165+
$message = $this->makeMessage();
166+
$message->setContentType('text/html');
167+
$this->mail_tracking->recordMail($message);
168+
169+
$this->assertEquals($this->mail_tracking, $this->callProtectedMethod('seeEmailContentTypeEquals', ['text/html']));
170+
}
171+
159172
/**
160173
* @test
161174
* @group unit
@@ -202,6 +215,25 @@ public function it_checks_email_from_address()
202215
$this->mail_tracking->recordMail($message);
203216

204217
$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]));
205237
}
206238

207239
/**
@@ -223,19 +255,19 @@ public function it_checks_email_reply_to_address()
223255
*/
224256
public function it_knows_how_many_emails_have_been_sent()
225257
{
226-
$this->assertEquals($this->mail_tracking, $this->callProtectedMethod('seeEmailsSent', [0]));
258+
$this->assertEquals($this->mail_tracking, $this->callProtectedMethod('seeEmailCountEquals', [0]));
227259

228260
$message = $this->makeMessage();
229261

230262
$this->mail_tracking->recordMail($message);
231263

232-
$this->assertEquals($this->mail_tracking, $this->callProtectedMethod('seeEmailsSent', [1]));
264+
$this->assertEquals($this->mail_tracking, $this->callProtectedMethod('seeEmailCountEquals', [1]));
233265

234266
$message = $this->makeMessage();
235267

236268
$this->mail_tracking->recordMail($message);
237269

238-
$this->assertEquals($this->mail_tracking, $this->callProtectedMethod('seeEmailsSent', [2]));
270+
$this->assertEquals($this->mail_tracking, $this->callProtectedMethod('seeEmailCountEquals', [2]));
239271
}
240272

241273
/**
@@ -292,7 +324,7 @@ public function it_checks_email_to_address()
292324
* @test
293325
* @group unit
294326
*/
295-
public function it_knows_if_email_has_not_been_sent_or_not()
327+
public function it_knows_if_email_has_been_sent_or_not()
296328
{
297329
$this->assertEquals($this->mail_tracking, $this->callProtectedMethod('seeEmailWasNotSent'));
298330

0 commit comments

Comments
 (0)