1 | <?php |
||
26 | trait MailTracking |
||
27 | { |
||
28 | // TODO: Add check for attachments (number of & name) |
||
29 | // TODO: Add check for BCC |
||
30 | // TODO: Add check for CC |
||
31 | // TODO: Add check for header |
||
32 | // TODO: Add check for message type |
||
33 | // TODO: Add check for Priority |
||
34 | // TODO: Add check for ReplyTo |
||
35 | // TODO: Allow checking specific message not just most recent one |
||
36 | |||
37 | /** |
||
38 | * Delivered emails. |
||
39 | * |
||
40 | * @var array |
||
41 | */ |
||
42 | protected $emails = []; |
||
43 | |||
44 | /** |
||
45 | * Register a listener for new emails. |
||
46 | * |
||
47 | * Called my PHPUnit before each test it run. It registers the MailRecorder "plugin" with Swift, so that we can |
||
48 | * get a copy of each email that is sent during that test. |
||
49 | * |
||
50 | * @before |
||
51 | */ |
||
52 | public function setUpMailTracking() |
||
57 | |||
58 | /** |
||
59 | * Retrieve the appropriate swift message. |
||
60 | * |
||
61 | * @param Swift_Message $message |
||
62 | * |
||
63 | * @return Swift_Message |
||
64 | */ |
||
65 | protected function getEmail(Swift_Message $message = null) |
||
71 | |||
72 | /** |
||
73 | * Retrieve the mostly recently sent swift message. |
||
74 | */ |
||
75 | protected function lastEmail() |
||
79 | |||
80 | /** |
||
81 | * Store a new swift message. |
||
82 | * |
||
83 | * Collection of emails that were received by the MailRecorder plugin during a test. |
||
84 | * |
||
85 | * @param Swift_Message $email |
||
86 | */ |
||
87 | public function recordMail(Swift_Message $email) |
||
91 | |||
92 | /** |
||
93 | * Assert that the last email's body contains the given text. |
||
94 | * |
||
95 | * @param string $excerpt |
||
96 | * @param Swift_Message $message |
||
97 | * |
||
98 | * @return PHPUnit_Framework_TestCase $this |
||
99 | */ |
||
100 | protected function seeEmailContains($excerpt, Swift_Message $message = null) |
||
107 | |||
108 | /** |
||
109 | * Assert that the last email's body equals the given text. |
||
110 | * |
||
111 | * @param string $body |
||
112 | * @param Swift_Message $message |
||
113 | * |
||
114 | * @return PHPUnit_Framework_TestCase $this |
||
115 | */ |
||
116 | protected function seeEmailEquals($body, Swift_Message $message = null) |
||
123 | |||
124 | /** |
||
125 | * Assert that the last email was delivered by the given address. |
||
126 | * |
||
127 | * @param string $sender |
||
128 | * @param Swift_Message $message |
||
129 | * |
||
130 | * @return PHPUnit_Framework_TestCase $this |
||
131 | */ |
||
132 | protected function seeEmailFrom($sender, Swift_Message $message = null) |
||
140 | |||
141 | /** |
||
142 | * Assert that the given number of emails were sent. |
||
143 | * |
||
144 | * @param integer $count |
||
145 | * |
||
146 | * @return PHPUnit_Framework_TestCase $this |
||
147 | */ |
||
148 | protected function seeEmailsSent($count) |
||
156 | |||
157 | /** |
||
158 | * Assert that the last email's subject matches the given string. |
||
159 | * |
||
160 | * @param string $subject |
||
161 | * @param Swift_Message $message |
||
162 | * |
||
163 | * @return PHPUnit_Framework_TestCase $this |
||
164 | */ |
||
165 | protected function seeEmailSubject($subject, Swift_Message $message = null) |
||
173 | |||
174 | /** |
||
175 | * Assert that the last email was sent to the given recipient. |
||
176 | * |
||
177 | * @param string $recipient |
||
178 | * @param Swift_Message $message |
||
179 | * |
||
180 | * @return PHPUnit_Framework_TestCase $this |
||
181 | */ |
||
182 | protected function seeEmailTo($recipient, Swift_Message $message = null) |
||
189 | |||
190 | /** |
||
191 | * Assert that no emails were sent. |
||
192 | * |
||
193 | * @return PHPUnit_Framework_TestCase $this |
||
194 | */ |
||
195 | protected function seeEmailWasNotSent() |
||
201 | |||
202 | /** |
||
203 | * Assert that at least one email was sent. |
||
204 | * |
||
205 | * @return PHPUnit_Framework_TestCase $this |
||
206 | */ |
||
207 | protected function seeEmailWasSent() |
||
213 | } |
||
214 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.