Skip to content

Commit 0d84e70

Browse files
committed
Correct a bug where strings containing special chars could not be find in emails when using the seeInEmail method.
1 parent 7917e78 commit 0d84e70

File tree

3 files changed

+137
-3
lines changed

3 files changed

+137
-3
lines changed

src/MailCatcher.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,11 @@ public function seeInEmail($expected, MailCollection $emails = null)
152152
}
153153

154154
$emails = $emails->filter(function(Mail $mail) use ($expected) {
155-
return false !== strstr(str_replace("=\r\n", '', $mail->source()), $expected);
155+
$content = $mail->subject()
156+
. ($mail->hasText() ? $mail->text() : '')
157+
. ($mail->hasHtml() ? $mail->html() : '');
158+
159+
return false !== strstr(str_replace("=\r\n", '', $content), $expected);
156160
});
157161

158162
$this->assertNotEmpty($emails->count(), 'Email contains');

tests/_support/_generated/FunctionalTesterActions.php

Lines changed: 122 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
<?php //[STAMP] c191ac0986f2902bab006307f7c9875b
1+
<?php //[STAMP] 42109e583aa5c4ff6b993f6e04e3de22
22
namespace _generated;
33

44
// This class was automatically generated by build task
55
// You should not change it manually as it will be overwritten on next build
66
// @codingStandardsIgnoreFile
77

88
use Helper\Functional;
9+
use Codeception\Module\MailCatcher;
910

1011
trait FunctionalTesterActions
1112
{
@@ -15,4 +16,124 @@ trait FunctionalTesterActions
1516
abstract protected function getScenario();
1617

1718

19+
/**
20+
* [!] Method is generated. Documentation taken from corresponding module.
21+
*
22+
* Remove all emails in MailCatcher.
23+
* @see \Codeception\Module\MailCatcher::removeEmails()
24+
*/
25+
public function removeEmails() {
26+
return $this->getScenario()->runStep(new \Codeception\Step\Action('removeEmails', func_get_args()));
27+
}
28+
29+
30+
/**
31+
* [!] Method is generated. Documentation taken from corresponding module.
32+
*
33+
* Assert that there is at least one email.
34+
* @param MailCollection $emails
35+
* @see \Codeception\Module\MailCatcher::hasEmails()
36+
*/
37+
public function hasEmails($emails = null) {
38+
return $this->getScenario()->runStep(new \Codeception\Step\Action('hasEmails', func_get_args()));
39+
}
40+
41+
42+
/**
43+
* [!] Method is generated. Documentation taken from corresponding module.
44+
*
45+
* Assert the number of emails sent.
46+
*
47+
* @param int $count
48+
* @param MailCollection $emails
49+
* Conditional Assertion: Test won't be stopped on fail
50+
* @see \Codeception\Module\MailCatcher::seeNumberEmails()
51+
*/
52+
public function canSeeNumberEmails($count, $emails = null) {
53+
return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeNumberEmails', func_get_args()));
54+
}
55+
/**
56+
* [!] Method is generated. Documentation taken from corresponding module.
57+
*
58+
* Assert the number of emails sent.
59+
*
60+
* @param int $count
61+
* @param MailCollection $emails
62+
* @see \Codeception\Module\MailCatcher::seeNumberEmails()
63+
*/
64+
public function seeNumberEmails($count, $emails = null) {
65+
return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeNumberEmails', func_get_args()));
66+
}
67+
68+
69+
/**
70+
* [!] Method is generated. Documentation taken from corresponding module.
71+
*
72+
* Assert that at least an email contains some text.
73+
*
74+
* @param string $expected
75+
* @param MailCollection $emails
76+
* Conditional Assertion: Test won't be stopped on fail
77+
* @see \Codeception\Module\MailCatcher::seeInEmail()
78+
*/
79+
public function canSeeInEmail($expected, $emails = null) {
80+
return $this->getScenario()->runStep(new \Codeception\Step\ConditionalAssertion('seeInEmail', func_get_args()));
81+
}
82+
/**
83+
* [!] Method is generated. Documentation taken from corresponding module.
84+
*
85+
* Assert that at least an email contains some text.
86+
*
87+
* @param string $expected
88+
* @param MailCollection $emails
89+
* @see \Codeception\Module\MailCatcher::seeInEmail()
90+
*/
91+
public function seeInEmail($expected, $emails = null) {
92+
return $this->getScenario()->runStep(new \Codeception\Step\Assertion('seeInEmail', func_get_args()));
93+
}
94+
95+
96+
/**
97+
* [!] Method is generated. Documentation taken from corresponding module.
98+
*
99+
* Get all emails with the given subject.
100+
*
101+
* @param string $subject
102+
* @param bool $strict
103+
* @return MailCollection
104+
* @see \Codeception\Module\MailCatcher::getEmailsBySubject()
105+
*/
106+
public function getEmailsBySubject($subject, $strict = null) {
107+
return $this->getScenario()->runStep(new \Codeception\Step\Action('getEmailsBySubject', func_get_args()));
108+
}
109+
110+
111+
/**
112+
* [!] Method is generated. Documentation taken from corresponding module.
113+
*
114+
* Get all emails with the given sender.
115+
*
116+
* @param string $sender
117+
* @param bool $strict
118+
* @return MailCollection
119+
* @see \Codeception\Module\MailCatcher::getEmailsBySender()
120+
*/
121+
public function getEmailsBySender($sender, $strict = null) {
122+
return $this->getScenario()->runStep(new \Codeception\Step\Action('getEmailsBySender', func_get_args()));
123+
}
124+
125+
126+
/**
127+
* [!] Method is generated. Documentation taken from corresponding module.
128+
*
129+
* Get all emails with the given recipients.
130+
*
131+
* @param array $recipients
132+
* @param bool $strict
133+
* @return MailCollection
134+
* @see \Codeception\Module\MailCatcher::getEmailsByRecipients()
135+
*/
136+
public function getEmailsByRecipients($recipients, $strict = null) {
137+
return $this->getScenario()->runStep(new \Codeception\Step\Action('getEmailsByRecipients', func_get_args()));
138+
}
18139
}

tests/functional/MailCatcherTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,13 @@ public function it_retrieve_the_emails_by_their_recipients_strictly()
107107

108108
$this->assertEquals(1, $this->getEmailsByRecipients(['user1@example.com', 'user2@example.com'], true)->count());
109109
}
110-
}
110+
111+
/** @test */
112+
public function it_manage_special_chars()
113+
{
114+
mail('user3@example.com', 'éàù', 'ïËù');
115+
116+
$this->assertEquals(1, $this->getEmailsBySubject('éàù')->count());
117+
$this->assertEquals(1, $this->seeInEmail('ïËù')->count());
118+
}
119+
}

0 commit comments

Comments
 (0)