Completed
Push — master ( 85dea1...7e6628 )
by Jacob
02:09
created
src/Archangel.php 1 patch
Indentation   +435 added lines, -436 removed lines patch added patch discarded remove patch
@@ -16,440 +16,439 @@
 block discarded – undo
16 16
 class Archangel implements LoggerAwareInterface
17 17
 {
18 18
 
19
-    /** @var string $subject */
20
-    protected $subject;
21
-
22
-    /** @var array $toAddresses */
23
-    protected $toAddresses = array();
24
-
25
-    /** @var array $headers */
26
-    protected $headers = array();
27
-
28
-    /** @var string $plainMessage */
29
-    protected $plainMessage;
30
-
31
-    /** @var string $htmlMessage */
32
-    protected $htmlMessage;
33
-
34
-    /** @var array $attachments */
35
-    protected $attachments = array();
36
-
37
-    /** @var string $boundaryMixed */
38
-    protected $boundaryMixed;
39
-
40
-    /** @var string $boundaryAlternative */
41
-    protected $boundaryAlternative;
42
-
43
-    /** @var LoggerInterface */
44
-    protected $logger;
45
-
46
-    /** @var string LINE_BREAK */
47
-    const LINE_BREAK = "\r\n";
48
-
49
-    /**
50
-     * @param string $mailer
51
-     */
52
-    public function __construct($mailer = null)
53
-    {
54
-        if (is_null($mailer)) {
55
-            $mailer = sprintf('PHP/%s', phpversion());
56
-        }
57
-        $this->headers['X-Mailer'] = $mailer;
58
-
59
-        $this->logger = new NullLogger();
60
-        $this->boundaryMixed = sprintf('PHP-mixed-%s', uniqid());
61
-        $this->boundaryAlternative = sprintf('PHP-alternative-%s', uniqid());
62
-    }
63
-
64
-    /**
65
-     * @param LoggerInterface $logger
66
-     *
67
-     * @return $this;
68
-     */
69
-    public function setLogger(LoggerInterface $logger)
70
-    {
71
-        $this->logger = $logger;
72
-
73
-        return $this;
74
-    }
75
-
76
-    /**
77
-     * Setter method for adding recipients
78
-     *
79
-     * @param string $address email address for the recipient
80
-     * @param string $title   name of the recipient (optional)
81
-
82
-     * @return object instantiated $this
83
-     */
84
-    public function addTo($address, $title = '')
85
-    {
86
-        array_push(
87
-            $this->toAddresses,
88
-            $this->formatEmailAddress($address, $title)
89
-        );
90
-
91
-        return $this;
92
-    }
93
-
94
-    /**
95
-     * Setter method for adding cc recipients
96
-     *
97
-     * @param string $address email address for the cc recipient
98
-     * @param string $title   name of the cc recipient (optional)
99
-     *
100
-     * @return object instantiated $this
101
-     */
102
-    public function addCC($address, $title = '')
103
-    {
104
-        if (!isset($this->headers['CC'])) {
105
-            $this->headers['CC'] = array();
106
-        }
107
-
108
-        array_push(
109
-            $this->headers['CC'],
110
-            $this->formatEmailAddress($address, $title)
111
-        );
112
-
113
-        return $this;
114
-    }
115
-
116
-    /**
117
-     * Setter method for adding bcc recipients
118
-     *
119
-     * @param string $address email address for the bcc recipient
120
-     * @param string $title   name of the bcc recipient (optional)
121
-     *
122
-     * @return object instantiated $this
123
-     */
124
-    public function addBCC($address, $title = '')
125
-    {
126
-        if (!isset($this->headers['BCC'])) {
127
-            $this->headers['BCC'] = array();
128
-        }
129
-
130
-        array_push(
131
-            $this->headers['BCC'],
132
-            $this->formatEmailAddress($address, $title)
133
-        );
134
-
135
-        return $this;
136
-    }
137
-
138
-    /**
139
-     * Setter method for setting the single 'from' field
140
-     *
141
-     * @param string $address email address for the sender
142
-     * @param string $title   name of the sender (optional)
143
-     *
144
-     * @return object instantiated $this
145
-     */
146
-    public function setFrom($address, $title = '')
147
-    {
148
-        $this->headers['From'] = $this->formatEmailAddress($address, $title);
149
-
150
-        return $this;
151
-    }
152
-
153
-    /**
154
-     * Setter method for setting the single 'reply-to' field
155
-     *
156
-     * @param string $address email address for the reply-to
157
-     * @param string $title   name of the reply-to (optional)
158
-     *
159
-     * @return object instantiated $this
160
-     */
161
-    public function setReplyTo($address, $title = '')
162
-    {
163
-        $this->headers['Reply-To'] = $this->formatEmailAddress($address, $title);
164
-
165
-        return $this;
166
-    }
167
-
168
-    /**
169
-     * @param string $address
170
-     * @param string $title
171
-     *
172
-     * @return string
173
-     */
174
-    protected function formatEmailAddress($address, $title)
175
-    {
176
-        if (!empty($title)) {
177
-            $address = sprintf('"%s" <%s>', $title, $address);
178
-        }
179
-        return $address;
180
-    }
181
-
182
-    /**
183
-     * Setter method for setting a subject
184
-     *
185
-     * @param string $subject subject for the email
186
-     *
187
-     * @return object instantiated $this
188
-     */
189
-    public function setSubject($subject)
190
-    {
191
-        $this->subject = $subject;
192
-
193
-        return $this;
194
-    }
195
-
196
-    /**
197
-     * Setter method for the plain text message
198
-     *
199
-     * @param string $message the plain-text message
200
-     *
201
-     * @return object instantiated $this
202
-     */
203
-    public function setPlainMessage($message)
204
-    {
205
-        $this->plainMessage = $message;
206
-
207
-        return $this;
208
-    }
209
-
210
-    /**
211
-     * Setter method for the html message
212
-     *
213
-     * @param string $message the html message
214
-     *
215
-     * @return object instantiated $this
216
-     */
217
-    public function setHTMLMessage($message)
218
-    {
219
-        $this->htmlMessage = $message;
220
-
221
-        return $this;
222
-    }
223
-
224
-    /**
225
-     * Setter method for adding attachments
226
-     *
227
-     * @param string $path  the full path of the attachment
228
-     * @param string $type  mime type of the file
229
-     * @param string $title the title of the attachment (optional)
230
-     *
231
-     * @return object instantiated $this
232
-     */
233
-    public function addAttachment($path, $type, $title = '')
234
-    {
235
-        array_push($this->attachments, array(
236
-          'path' => $path,
237
-          'type' => $type,
238
-          'title' => $title,
239
-        ));
240
-
241
-        return $this;
242
-    }
243
-
244
-    /**
245
-     * The executing step, the actual sending of the email
246
-     * First checks to make sure the minimum fields are set (returns false if they are not)
247
-     * Second it attempts to send the mail with php's mail() (returns false if it fails)
248
-     *
249
-     * return boolean whether or not the email was valid & sent
250
-     */
251
-    public function send()
252
-    {
253
-        if (!$this->checkRequiredFields()) {
254
-            return false;
255
-        }
256
-
257
-        $recipients = $this->buildTo();
258
-        $subject = $this->subject;
259
-        $message = (empty($this->attachments)) ? $this->buildMessage() : $this->buildHtmlMessage();
260
-        $headers = $this->buildHeaders();
261
-
262
-        return mail($recipients, $subject, $message, $headers);
263
-    }
264
-
265
-    /**
266
-     * Call to check the minimum required fields
267
-     *
268
-     * @return boolean whether or not the email meets the minimum required fields
269
-     */
270
-    protected function checkRequiredFields()
271
-    {
272
-        if (empty($this->toAddresses)) {
273
-            return false;
274
-        }
275
-        if (empty($this->subject)) {
276
-            return false;
277
-        }
278
-
279
-        if (empty($this->plainMessage) && empty($this->htmlMessage) && empty($this->attachments)) {
280
-            return false;
281
-        }
282
-
283
-        return true;
284
-    }
285
-
286
-    /**
287
-     * Build the recipients from 'to'
288
-     *
289
-     * @return string comma-separated lit of recipients
290
-     */
291
-    protected function buildTo()
292
-    {
293
-        return implode(', ', $this->toAddresses);
294
-    }
295
-
296
-    /**
297
-     * Returns a simple email message without attachments
298
-     *
299
-     * @return string email message
300
-     */
301
-    protected function buildMessage()
302
-    {
303
-        if (empty($this->plainMessage) && empty($this->htmlMessage)) {
304
-            return '';
305
-        }
306
-        if (!empty($this->plainMessage) && empty($this->htmlMessage)) {
307
-            return $this->plainMessage;
308
-        }
309
-        if (empty($this->plainMessage) && !empty($this->htmlMessage)) {
310
-            return $this->htmlMessage;
311
-        }
312
-
313
-        $message = array();
314
-        array_push($message, "--{$this->boundaryAlternative}");
315
-        $message += $this->buildPlainMessageHeaders();
316
-        array_push($message, $this->plainMessage);
317
-        array_push($message, "--{$this->boundaryAlternative}");
318
-        $message += $this->buildHtmlMessageHeaders();
319
-        array_push($message, $this->htmlMessage);
320
-        array_push($message, "--{$this->boundaryAlternative}--");
321
-
322
-        return implode(self::LINE_BREAK, $message);
323
-    }
324
-
325
-    /**
326
-     * Build multi-part message with attachments
327
-     *
328
-     * @return string email message
329
-     */
330
-    protected function buildMessageWithAttachments()
331
-    {
332
-        $message = array();
333
-
334
-        if (!empty($this->plainMessage) || !empty($this->htmlMessage)) {
335
-            array_push($message, "--{$this->boundaryMixed}");
336
-        }
337
-
338
-        if (!empty($this->plainMessage) && !empty($this->htmlMessage)) {
339
-            array_push($message, "Content-Type: multipart/alternative; boundary={$this->boundaryAlternative}");
340
-            array_push($message, '');
341
-            array_push($message, "--{$this->boundaryAlternative}");
342
-            $message += $this->buildPlainMessageHeaders();
343
-            array_push($message, $this->plainMessage);
344
-            array_push($message, "--{$this->boundaryAlternative}");
345
-            $message += $this->buildHtmlMessageHeaders();
346
-            array_push($message, $this->htmlMessage);
347
-            array_push($message, "--{$this->boundaryAlternative}--");
348
-            array_push($message, '');
349
-        } elseif (!empty($this->plainMessage)) {
350
-            $message += $this->buildPlainMessageHeaders();
351
-            array_push($message, $this->plainMessage);
352
-        } elseif (!empty($this->htmlMessage)) {
353
-            $message += $this->buildHtmlMessageHeaders();
354
-            array_push($message, $this->htmlMessage);
355
-        }
356
-        foreach ($this->attachments as $attachment) {
357
-            array_push($message, "--{$this->boundaryMixed}");
358
-            array_push($message, "Content-Type: {$attachment['type']}; name=\"{$attachment['title']}\"");
359
-            array_push($message, 'Content-Transfer-Encoding: base64');
360
-            array_push($message, 'Content-Disposition: attachment');
361
-            array_push($message, '');
362
-            array_push($message, $this->buildAttachmentContent($attachment['path']));
363
-        }
364
-        array_push($message, "--{$this->boundaryMixed}--");
365
-
366
-        return implode(self::LINE_BREAK, $message);
367
-    }
368
-
369
-
370
-    /**
371
-     * Shared holder for the plain message header
372
-     *
373
-     * @return array
374
-     */
375
-    protected function buildPlainMessageHeader()
376
-    {
377
-        return array(
378
-            'Content-Type: text/plain; charset="iso-8859"',
379
-            'Content-Transfer-Encoding: 7bit',
380
-            '',
381
-        );
382
-    }
383
-
384
-    /**
385
-     * Shared holder for the html message header
386
-     *
387
-     * @return array
388
-     */
389
-    protected function buildHtmlMessageHeader()
390
-    {
391
-        return array(
392
-            'Content-Type: text/html; charset="iso-8859-1"',
393
-            'Content-Transfer-Encoding: 7bit',
394
-            '',
395
-        );
396
-    }
397
-
398
-    /**
399
-     * Builder for the additional headers needed for multipart emails
400
-     *
401
-     * @return string headers needed for multipart
402
-     */
403
-    protected function buildHeaders()
404
-    {
405
-        $headers = array();
406
-        foreach ($this->headers as $key => $value) {
407
-            if ($key == 'CC' || $key == 'BCC') {
408
-                $value = implode(', ', $value);
409
-            }
410
-            array_push($headers, sprintf('%s: %s', $key, $value));
411
-        }
412
-
413
-        if (!empty($this->attachments)) {
414
-            array_push(
415
-                $headers,
416
-                "Content-Type: multipart/mixed; boundary=\"{$this->boundaryMixed}\""
417
-            );
418
-        } elseif (!empty($this->plainMessage) && !empty($this->htmlMessage)) {
419
-            array_push(
420
-                $headers,
421
-                "Content-Type: multipart/alternative; boundary=\"{$this->boundaryAlternative}\""
422
-            );
423
-        } elseif (!empty($this->htmlMessage)) {
424
-            array_push(
425
-                $headers,
426
-                'Content-type: text/html; charset="iso-8859-1"'
427
-            );
428
-        }
429
-
430
-        return implode(self::LINE_BREAK, $headers);
431
-    }
432
-
433
-    /**
434
-     * File reader for attachments
435
-     *
436
-     * @param string $path filepath of the attachment
437
-     *
438
-     * @return string binary representation of file, base64'd
439
-     */
440
-    protected function buildAttachmentContent($path)
441
-    {
442
-        if (!file_exists($path)) {
443
-            $this->logger->error("Could not find file {$path} for attaching to Archangel mail.");
444
-            return '';
445
-        }
446
-
447
-        $handle = fopen($path, 'r');
448
-        $contents = fread($handle, filesize($path));
449
-        fclose($handle);
450
-
451
-        $contents = base64_encode($contents);
452
-        $contents = chunk_split($contents);
453
-        return $contents;
454
-    }
19
+	/** @var string $subject */
20
+	protected $subject;
21
+
22
+	/** @var array $toAddresses */
23
+	protected $toAddresses = array();
24
+
25
+	/** @var array $headers */
26
+	protected $headers = array();
27
+
28
+	/** @var string $plainMessage */
29
+	protected $plainMessage;
30
+
31
+	/** @var string $htmlMessage */
32
+	protected $htmlMessage;
33
+
34
+	/** @var array $attachments */
35
+	protected $attachments = array();
36
+
37
+	/** @var string $boundaryMixed */
38
+	protected $boundaryMixed;
39
+
40
+	/** @var string $boundaryAlternative */
41
+	protected $boundaryAlternative;
42
+
43
+	/** @var LoggerInterface */
44
+	protected $logger;
45
+
46
+	/** @var string LINE_BREAK */
47
+	const LINE_BREAK = "\r\n";
48
+
49
+	/**
50
+	 * @param string $mailer
51
+	 */
52
+	public function __construct($mailer = null)
53
+	{
54
+		if (is_null($mailer)) {
55
+			$mailer = sprintf('PHP/%s', phpversion());
56
+		}
57
+		$this->headers['X-Mailer'] = $mailer;
58
+
59
+		$this->logger = new NullLogger();
60
+		$this->boundaryMixed = sprintf('PHP-mixed-%s', uniqid());
61
+		$this->boundaryAlternative = sprintf('PHP-alternative-%s', uniqid());
62
+	}
63
+
64
+	/**
65
+	 * @param LoggerInterface $logger
66
+	 *
67
+	 * @return $this;
68
+	 */
69
+	public function setLogger(LoggerInterface $logger)
70
+	{
71
+		$this->logger = $logger;
72
+
73
+		return $this;
74
+	}
75
+
76
+	/**
77
+	 * Setter method for adding recipients
78
+	 *
79
+	 * @param string $address email address for the recipient
80
+	 * @param string $title   name of the recipient (optional)
81
+	 * @return object instantiated $this
82
+	 */
83
+	public function addTo($address, $title = '')
84
+	{
85
+		array_push(
86
+			$this->toAddresses,
87
+			$this->formatEmailAddress($address, $title)
88
+		);
89
+
90
+		return $this;
91
+	}
92
+
93
+	/**
94
+	 * Setter method for adding cc recipients
95
+	 *
96
+	 * @param string $address email address for the cc recipient
97
+	 * @param string $title   name of the cc recipient (optional)
98
+	 *
99
+	 * @return object instantiated $this
100
+	 */
101
+	public function addCC($address, $title = '')
102
+	{
103
+		if (!isset($this->headers['CC'])) {
104
+			$this->headers['CC'] = array();
105
+		}
106
+
107
+		array_push(
108
+			$this->headers['CC'],
109
+			$this->formatEmailAddress($address, $title)
110
+		);
111
+
112
+		return $this;
113
+	}
114
+
115
+	/**
116
+	 * Setter method for adding bcc recipients
117
+	 *
118
+	 * @param string $address email address for the bcc recipient
119
+	 * @param string $title   name of the bcc recipient (optional)
120
+	 *
121
+	 * @return object instantiated $this
122
+	 */
123
+	public function addBCC($address, $title = '')
124
+	{
125
+		if (!isset($this->headers['BCC'])) {
126
+			$this->headers['BCC'] = array();
127
+		}
128
+
129
+		array_push(
130
+			$this->headers['BCC'],
131
+			$this->formatEmailAddress($address, $title)
132
+		);
133
+
134
+		return $this;
135
+	}
136
+
137
+	/**
138
+	 * Setter method for setting the single 'from' field
139
+	 *
140
+	 * @param string $address email address for the sender
141
+	 * @param string $title   name of the sender (optional)
142
+	 *
143
+	 * @return object instantiated $this
144
+	 */
145
+	public function setFrom($address, $title = '')
146
+	{
147
+		$this->headers['From'] = $this->formatEmailAddress($address, $title);
148
+
149
+		return $this;
150
+	}
151
+
152
+	/**
153
+	 * Setter method for setting the single 'reply-to' field
154
+	 *
155
+	 * @param string $address email address for the reply-to
156
+	 * @param string $title   name of the reply-to (optional)
157
+	 *
158
+	 * @return object instantiated $this
159
+	 */
160
+	public function setReplyTo($address, $title = '')
161
+	{
162
+		$this->headers['Reply-To'] = $this->formatEmailAddress($address, $title);
163
+
164
+		return $this;
165
+	}
166
+
167
+	/**
168
+	 * @param string $address
169
+	 * @param string $title
170
+	 *
171
+	 * @return string
172
+	 */
173
+	protected function formatEmailAddress($address, $title)
174
+	{
175
+		if (!empty($title)) {
176
+			$address = sprintf('"%s" <%s>', $title, $address);
177
+		}
178
+		return $address;
179
+	}
180
+
181
+	/**
182
+	 * Setter method for setting a subject
183
+	 *
184
+	 * @param string $subject subject for the email
185
+	 *
186
+	 * @return object instantiated $this
187
+	 */
188
+	public function setSubject($subject)
189
+	{
190
+		$this->subject = $subject;
191
+
192
+		return $this;
193
+	}
194
+
195
+	/**
196
+	 * Setter method for the plain text message
197
+	 *
198
+	 * @param string $message the plain-text message
199
+	 *
200
+	 * @return object instantiated $this
201
+	 */
202
+	public function setPlainMessage($message)
203
+	{
204
+		$this->plainMessage = $message;
205
+
206
+		return $this;
207
+	}
208
+
209
+	/**
210
+	 * Setter method for the html message
211
+	 *
212
+	 * @param string $message the html message
213
+	 *
214
+	 * @return object instantiated $this
215
+	 */
216
+	public function setHTMLMessage($message)
217
+	{
218
+		$this->htmlMessage = $message;
219
+
220
+		return $this;
221
+	}
222
+
223
+	/**
224
+	 * Setter method for adding attachments
225
+	 *
226
+	 * @param string $path  the full path of the attachment
227
+	 * @param string $type  mime type of the file
228
+	 * @param string $title the title of the attachment (optional)
229
+	 *
230
+	 * @return object instantiated $this
231
+	 */
232
+	public function addAttachment($path, $type, $title = '')
233
+	{
234
+		array_push($this->attachments, array(
235
+		  'path' => $path,
236
+		  'type' => $type,
237
+		  'title' => $title,
238
+		));
239
+
240
+		return $this;
241
+	}
242
+
243
+	/**
244
+	 * The executing step, the actual sending of the email
245
+	 * First checks to make sure the minimum fields are set (returns false if they are not)
246
+	 * Second it attempts to send the mail with php's mail() (returns false if it fails)
247
+	 *
248
+	 * return boolean whether or not the email was valid & sent
249
+	 */
250
+	public function send()
251
+	{
252
+		if (!$this->checkRequiredFields()) {
253
+			return false;
254
+		}
255
+
256
+		$recipients = $this->buildTo();
257
+		$subject = $this->subject;
258
+		$message = (empty($this->attachments)) ? $this->buildMessage() : $this->buildHtmlMessage();
259
+		$headers = $this->buildHeaders();
260
+
261
+		return mail($recipients, $subject, $message, $headers);
262
+	}
263
+
264
+	/**
265
+	 * Call to check the minimum required fields
266
+	 *
267
+	 * @return boolean whether or not the email meets the minimum required fields
268
+	 */
269
+	protected function checkRequiredFields()
270
+	{
271
+		if (empty($this->toAddresses)) {
272
+			return false;
273
+		}
274
+		if (empty($this->subject)) {
275
+			return false;
276
+		}
277
+
278
+		if (empty($this->plainMessage) && empty($this->htmlMessage) && empty($this->attachments)) {
279
+			return false;
280
+		}
281
+
282
+		return true;
283
+	}
284
+
285
+	/**
286
+	 * Build the recipients from 'to'
287
+	 *
288
+	 * @return string comma-separated lit of recipients
289
+	 */
290
+	protected function buildTo()
291
+	{
292
+		return implode(', ', $this->toAddresses);
293
+	}
294
+
295
+	/**
296
+	 * Returns a simple email message without attachments
297
+	 *
298
+	 * @return string email message
299
+	 */
300
+	protected function buildMessage()
301
+	{
302
+		if (empty($this->plainMessage) && empty($this->htmlMessage)) {
303
+			return '';
304
+		}
305
+		if (!empty($this->plainMessage) && empty($this->htmlMessage)) {
306
+			return $this->plainMessage;
307
+		}
308
+		if (empty($this->plainMessage) && !empty($this->htmlMessage)) {
309
+			return $this->htmlMessage;
310
+		}
311
+
312
+		$message = array();
313
+		array_push($message, "--{$this->boundaryAlternative}");
314
+		$message += $this->buildPlainMessageHeaders();
315
+		array_push($message, $this->plainMessage);
316
+		array_push($message, "--{$this->boundaryAlternative}");
317
+		$message += $this->buildHtmlMessageHeaders();
318
+		array_push($message, $this->htmlMessage);
319
+		array_push($message, "--{$this->boundaryAlternative}--");
320
+
321
+		return implode(self::LINE_BREAK, $message);
322
+	}
323
+
324
+	/**
325
+	 * Build multi-part message with attachments
326
+	 *
327
+	 * @return string email message
328
+	 */
329
+	protected function buildMessageWithAttachments()
330
+	{
331
+		$message = array();
332
+
333
+		if (!empty($this->plainMessage) || !empty($this->htmlMessage)) {
334
+			array_push($message, "--{$this->boundaryMixed}");
335
+		}
336
+
337
+		if (!empty($this->plainMessage) && !empty($this->htmlMessage)) {
338
+			array_push($message, "Content-Type: multipart/alternative; boundary={$this->boundaryAlternative}");
339
+			array_push($message, '');
340
+			array_push($message, "--{$this->boundaryAlternative}");
341
+			$message += $this->buildPlainMessageHeaders();
342
+			array_push($message, $this->plainMessage);
343
+			array_push($message, "--{$this->boundaryAlternative}");
344
+			$message += $this->buildHtmlMessageHeaders();
345
+			array_push($message, $this->htmlMessage);
346
+			array_push($message, "--{$this->boundaryAlternative}--");
347
+			array_push($message, '');
348
+		} elseif (!empty($this->plainMessage)) {
349
+			$message += $this->buildPlainMessageHeaders();
350
+			array_push($message, $this->plainMessage);
351
+		} elseif (!empty($this->htmlMessage)) {
352
+			$message += $this->buildHtmlMessageHeaders();
353
+			array_push($message, $this->htmlMessage);
354
+		}
355
+		foreach ($this->attachments as $attachment) {
356
+			array_push($message, "--{$this->boundaryMixed}");
357
+			array_push($message, "Content-Type: {$attachment['type']}; name=\"{$attachment['title']}\"");
358
+			array_push($message, 'Content-Transfer-Encoding: base64');
359
+			array_push($message, 'Content-Disposition: attachment');
360
+			array_push($message, '');
361
+			array_push($message, $this->buildAttachmentContent($attachment['path']));
362
+		}
363
+		array_push($message, "--{$this->boundaryMixed}--");
364
+
365
+		return implode(self::LINE_BREAK, $message);
366
+	}
367
+
368
+
369
+	/**
370
+	 * Shared holder for the plain message header
371
+	 *
372
+	 * @return array
373
+	 */
374
+	protected function buildPlainMessageHeader()
375
+	{
376
+		return array(
377
+			'Content-Type: text/plain; charset="iso-8859"',
378
+			'Content-Transfer-Encoding: 7bit',
379
+			'',
380
+		);
381
+	}
382
+
383
+	/**
384
+	 * Shared holder for the html message header
385
+	 *
386
+	 * @return array
387
+	 */
388
+	protected function buildHtmlMessageHeader()
389
+	{
390
+		return array(
391
+			'Content-Type: text/html; charset="iso-8859-1"',
392
+			'Content-Transfer-Encoding: 7bit',
393
+			'',
394
+		);
395
+	}
396
+
397
+	/**
398
+	 * Builder for the additional headers needed for multipart emails
399
+	 *
400
+	 * @return string headers needed for multipart
401
+	 */
402
+	protected function buildHeaders()
403
+	{
404
+		$headers = array();
405
+		foreach ($this->headers as $key => $value) {
406
+			if ($key == 'CC' || $key == 'BCC') {
407
+				$value = implode(', ', $value);
408
+			}
409
+			array_push($headers, sprintf('%s: %s', $key, $value));
410
+		}
411
+
412
+		if (!empty($this->attachments)) {
413
+			array_push(
414
+				$headers,
415
+				"Content-Type: multipart/mixed; boundary=\"{$this->boundaryMixed}\""
416
+			);
417
+		} elseif (!empty($this->plainMessage) && !empty($this->htmlMessage)) {
418
+			array_push(
419
+				$headers,
420
+				"Content-Type: multipart/alternative; boundary=\"{$this->boundaryAlternative}\""
421
+			);
422
+		} elseif (!empty($this->htmlMessage)) {
423
+			array_push(
424
+				$headers,
425
+				'Content-type: text/html; charset="iso-8859-1"'
426
+			);
427
+		}
428
+
429
+		return implode(self::LINE_BREAK, $headers);
430
+	}
431
+
432
+	/**
433
+	 * File reader for attachments
434
+	 *
435
+	 * @param string $path filepath of the attachment
436
+	 *
437
+	 * @return string binary representation of file, base64'd
438
+	 */
439
+	protected function buildAttachmentContent($path)
440
+	{
441
+		if (!file_exists($path)) {
442
+			$this->logger->error("Could not find file {$path} for attaching to Archangel mail.");
443
+			return '';
444
+		}
445
+
446
+		$handle = fopen($path, 'r');
447
+		$contents = fread($handle, filesize($path));
448
+		fclose($handle);
449
+
450
+		$contents = base64_encode($contents);
451
+		$contents = chunk_split($contents);
452
+		return $contents;
453
+	}
455 454
 }
Please login to merge, or discard this patch.
tests/ArchangelTest.php 1 patch
Indentation   +673 added lines, -673 removed lines patch added patch discarded remove patch
@@ -10,678 +10,678 @@
 block discarded – undo
10 10
 class ArchangelTest extends PHPUnit_Framework_TestCase
11 11
 {
12 12
 
13
-    public function testIsInstanceOfArchangel()
14
-    {
15
-        $archangel = new Archangel();
16
-
17
-        $this->assertInstanceOf('Jacobemerick\Archangel\Archangel', $archangel);
18
-    }
19
-
20
-    public function testIsLoggerAwareInterface()
21
-    {
22
-        $archangel = new Archangel();
23
-
24
-        $this->assertInstanceOf('Psr\Log\LoggerAwareInterface', $archangel);
25
-    }
26
-
27
-    public function testConstructSetsDefaultMailer()
28
-    {
29
-        $archangel = new Archangel();
30
-        $mailer = sprintf('PHP/%s', phpversion());
31
-        $headers = array('X-Mailer' => $mailer);
32
-
33
-        $this->assertAttributeEquals($headers, 'headers', $archangel);
34
-    }
35
-
36
-    public function testConstructOverridesMailer()
37
-    {
38
-        $archangel = new Archangel('AwesomeMailer');
39
-        $headers = array('X-Mailer' => 'AwesomeMailer');
40
-
41
-        $this->assertAttributeEquals($headers, 'headers', $archangel);
42
-    }
43
-
44
-    public function testConstructSetsNullLogger()
45
-    {
46
-        $archangel = new Archangel();
47
-
48
-        $this->assertAttributeInstanceOf('Psr\Log\NullLogger', 'logger', $archangel);
49
-    }
50
-
51
-    public function testConstructSetsBoundaries()
52
-    {
53
-        $archangel = new Archangel();
54
-        $expectedBoundaryMixed = sprintf('PHP-mixed-%s', uniqid());
55
-        $expectedBoundaryAlternative = sprintf('PHP-alternative-%s', uniqid());
56
-
57
-        $this->assertAttributeEquals($expectedBoundaryMixed, 'boundaryMixed', $archangel);
58
-        $this->assertAttributeEquals($expectedBoundaryAlternative, 'boundaryAlternative', $archangel);
59
-    }
60
-
61
-    public function testSetLogger()
62
-    {
63
-        $logger = $this->getMock('Psr\Log\LoggerInterface');
64
-        $archangel = new Archangel();
65
-        $archangel->setLogger($logger);
66
-
67
-        $this->assertAttributeSame($logger, 'logger', $archangel);
68
-    }
69
-
70
-    public function testAddTo()
71
-    {
72
-        $archangel = new Archangel();
73
-        $archangel->addTo('[email protected]');
74
-
75
-        $this->assertAttributeContains('[email protected]', 'toAddresses', $archangel);
76
-    }
77
-
78
-    public function testAddToMultiple()
79
-    {
80
-        $archangel = new Archangel();
81
-        $archangel->addTo('[email protected]');
82
-        $archangel->addTo('[email protected]');
83
-
84
-        $this->assertAttributeContains('[email protected]', 'toAddresses', $archangel);
85
-        $this->assertAttributeContains('[email protected]', 'toAddresses', $archangel);
86
-    }
87
-
88
-    public function testAddToWithTitle()
89
-    {
90
-        $archangel = new Archangel();
91
-        $archangel->addTo('[email protected]', 'Mr. Test Alot');
92
-
93
-        $this->assertAttributeContains('"Mr. Test Alot" <[email protected]>', 'toAddresses', $archangel);
94
-    }
95
-
96
-    public function testAddCC()
97
-    {
98
-        $archangel = new Archangel();
99
-        $archangel->addCC('[email protected]');
100
-        $headersProperty = $this->getProtectedProperty('headers');
101
-        $headers = $headersProperty->getValue($archangel);
102
-
103
-        $this->assertArraySubset(
104
-            array('CC' => array('[email protected]')),
105
-            $headers
106
-        );
107
-    }
108
-
109
-    public function testAddCCMultiple()
110
-    {
111
-        $archangel = new Archangel();
112
-        $archangel->addCC('[email protected]');
113
-        $archangel->addCC('[email protected]');
114
-        $headersProperty = $this->getProtectedProperty('headers');
115
-        $headers = $headersProperty->getValue($archangel);
116
-
117
-        $this->assertArraySubset(
118
-            array('CC' => array('[email protected]', '[email protected]')),
119
-            $headers
120
-        );
121
-    }
122
-
123
-    public function testAddCCWithTitle()
124
-    {
125
-        $archangel = new Archangel();
126
-        $archangel->addCC('[email protected]', 'Mr. Test Alot');
127
-        $headersProperty = $this->getProtectedProperty('headers');
128
-        $headers = $headersProperty->getValue($archangel);
129
-
130
-        $this->assertArraySubset(
131
-            array('CC' => array('"Mr. Test Alot" <[email protected]>')),
132
-            $headers
133
-        );
134
-    }
135
-
136
-    public function testAddBCC()
137
-    {
138
-        $archangel = new Archangel();
139
-        $archangel->addBCC('[email protected]');
140
-        $headersProperty = $this->getProtectedProperty('headers');
141
-        $headers = $headersProperty->getValue($archangel);
142
-
143
-        $this->assertArraySubset(
144
-            array('BCC' => array('[email protected]')),
145
-            $headers
146
-        );
147
-    }
148
-
149
-    public function testAddBCCMultiple()
150
-    {
151
-        $archangel = new Archangel();
152
-        $archangel->addBCC('[email protected]');
153
-        $archangel->addBCC('[email protected]');
154
-        $headersProperty = $this->getProtectedProperty('headers');
155
-        $headers = $headersProperty->getValue($archangel);
156
-
157
-        $this->assertArraySubset(
158
-            array('BCC' => array('[email protected]', '[email protected]')),
159
-            $headers
160
-        );
161
-    }
162
-
163
-    public function testAddBCCWithTitle()
164
-    {
165
-        $archangel = new Archangel();
166
-        $archangel->addBCC('[email protected]', 'Mr. Test Alot');
167
-        $headersProperty = $this->getProtectedProperty('headers');
168
-        $headers = $headersProperty->getValue($archangel);
169
-
170
-        $this->assertArraySubset(
171
-            array('BCC' => array('"Mr. Test Alot" <[email protected]>')),
172
-            $headers
173
-        );
174
-    }
175
-
176
-    public function testSetFrom()
177
-    {
178
-        $archangel = new Archangel();
179
-        $archangel->setFrom('[email protected]');
180
-        $headersProperty = $this->getProtectedProperty('headers');
181
-        $headers = $headersProperty->getValue($archangel);
182
-
183
-        $this->assertArraySubset(array('From' => '[email protected]'), $headers);
184
-    }
185
-
186
-    public function testSetFromMultiple()
187
-    {
188
-        $archangel = new Archangel();
189
-        $archangel->setFrom('[email protected]');
190
-        $archangel->setFrom('[email protected]');
191
-        $headersProperty = $this->getProtectedProperty('headers');
192
-        $headers = $headersProperty->getValue($archangel);
193
-
194
-        $this->assertArraySubset(array('From' => '[email protected]'), $headers);
195
-        $this->assertNotContains('[email protected]', $headers);
196
-    }
197
-
198
-    public function testSetFromWithTitle()
199
-    {
200
-        $archangel = new Archangel();
201
-        $archangel->setFrom('[email protected]', 'Mr. Test Alot');
202
-        $headersProperty = $this->getProtectedProperty('headers');
203
-        $headers = $headersProperty->getValue($archangel);
204
-
205
-        $this->assertArraySubset(array('From' => '"Mr. Test Alot" <[email protected]>'), $headers);
206
-    }
207
-
208
-    public function testSetReplyTo()
209
-    {
210
-        $archangel = new Archangel();
211
-        $archangel->setReplyTo('[email protected]');
212
-        $headersProperty = $this->getProtectedProperty('headers');
213
-        $headers = $headersProperty->getValue($archangel);
214
-
215
-        $this->assertArraySubset(array('Reply-To' => '[email protected]'), $headers);
216
-    }
217
-
218
-    public function testSetReplyToMultiple()
219
-    {
220
-        $archangel = new Archangel();
221
-        $archangel->setReplyTo('[email protected]');
222
-        $archangel->setReplyTo('[email protected]');
223
-        $headersProperty = $this->getProtectedProperty('headers');
224
-        $headers = $headersProperty->getValue($archangel);
225
-
226
-        $this->assertArraySubset(array('Reply-To' => '[email protected]'), $headers);
227
-        $this->assertNotContains('[email protected]', $headers);
228
-    }
229
-
230
-    public function testSetReplyToWithTitle()
231
-    {
232
-        $archangel = new Archangel();
233
-        $archangel->setReplyTo('[email protected]', 'Mr. Test Alot');
234
-        $headersProperty = $this->getProtectedProperty('headers');
235
-        $headers = $headersProperty->getValue($archangel);
236
-
237
-        $this->assertArraySubset(array('Reply-To' => '"Mr. Test Alot" <[email protected]>'), $headers);
238
-    }
239
-
240
-    public function testFormatEmailAddress()
241
-    {
242
-        $archangel = new Archangel();
243
-        $formatMethod = $this->getProtectedMethod('formatEmailAddress');
244
-        $formattedEmail = $formatMethod->invokeArgs($archangel, array('[email protected]', ''));
245
-
246
-        $this->assertEquals('[email protected]', $formattedEmail);
247
-    }
248
-
249
-    public function testFormatEmailAddressWithTitle()
250
-    {
251
-        $archangel = new Archangel();
252
-        $formatMethod = $this->getProtectedMethod('formatEmailAddress');
253
-        $formattedEmail = $formatMethod->invokeArgs($archangel, array('[email protected]', 'Mr. Test Alot'));
254
-
255
-        $this->assertEquals('"Mr. Test Alot" <[email protected]>', $formattedEmail);
256
-    }
257
-
258
-    public function testSetSubject()
259
-    {
260
-        $archangel = new Archangel();
261
-        $archangel->setSubject('Test Subject');
262
-
263
-        $this->assertAttributeEquals('Test Subject', 'subject', $archangel);
264
-    }
265
-
266
-    public function testSetPlainMessage()
267
-    {
268
-        $archangel = new Archangel();
269
-        $archangel->setPlainMessage('Plain text message');
270
-
271
-        $this->assertAttributeEquals('Plain text message', 'plainMessage', $archangel);
272
-    }
273
-
274
-    public function testSetHTMLMessage()
275
-    {
276
-        $archangel = new Archangel();
277
-        $archangel->setHTMLMessage('<p>An HTML message.</p>');
278
-
279
-        $this->assertAttributeEquals('<p>An HTML message.</p>', 'htmlMessage', $archangel);
280
-    }
281
-
282
-    public function testAddAttachment()
283
-    {
284
-        $archangel = new Archangel();
285
-        $archangel->addAttachment('path', 'type');
286
-
287
-        $this->assertAttributeContains(
288
-            array('path' => 'path', 'type' => 'type', 'title' => ''),
289
-            'attachments',
290
-            $archangel
291
-        );
292
-    }
293
-
294
-    public function testAddAttachmentMultiple()
295
-    {
296
-        $archangel = new Archangel();
297
-        $archangel->addAttachment('pathOne', 'typeOne');
298
-        $archangel->addAttachment('pathTwo', 'typeTwo');
299
-
300
-        $this->assertAttributeContains(
301
-            array('path' => 'pathOne', 'type' => 'typeOne', 'title' => ''),
302
-            'attachments',
303
-            $archangel
304
-        );
305
-        $this->assertAttributeContains(
306
-            array('path' => 'pathTwo', 'type' => 'typeTwo', 'title' => ''),
307
-            'attachments',
308
-            $archangel
309
-        );
310
-    }
311
-
312
-    public function testAddAttachmentWithTitle()
313
-    {
314
-        $archangel = new Archangel();
315
-        $archangel->addAttachment('path', 'type', 'title');
316
-
317
-        $this->assertAttributeContains(
318
-            array('path' => 'path', 'type' => 'type', 'title' => 'title'),
319
-            'attachments',
320
-            $archangel
321
-        );
322
-    }
323
-
324
-    public function testSend()
325
-    {
326
-        $archangel = new Archangel();
327
-        $archangel->addTo('[email protected]');
328
-        $archangel->setSubject('Test Subject');
329
-        $archangel->setPlainMessage('Plain text message');
330
-        $response = $archangel->send();
331
-
332
-        $expectedResponse = array(
333
-            'to' => '[email protected]',
334
-            'subject' => 'Test Subject',
335
-            'message' => 'Plain text message',
336
-            'headers' => 'X-Mailer: PHP/6.0.0',
337
-        );
338
-
339
-        $this->assertEquals($expectedResponse, $response);
340
-    }
341
-
342
-    public function testSendFailure()
343
-    {
344
-        $archangel = new Archangel();
345
-        $response = $archangel->send();
346
-
347
-        $this->assertFalse($response);
348
-    }
349
-
350
-    /**
351
-     * @dataProvider dataCheckRequiredFields
352
-     */
353
-    public function testCheckRequiredFields(
354
-        $expectedResult,
355
-        $toAddresses,
356
-        $subject,
357
-        $plainMessage,
358
-        $htmlMessage,
359
-        $attachments
360
-    ) {
361
-        $archangel = new Archangel();
362
-
363
-        if (!empty($toAddresses)) {
364
-            $toAddressesProperty = $this->getProtectedProperty('toAddresses');
365
-            $toAddressesProperty->setValue($archangel, $toAddresses);
366
-        }
367
-
368
-        if (!empty($subject)) {
369
-            $subjectProperty = $this->getProtectedProperty('subject');
370
-            $subjectProperty->setValue($archangel, $subject);
371
-        }
372
-
373
-        if (!empty($plainMessage)) {
374
-            $plainMessageProperty = $this->getProtectedProperty('plainMessage');
375
-            $plainMessageProperty->setValue($archangel, $plainMessage);
376
-        }
377
-
378
-        if (!empty($htmlMessage)) {
379
-            $htmlMessageProperty = $this->getProtectedProperty('htmlMessage');
380
-            $htmlMessageProperty->setValue($archangel, $htmlMessage);
381
-        }
382
-
383
-        if (!empty($attachments)) {
384
-            $attachmentsProperty = $this->getProtectedProperty('attachments');
385
-            $attachmentsProperty->setValue($archangel, $attachments);
386
-        }
387
-
388
-        $checkMethod = $this->getProtectedMethod('checkRequiredFields');
389
-        $isValid = $checkMethod->invoke($archangel);
390
-
391
-        if ($expectedResult == true) {
392
-            $this->assertTrue($isValid);
393
-            return;
394
-        }
395
-        $this->assertNotTrue($isValid);
396
-    }
397
-
398
-    public function dataCheckRequiredFields()
399
-    {
400
-        return array(
401
-            array(
402
-                'expectedResult' => false,
403
-                'toAddresses' => array(),
404
-                'subject' => '',
405
-                'plainMessage' => '',
406
-                'htmlMessage' => '',
407
-                'attachments' => array(),
408
-            ),
409
-            array(
410
-                'expectedResult' => false,
411
-                'toAddresses' => array('[email protected]'),
412
-                'subject' => '',
413
-                'plainMessage' => '',
414
-                'htmlMessage' => '',
415
-                'attachments' => array(),
416
-            ),
417
-            array(
418
-                'expectedResult' => false,
419
-                'toAddresses' => array('[email protected]'),
420
-                'subject' => 'Test Subject',
421
-                'plainMessage' => '',
422
-                'htmlMessage' => '',
423
-                'attachments' => array(),
424
-            ),
425
-            array(
426
-                'expectedResult' => false,
427
-                'toAddresses' => array(),
428
-                'subject' => 'Test Subject',
429
-                'plainMessage' => '',
430
-                'htmlMessage' => '',
431
-                'attachments' => array(),
432
-            ),
433
-            array(
434
-                'expectedResult' => false,
435
-                'toAddresses' => array(),
436
-                'subject' => 'Test Subject',
437
-                'plainMessage' => 'Plain text message',
438
-                'htmlMessage' => '',
439
-                'attachments' => array(),
440
-            ),
441
-            array(
442
-                'expectedResult' => true,
443
-                'toAddresses' => array('[email protected]'),
444
-                'subject' => 'Test Subject',
445
-                'plainMessage' => 'Plain text message',
446
-                'htmlMessage' => '',
447
-                'attachments' => array(),
448
-            ),
449
-            array(
450
-                'expectedResult' => true,
451
-                'toAddresses' => array('[email protected]'),
452
-                'subject' => 'Test Subject',
453
-                'plainMessage' => '',
454
-                'htmlMessage' => '<p>An HTML message.</p>',
455
-                'attachments' => array(),
456
-            ),
457
-            array(
458
-                'expectedResult' => true,
459
-                'toAddresses' => array('[email protected]'),
460
-                'subject' => 'Test Subject',
461
-                'plainMessage' => '',
462
-                'htmlMessage' => '',
463
-                'attachments' => array(
464
-                    array('path' => 'path', 'type' => 'type'),
465
-                ),
466
-            ),
467
-            array(
468
-                'expectedResult' => true,
469
-                'toAddresses' => array('[email protected]'),
470
-                'subject' => 'Test Subject',
471
-                'plainMessage' => 'Plain text message',
472
-                'htmlMessage' => '<p>An HTML message.</p>',
473
-                'attachments' => array(
474
-                    array('path' => 'path', 'type' => 'type'),
475
-                ),
476
-            ),
477
-       );
478
-    }
13
+	public function testIsInstanceOfArchangel()
14
+	{
15
+		$archangel = new Archangel();
16
+
17
+		$this->assertInstanceOf('Jacobemerick\Archangel\Archangel', $archangel);
18
+	}
19
+
20
+	public function testIsLoggerAwareInterface()
21
+	{
22
+		$archangel = new Archangel();
23
+
24
+		$this->assertInstanceOf('Psr\Log\LoggerAwareInterface', $archangel);
25
+	}
26
+
27
+	public function testConstructSetsDefaultMailer()
28
+	{
29
+		$archangel = new Archangel();
30
+		$mailer = sprintf('PHP/%s', phpversion());
31
+		$headers = array('X-Mailer' => $mailer);
32
+
33
+		$this->assertAttributeEquals($headers, 'headers', $archangel);
34
+	}
35
+
36
+	public function testConstructOverridesMailer()
37
+	{
38
+		$archangel = new Archangel('AwesomeMailer');
39
+		$headers = array('X-Mailer' => 'AwesomeMailer');
40
+
41
+		$this->assertAttributeEquals($headers, 'headers', $archangel);
42
+	}
43
+
44
+	public function testConstructSetsNullLogger()
45
+	{
46
+		$archangel = new Archangel();
47
+
48
+		$this->assertAttributeInstanceOf('Psr\Log\NullLogger', 'logger', $archangel);
49
+	}
50
+
51
+	public function testConstructSetsBoundaries()
52
+	{
53
+		$archangel = new Archangel();
54
+		$expectedBoundaryMixed = sprintf('PHP-mixed-%s', uniqid());
55
+		$expectedBoundaryAlternative = sprintf('PHP-alternative-%s', uniqid());
56
+
57
+		$this->assertAttributeEquals($expectedBoundaryMixed, 'boundaryMixed', $archangel);
58
+		$this->assertAttributeEquals($expectedBoundaryAlternative, 'boundaryAlternative', $archangel);
59
+	}
60
+
61
+	public function testSetLogger()
62
+	{
63
+		$logger = $this->getMock('Psr\Log\LoggerInterface');
64
+		$archangel = new Archangel();
65
+		$archangel->setLogger($logger);
66
+
67
+		$this->assertAttributeSame($logger, 'logger', $archangel);
68
+	}
69
+
70
+	public function testAddTo()
71
+	{
72
+		$archangel = new Archangel();
73
+		$archangel->addTo('[email protected]');
74
+
75
+		$this->assertAttributeContains('[email protected]', 'toAddresses', $archangel);
76
+	}
77
+
78
+	public function testAddToMultiple()
79
+	{
80
+		$archangel = new Archangel();
81
+		$archangel->addTo('[email protected]');
82
+		$archangel->addTo('[email protected]');
83
+
84
+		$this->assertAttributeContains('[email protected]', 'toAddresses', $archangel);
85
+		$this->assertAttributeContains('[email protected]', 'toAddresses', $archangel);
86
+	}
87
+
88
+	public function testAddToWithTitle()
89
+	{
90
+		$archangel = new Archangel();
91
+		$archangel->addTo('[email protected]', 'Mr. Test Alot');
92
+
93
+		$this->assertAttributeContains('"Mr. Test Alot" <[email protected]>', 'toAddresses', $archangel);
94
+	}
95
+
96
+	public function testAddCC()
97
+	{
98
+		$archangel = new Archangel();
99
+		$archangel->addCC('[email protected]');
100
+		$headersProperty = $this->getProtectedProperty('headers');
101
+		$headers = $headersProperty->getValue($archangel);
102
+
103
+		$this->assertArraySubset(
104
+			array('CC' => array('[email protected]')),
105
+			$headers
106
+		);
107
+	}
108
+
109
+	public function testAddCCMultiple()
110
+	{
111
+		$archangel = new Archangel();
112
+		$archangel->addCC('[email protected]');
113
+		$archangel->addCC('[email protected]');
114
+		$headersProperty = $this->getProtectedProperty('headers');
115
+		$headers = $headersProperty->getValue($archangel);
116
+
117
+		$this->assertArraySubset(
118
+			array('CC' => array('[email protected]', '[email protected]')),
119
+			$headers
120
+		);
121
+	}
122
+
123
+	public function testAddCCWithTitle()
124
+	{
125
+		$archangel = new Archangel();
126
+		$archangel->addCC('[email protected]', 'Mr. Test Alot');
127
+		$headersProperty = $this->getProtectedProperty('headers');
128
+		$headers = $headersProperty->getValue($archangel);
129
+
130
+		$this->assertArraySubset(
131
+			array('CC' => array('"Mr. Test Alot" <[email protected]>')),
132
+			$headers
133
+		);
134
+	}
135
+
136
+	public function testAddBCC()
137
+	{
138
+		$archangel = new Archangel();
139
+		$archangel->addBCC('[email protected]');
140
+		$headersProperty = $this->getProtectedProperty('headers');
141
+		$headers = $headersProperty->getValue($archangel);
142
+
143
+		$this->assertArraySubset(
144
+			array('BCC' => array('[email protected]')),
145
+			$headers
146
+		);
147
+	}
148
+
149
+	public function testAddBCCMultiple()
150
+	{
151
+		$archangel = new Archangel();
152
+		$archangel->addBCC('[email protected]');
153
+		$archangel->addBCC('[email protected]');
154
+		$headersProperty = $this->getProtectedProperty('headers');
155
+		$headers = $headersProperty->getValue($archangel);
156
+
157
+		$this->assertArraySubset(
158
+			array('BCC' => array('[email protected]', '[email protected]')),
159
+			$headers
160
+		);
161
+	}
162
+
163
+	public function testAddBCCWithTitle()
164
+	{
165
+		$archangel = new Archangel();
166
+		$archangel->addBCC('[email protected]', 'Mr. Test Alot');
167
+		$headersProperty = $this->getProtectedProperty('headers');
168
+		$headers = $headersProperty->getValue($archangel);
169
+
170
+		$this->assertArraySubset(
171
+			array('BCC' => array('"Mr. Test Alot" <[email protected]>')),
172
+			$headers
173
+		);
174
+	}
175
+
176
+	public function testSetFrom()
177
+	{
178
+		$archangel = new Archangel();
179
+		$archangel->setFrom('[email protected]');
180
+		$headersProperty = $this->getProtectedProperty('headers');
181
+		$headers = $headersProperty->getValue($archangel);
182
+
183
+		$this->assertArraySubset(array('From' => '[email protected]'), $headers);
184
+	}
185
+
186
+	public function testSetFromMultiple()
187
+	{
188
+		$archangel = new Archangel();
189
+		$archangel->setFrom('[email protected]');
190
+		$archangel->setFrom('[email protected]');
191
+		$headersProperty = $this->getProtectedProperty('headers');
192
+		$headers = $headersProperty->getValue($archangel);
193
+
194
+		$this->assertArraySubset(array('From' => '[email protected]'), $headers);
195
+		$this->assertNotContains('[email protected]', $headers);
196
+	}
197
+
198
+	public function testSetFromWithTitle()
199
+	{
200
+		$archangel = new Archangel();
201
+		$archangel->setFrom('[email protected]', 'Mr. Test Alot');
202
+		$headersProperty = $this->getProtectedProperty('headers');
203
+		$headers = $headersProperty->getValue($archangel);
204
+
205
+		$this->assertArraySubset(array('From' => '"Mr. Test Alot" <[email protected]>'), $headers);
206
+	}
207
+
208
+	public function testSetReplyTo()
209
+	{
210
+		$archangel = new Archangel();
211
+		$archangel->setReplyTo('[email protected]');
212
+		$headersProperty = $this->getProtectedProperty('headers');
213
+		$headers = $headersProperty->getValue($archangel);
214
+
215
+		$this->assertArraySubset(array('Reply-To' => '[email protected]'), $headers);
216
+	}
217
+
218
+	public function testSetReplyToMultiple()
219
+	{
220
+		$archangel = new Archangel();
221
+		$archangel->setReplyTo('[email protected]');
222
+		$archangel->setReplyTo('[email protected]');
223
+		$headersProperty = $this->getProtectedProperty('headers');
224
+		$headers = $headersProperty->getValue($archangel);
225
+
226
+		$this->assertArraySubset(array('Reply-To' => '[email protected]'), $headers);
227
+		$this->assertNotContains('[email protected]', $headers);
228
+	}
229
+
230
+	public function testSetReplyToWithTitle()
231
+	{
232
+		$archangel = new Archangel();
233
+		$archangel->setReplyTo('[email protected]', 'Mr. Test Alot');
234
+		$headersProperty = $this->getProtectedProperty('headers');
235
+		$headers = $headersProperty->getValue($archangel);
236
+
237
+		$this->assertArraySubset(array('Reply-To' => '"Mr. Test Alot" <[email protected]>'), $headers);
238
+	}
239
+
240
+	public function testFormatEmailAddress()
241
+	{
242
+		$archangel = new Archangel();
243
+		$formatMethod = $this->getProtectedMethod('formatEmailAddress');
244
+		$formattedEmail = $formatMethod->invokeArgs($archangel, array('[email protected]', ''));
245
+
246
+		$this->assertEquals('[email protected]', $formattedEmail);
247
+	}
248
+
249
+	public function testFormatEmailAddressWithTitle()
250
+	{
251
+		$archangel = new Archangel();
252
+		$formatMethod = $this->getProtectedMethod('formatEmailAddress');
253
+		$formattedEmail = $formatMethod->invokeArgs($archangel, array('[email protected]', 'Mr. Test Alot'));
254
+
255
+		$this->assertEquals('"Mr. Test Alot" <[email protected]>', $formattedEmail);
256
+	}
257
+
258
+	public function testSetSubject()
259
+	{
260
+		$archangel = new Archangel();
261
+		$archangel->setSubject('Test Subject');
262
+
263
+		$this->assertAttributeEquals('Test Subject', 'subject', $archangel);
264
+	}
265
+
266
+	public function testSetPlainMessage()
267
+	{
268
+		$archangel = new Archangel();
269
+		$archangel->setPlainMessage('Plain text message');
270
+
271
+		$this->assertAttributeEquals('Plain text message', 'plainMessage', $archangel);
272
+	}
273
+
274
+	public function testSetHTMLMessage()
275
+	{
276
+		$archangel = new Archangel();
277
+		$archangel->setHTMLMessage('<p>An HTML message.</p>');
278
+
279
+		$this->assertAttributeEquals('<p>An HTML message.</p>', 'htmlMessage', $archangel);
280
+	}
281
+
282
+	public function testAddAttachment()
283
+	{
284
+		$archangel = new Archangel();
285
+		$archangel->addAttachment('path', 'type');
286
+
287
+		$this->assertAttributeContains(
288
+			array('path' => 'path', 'type' => 'type', 'title' => ''),
289
+			'attachments',
290
+			$archangel
291
+		);
292
+	}
293
+
294
+	public function testAddAttachmentMultiple()
295
+	{
296
+		$archangel = new Archangel();
297
+		$archangel->addAttachment('pathOne', 'typeOne');
298
+		$archangel->addAttachment('pathTwo', 'typeTwo');
299
+
300
+		$this->assertAttributeContains(
301
+			array('path' => 'pathOne', 'type' => 'typeOne', 'title' => ''),
302
+			'attachments',
303
+			$archangel
304
+		);
305
+		$this->assertAttributeContains(
306
+			array('path' => 'pathTwo', 'type' => 'typeTwo', 'title' => ''),
307
+			'attachments',
308
+			$archangel
309
+		);
310
+	}
311
+
312
+	public function testAddAttachmentWithTitle()
313
+	{
314
+		$archangel = new Archangel();
315
+		$archangel->addAttachment('path', 'type', 'title');
316
+
317
+		$this->assertAttributeContains(
318
+			array('path' => 'path', 'type' => 'type', 'title' => 'title'),
319
+			'attachments',
320
+			$archangel
321
+		);
322
+	}
323
+
324
+	public function testSend()
325
+	{
326
+		$archangel = new Archangel();
327
+		$archangel->addTo('[email protected]');
328
+		$archangel->setSubject('Test Subject');
329
+		$archangel->setPlainMessage('Plain text message');
330
+		$response = $archangel->send();
331
+
332
+		$expectedResponse = array(
333
+			'to' => '[email protected]',
334
+			'subject' => 'Test Subject',
335
+			'message' => 'Plain text message',
336
+			'headers' => 'X-Mailer: PHP/6.0.0',
337
+		);
338
+
339
+		$this->assertEquals($expectedResponse, $response);
340
+	}
341
+
342
+	public function testSendFailure()
343
+	{
344
+		$archangel = new Archangel();
345
+		$response = $archangel->send();
346
+
347
+		$this->assertFalse($response);
348
+	}
349
+
350
+	/**
351
+	 * @dataProvider dataCheckRequiredFields
352
+	 */
353
+	public function testCheckRequiredFields(
354
+		$expectedResult,
355
+		$toAddresses,
356
+		$subject,
357
+		$plainMessage,
358
+		$htmlMessage,
359
+		$attachments
360
+	) {
361
+		$archangel = new Archangel();
362
+
363
+		if (!empty($toAddresses)) {
364
+			$toAddressesProperty = $this->getProtectedProperty('toAddresses');
365
+			$toAddressesProperty->setValue($archangel, $toAddresses);
366
+		}
367
+
368
+		if (!empty($subject)) {
369
+			$subjectProperty = $this->getProtectedProperty('subject');
370
+			$subjectProperty->setValue($archangel, $subject);
371
+		}
372
+
373
+		if (!empty($plainMessage)) {
374
+			$plainMessageProperty = $this->getProtectedProperty('plainMessage');
375
+			$plainMessageProperty->setValue($archangel, $plainMessage);
376
+		}
377
+
378
+		if (!empty($htmlMessage)) {
379
+			$htmlMessageProperty = $this->getProtectedProperty('htmlMessage');
380
+			$htmlMessageProperty->setValue($archangel, $htmlMessage);
381
+		}
382
+
383
+		if (!empty($attachments)) {
384
+			$attachmentsProperty = $this->getProtectedProperty('attachments');
385
+			$attachmentsProperty->setValue($archangel, $attachments);
386
+		}
387
+
388
+		$checkMethod = $this->getProtectedMethod('checkRequiredFields');
389
+		$isValid = $checkMethod->invoke($archangel);
390
+
391
+		if ($expectedResult == true) {
392
+			$this->assertTrue($isValid);
393
+			return;
394
+		}
395
+		$this->assertNotTrue($isValid);
396
+	}
397
+
398
+	public function dataCheckRequiredFields()
399
+	{
400
+		return array(
401
+			array(
402
+				'expectedResult' => false,
403
+				'toAddresses' => array(),
404
+				'subject' => '',
405
+				'plainMessage' => '',
406
+				'htmlMessage' => '',
407
+				'attachments' => array(),
408
+			),
409
+			array(
410
+				'expectedResult' => false,
411
+				'toAddresses' => array('[email protected]'),
412
+				'subject' => '',
413
+				'plainMessage' => '',
414
+				'htmlMessage' => '',
415
+				'attachments' => array(),
416
+			),
417
+			array(
418
+				'expectedResult' => false,
419
+				'toAddresses' => array('[email protected]'),
420
+				'subject' => 'Test Subject',
421
+				'plainMessage' => '',
422
+				'htmlMessage' => '',
423
+				'attachments' => array(),
424
+			),
425
+			array(
426
+				'expectedResult' => false,
427
+				'toAddresses' => array(),
428
+				'subject' => 'Test Subject',
429
+				'plainMessage' => '',
430
+				'htmlMessage' => '',
431
+				'attachments' => array(),
432
+			),
433
+			array(
434
+				'expectedResult' => false,
435
+				'toAddresses' => array(),
436
+				'subject' => 'Test Subject',
437
+				'plainMessage' => 'Plain text message',
438
+				'htmlMessage' => '',
439
+				'attachments' => array(),
440
+			),
441
+			array(
442
+				'expectedResult' => true,
443
+				'toAddresses' => array('[email protected]'),
444
+				'subject' => 'Test Subject',
445
+				'plainMessage' => 'Plain text message',
446
+				'htmlMessage' => '',
447
+				'attachments' => array(),
448
+			),
449
+			array(
450
+				'expectedResult' => true,
451
+				'toAddresses' => array('[email protected]'),
452
+				'subject' => 'Test Subject',
453
+				'plainMessage' => '',
454
+				'htmlMessage' => '<p>An HTML message.</p>',
455
+				'attachments' => array(),
456
+			),
457
+			array(
458
+				'expectedResult' => true,
459
+				'toAddresses' => array('[email protected]'),
460
+				'subject' => 'Test Subject',
461
+				'plainMessage' => '',
462
+				'htmlMessage' => '',
463
+				'attachments' => array(
464
+					array('path' => 'path', 'type' => 'type'),
465
+				),
466
+			),
467
+			array(
468
+				'expectedResult' => true,
469
+				'toAddresses' => array('[email protected]'),
470
+				'subject' => 'Test Subject',
471
+				'plainMessage' => 'Plain text message',
472
+				'htmlMessage' => '<p>An HTML message.</p>',
473
+				'attachments' => array(
474
+					array('path' => 'path', 'type' => 'type'),
475
+				),
476
+			),
477
+	   );
478
+	}
479 479
  
480
-    public function testBuildTo()
481
-    {
482
-        $archangel = new Archangel();
483
-        $addressesProperty = $this->getProtectedProperty('toAddresses');
484
-        $addressesProperty->setValue($archangel, array('[email protected]'));
485
-        $buildMethod = $this->getProtectedMethod('buildTo');
486
-        $toAddresses = $buildMethod->invoke($archangel);
487
-
488
-        $this->assertEquals('[email protected]', $toAddresses);
489
-    }
490
-
491
-    public function testBuildToMultiple()
492
-    {
493
-        $archangel = new Archangel();
494
-        $addressesProperty = $this->getProtectedProperty('toAddresses');
495
-        $addressesProperty->setValue($archangel, array('[email protected]', '[email protected]'));
496
-        $buildMethod = $this->getProtectedMethod('buildTo');
497
-        $toAddresses = $buildMethod->invoke($archangel);
498
-
499
-        $this->assertEquals('[email protected], [email protected]', $toAddresses);
500
-    }
501
-
502
-    public function testBuildPlainMessageHeader()
503
-    {
504
-        $expectedMessageHeader = array(
505
-            'Content-Type: text/plain; charset="iso-8859"',
506
-            'Content-Transfer-Encoding: 7bit',
507
-            '',
508
-        );
509
-
510
-        $archangel = new Archangel();
511
-        $buildMethod = $this->getProtectedMethod('buildPlainMessageHeader');
512
-        $messageHeader = $buildMethod->invoke($archangel);
513
-
514
-        $this->assertEquals($expectedMessageHeader, $messageHeader);
515
-    }
516
-
517
-    public function testBuildHtmlMessageHeader()
518
-    {
519
-        $expectedMessageHeader = array(
520
-            'Content-Type: text/html; charset="iso-8859-1"',
521
-            'Content-Transfer-Encoding: 7bit',
522
-            '',
523
-        );
524
-
525
-        $archangel = new Archangel();
526
-        $buildMethod = $this->getProtectedMethod('buildHtmlMessageHeader');
527
-        $messageHeader = $buildMethod->invoke($archangel);
528
-
529
-        $this->assertEquals($expectedMessageHeader, $messageHeader);
530
-    }
531
-
532
-    /**
533
-     * @dataProvider dataBuildHeaders
534
-     */
535
-    public function testBuildHeaders(
536
-        $expectedHeaders,
537
-        $headers,
538
-        $attachments,
539
-        $plainMessage,
540
-        $htmlMessage
541
-    ) {
542
-        $archangel = new Archangel();
543
-        $headersProperty = $this->getProtectedProperty('headers');
544
-        $headersProperty->setValue($archangel, $headers);
545
-
546
-        if (!empty($attachments)) {
547
-            $attachmentsProperty = $this->getProtectedProperty('attachments');
548
-            $attachmentsProperty->setValue($archangel, $attachments);
549
-        }
550
-
551
-        if (!empty($plainMessage)) {
552
-            $plainMessageProperty = $this->getProtectedProperty('plainMessage');
553
-            $plainMessageProperty->setValue($archangel, $plainMessage);
554
-        }
555
-
556
-        if (!empty($htmlMessage)) {
557
-            $htmlMessageProperty = $this->getProtectedProperty('htmlMessage');
558
-            $htmlMessageProperty->setValue($archangel, $htmlMessage);
559
-        }
560
-
561
-        $buildHeadersMethod = $this->getProtectedMethod('buildHeaders');
562
-        $builtHeaders = $buildHeadersMethod->invoke($archangel);
563
-
564
-        $this->assertEquals($expectedHeaders, $builtHeaders);
565
-    }
566
-
567
-    public function dataBuildHeaders()
568
-    {
569
-        return array(
570
-            array(
571
-                'expectedHeaders' =>
572
-                    "From: [email protected]\r\n" .
573
-                    "X-Mailer: PHP/6.0.0",
574
-                'headers' => array(
575
-                    'From' => '[email protected]',
576
-                    'X-Mailer' => sprintf('PHP/%s', phpversion())
577
-                ),
578
-                'attachments' => null,
579
-                'plainMessage' => true,
580
-                'htmlMessage' => null,
581
-            ),
582
-            array(
583
-                'expectedHeaders' =>
584
-                    "CC: [email protected], [email protected]\r\n" .
585
-                    "From: [email protected]\r\n" .
586
-                    "X-Mailer: PHP/6.0.0",
587
-                'headers' => array(
588
-                    'CC' => array('[email protected]', '[email protected]'),
589
-                    'From' => '[email protected]',
590
-                    'X-Mailer' => sprintf('PHP/%s', phpversion())
591
-                ),
592
-                'attachments' => null,
593
-                'plainMessage' => true,
594
-                'htmlMessage' => null,
595
-            ),
596
-            array(
597
-                'expectedHeaders' =>
598
-                    "BCC: [email protected], [email protected]\r\n" .
599
-                    "From: [email protected]\r\n" .
600
-                    "X-Mailer: PHP/6.0.0",
601
-                'headers' => array(
602
-                    'BCC' => array('[email protected]', '[email protected]'),
603
-                    'From' => '[email protected]',
604
-                    'X-Mailer' => sprintf('PHP/%s', phpversion())
605
-                ),
606
-                'attachments' => null,
607
-                'plainMessage' => true,
608
-                'htmlMessage' => null,
609
-            ),
610
-            array(
611
-                'expectedHeaders' =>
612
-                    "From: [email protected]\r\n" .
613
-                    "X-Mailer: PHP/6.0.0\r\n" .
614
-                    "Content-Type: multipart/mixed; boundary=\"PHP-mixed-1234567890123\"",
615
-                'headers' => array(
616
-                    'From' => '[email protected]',
617
-                    'X-Mailer' => sprintf('PHP/%s', phpversion())
618
-                ),
619
-                'attachments' => true,
620
-                'plainMessage' => true,
621
-                'htmlMessage' => null,
622
-            ),
623
-            array(
624
-                'expectedHeaders' =>
625
-                    "From: [email protected]\r\n" .
626
-                    "X-Mailer: PHP/6.0.0\r\n" .
627
-                    "Content-Type: multipart/alternative; boundary=\"PHP-alternative-1234567890123\"",
628
-                'headers' => array(
629
-                    'From' => '[email protected]',
630
-                    'X-Mailer' => sprintf('PHP/%s', phpversion())
631
-                ),
632
-                'attachments' => null,
633
-                'plainMessage' => true,
634
-                'htmlMessage' => true,
635
-            ),
636
-            array(
637
-                'expectedHeaders' =>
638
-                    "From: [email protected]\r\n" .
639
-                    "X-Mailer: PHP/6.0.0\r\n" .
640
-                    "Content-type: text/html; charset=\"iso-8859-1\"",
641
-                'headers' => array(
642
-                    'From' => '[email protected]',
643
-                    'X-Mailer' => sprintf('PHP/%s', phpversion())
644
-                ),
645
-                'attachments' => null,
646
-                'plainMessage' => null,
647
-                'htmlMessage' => true,
648
-            ),
649
-        );
650
-    }
651
-
652
-    public function testBuildAttachmentContent()
653
-    {
654
-        $textContent = 'Dummy Content';
655
-        $expectedContent = chunk_split(base64_encode($textContent));
656
-
657
-        $path = __DIR__ . '/test.txt';
658
-        $handle = fopen($path, 'w');
659
-        fwrite($handle, $textContent);
660
-        fclose($handle);
661
-
662
-        $archangel = new Archangel();
663
-        $buildMethod = $this->getProtectedMethod('buildAttachmentContent');
664
-        $content = $buildMethod->invokeArgs($archangel, array($path));
665
-
666
-        unlink($path);
667
-        $this->assertEquals($expectedContent, $content);
668
-    }
669
-
670
-    protected function getProtectedProperty($property)
671
-    {
672
-        $reflectedArchangel = new ReflectionClass('Jacobemerick\Archangel\Archangel');
673
-        $reflectedProperty = $reflectedArchangel->getProperty($property);
674
-        $reflectedProperty->setAccessible(true);
675
-
676
-        return $reflectedProperty;
677
-    }
678
-
679
-    protected function getProtectedMethod($method)
680
-    {
681
-        $reflectedArchangel = new ReflectionClass('Jacobemerick\Archangel\Archangel');
682
-        $reflectedMethod = $reflectedArchangel->getMethod($method);
683
-        $reflectedMethod->setAccessible(true);
684
-
685
-        return $reflectedMethod;
686
-    }
480
+	public function testBuildTo()
481
+	{
482
+		$archangel = new Archangel();
483
+		$addressesProperty = $this->getProtectedProperty('toAddresses');
484
+		$addressesProperty->setValue($archangel, array('[email protected]'));
485
+		$buildMethod = $this->getProtectedMethod('buildTo');
486
+		$toAddresses = $buildMethod->invoke($archangel);
487
+
488
+		$this->assertEquals('[email protected]', $toAddresses);
489
+	}
490
+
491
+	public function testBuildToMultiple()
492
+	{
493
+		$archangel = new Archangel();
494
+		$addressesProperty = $this->getProtectedProperty('toAddresses');
495
+		$addressesProperty->setValue($archangel, array('[email protected]', '[email protected]'));
496
+		$buildMethod = $this->getProtectedMethod('buildTo');
497
+		$toAddresses = $buildMethod->invoke($archangel);
498
+
499
+		$this->assertEquals('[email protected], [email protected]', $toAddresses);
500
+	}
501
+
502
+	public function testBuildPlainMessageHeader()
503
+	{
504
+		$expectedMessageHeader = array(
505
+			'Content-Type: text/plain; charset="iso-8859"',
506
+			'Content-Transfer-Encoding: 7bit',
507
+			'',
508
+		);
509
+
510
+		$archangel = new Archangel();
511
+		$buildMethod = $this->getProtectedMethod('buildPlainMessageHeader');
512
+		$messageHeader = $buildMethod->invoke($archangel);
513
+
514
+		$this->assertEquals($expectedMessageHeader, $messageHeader);
515
+	}
516
+
517
+	public function testBuildHtmlMessageHeader()
518
+	{
519
+		$expectedMessageHeader = array(
520
+			'Content-Type: text/html; charset="iso-8859-1"',
521
+			'Content-Transfer-Encoding: 7bit',
522
+			'',
523
+		);
524
+
525
+		$archangel = new Archangel();
526
+		$buildMethod = $this->getProtectedMethod('buildHtmlMessageHeader');
527
+		$messageHeader = $buildMethod->invoke($archangel);
528
+
529
+		$this->assertEquals($expectedMessageHeader, $messageHeader);
530
+	}
531
+
532
+	/**
533
+	 * @dataProvider dataBuildHeaders
534
+	 */
535
+	public function testBuildHeaders(
536
+		$expectedHeaders,
537
+		$headers,
538
+		$attachments,
539
+		$plainMessage,
540
+		$htmlMessage
541
+	) {
542
+		$archangel = new Archangel();
543
+		$headersProperty = $this->getProtectedProperty('headers');
544
+		$headersProperty->setValue($archangel, $headers);
545
+
546
+		if (!empty($attachments)) {
547
+			$attachmentsProperty = $this->getProtectedProperty('attachments');
548
+			$attachmentsProperty->setValue($archangel, $attachments);
549
+		}
550
+
551
+		if (!empty($plainMessage)) {
552
+			$plainMessageProperty = $this->getProtectedProperty('plainMessage');
553
+			$plainMessageProperty->setValue($archangel, $plainMessage);
554
+		}
555
+
556
+		if (!empty($htmlMessage)) {
557
+			$htmlMessageProperty = $this->getProtectedProperty('htmlMessage');
558
+			$htmlMessageProperty->setValue($archangel, $htmlMessage);
559
+		}
560
+
561
+		$buildHeadersMethod = $this->getProtectedMethod('buildHeaders');
562
+		$builtHeaders = $buildHeadersMethod->invoke($archangel);
563
+
564
+		$this->assertEquals($expectedHeaders, $builtHeaders);
565
+	}
566
+
567
+	public function dataBuildHeaders()
568
+	{
569
+		return array(
570
+			array(
571
+				'expectedHeaders' =>
572
+					"From: [email protected]\r\n" .
573
+					"X-Mailer: PHP/6.0.0",
574
+				'headers' => array(
575
+					'From' => '[email protected]',
576
+					'X-Mailer' => sprintf('PHP/%s', phpversion())
577
+				),
578
+				'attachments' => null,
579
+				'plainMessage' => true,
580
+				'htmlMessage' => null,
581
+			),
582
+			array(
583
+				'expectedHeaders' =>
584
+					"CC: [email protected], [email protected]\r\n" .
585
+					"From: [email protected]\r\n" .
586
+					"X-Mailer: PHP/6.0.0",
587
+				'headers' => array(
588
+					'CC' => array('[email protected]', '[email protected]'),
589
+					'From' => '[email protected]',
590
+					'X-Mailer' => sprintf('PHP/%s', phpversion())
591
+				),
592
+				'attachments' => null,
593
+				'plainMessage' => true,
594
+				'htmlMessage' => null,
595
+			),
596
+			array(
597
+				'expectedHeaders' =>
598
+					"BCC: [email protected], [email protected]\r\n" .
599
+					"From: [email protected]\r\n" .
600
+					"X-Mailer: PHP/6.0.0",
601
+				'headers' => array(
602
+					'BCC' => array('[email protected]', '[email protected]'),
603
+					'From' => '[email protected]',
604
+					'X-Mailer' => sprintf('PHP/%s', phpversion())
605
+				),
606
+				'attachments' => null,
607
+				'plainMessage' => true,
608
+				'htmlMessage' => null,
609
+			),
610
+			array(
611
+				'expectedHeaders' =>
612
+					"From: [email protected]\r\n" .
613
+					"X-Mailer: PHP/6.0.0\r\n" .
614
+					"Content-Type: multipart/mixed; boundary=\"PHP-mixed-1234567890123\"",
615
+				'headers' => array(
616
+					'From' => '[email protected]',
617
+					'X-Mailer' => sprintf('PHP/%s', phpversion())
618
+				),
619
+				'attachments' => true,
620
+				'plainMessage' => true,
621
+				'htmlMessage' => null,
622
+			),
623
+			array(
624
+				'expectedHeaders' =>
625
+					"From: [email protected]\r\n" .
626
+					"X-Mailer: PHP/6.0.0\r\n" .
627
+					"Content-Type: multipart/alternative; boundary=\"PHP-alternative-1234567890123\"",
628
+				'headers' => array(
629
+					'From' => '[email protected]',
630
+					'X-Mailer' => sprintf('PHP/%s', phpversion())
631
+				),
632
+				'attachments' => null,
633
+				'plainMessage' => true,
634
+				'htmlMessage' => true,
635
+			),
636
+			array(
637
+				'expectedHeaders' =>
638
+					"From: [email protected]\r\n" .
639
+					"X-Mailer: PHP/6.0.0\r\n" .
640
+					"Content-type: text/html; charset=\"iso-8859-1\"",
641
+				'headers' => array(
642
+					'From' => '[email protected]',
643
+					'X-Mailer' => sprintf('PHP/%s', phpversion())
644
+				),
645
+				'attachments' => null,
646
+				'plainMessage' => null,
647
+				'htmlMessage' => true,
648
+			),
649
+		);
650
+	}
651
+
652
+	public function testBuildAttachmentContent()
653
+	{
654
+		$textContent = 'Dummy Content';
655
+		$expectedContent = chunk_split(base64_encode($textContent));
656
+
657
+		$path = __DIR__ . '/test.txt';
658
+		$handle = fopen($path, 'w');
659
+		fwrite($handle, $textContent);
660
+		fclose($handle);
661
+
662
+		$archangel = new Archangel();
663
+		$buildMethod = $this->getProtectedMethod('buildAttachmentContent');
664
+		$content = $buildMethod->invokeArgs($archangel, array($path));
665
+
666
+		unlink($path);
667
+		$this->assertEquals($expectedContent, $content);
668
+	}
669
+
670
+	protected function getProtectedProperty($property)
671
+	{
672
+		$reflectedArchangel = new ReflectionClass('Jacobemerick\Archangel\Archangel');
673
+		$reflectedProperty = $reflectedArchangel->getProperty($property);
674
+		$reflectedProperty->setAccessible(true);
675
+
676
+		return $reflectedProperty;
677
+	}
678
+
679
+	protected function getProtectedMethod($method)
680
+	{
681
+		$reflectedArchangel = new ReflectionClass('Jacobemerick\Archangel\Archangel');
682
+		$reflectedMethod = $reflectedArchangel->getMethod($method);
683
+		$reflectedMethod->setAccessible(true);
684
+
685
+		return $reflectedMethod;
686
+	}
687 687
 }
Please login to merge, or discard this patch.