-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathPhpMailerTest.php
99 lines (81 loc) · 2.44 KB
/
PhpMailerTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
*
* This file is part of the Apix Project.
*
* (c) Franck Cassedanne <franck at ouarz.net>
*
* @license http://opensource.org/licenses/BSD-3-Clause New BSD License
*
*/
namespace Apix\Log\Logger;
use PHPUnit\Framework\TestCase;
class PhpMailerTest extends TestCase
{
protected $mailer;
protected function setUp()
{
$mail = new \PHPMailer\PHPMailer\PHPMailer(true);
$mail->addAddress('[email protected]', 'Log Mailbox');
$mail->setFrom('[email protected]', 'My App');
$mail->isSMTP();
$mail->SMTPAuth = true;
$mail->Host = 'tls://mail.example.com:587';
$mail->Username = 'user';
$mail->Password = 'pass';
$mail->isHTML(false);
$mail->Subject = 'Error log';
$this->mailer = $mail;
}
protected function tearDown()
{
unset($this->mailer);
}
/**
* @expectedException Psr\Log\InvalidArgumentException
* @expectedExceptionMessage Must be an instance of \PHPMailer
*/
public function testThrowsInvalidArgumentExceptionWhenNull()
{
new PhpMailer(null);
}
/**
* @expectedException Psr\Log\InvalidArgumentException
* @expectedExceptionMessage Must be an instance of \PHPMailer
*/
public function testThrowsInvalidArgumentExceptionWhenWrongInstance()
{
new PhpMailer(new \stdClass());
}
/**
* @expectedException Psr\Log\InvalidArgumentException
* @expectedExceptionMessage No valid email address set in PHPMailer
*/
public function testThrowsInvalidArgumentExceptionWhenNoValidEmail()
{
new PhpMailer(new \PHPMailer\PHPMailer\PHPMailer);
}
public function testConstructor()
{
new PhpMailer($this->mailer);
}
/**
* @expectedException Apix\Log\Exception
* This test relies on the mailer not being usable - for example that it uses an unreachable host
*/
public function testThrowsExceptionOnPhpMailerError()
{
$logger = new PhpMailer($this->mailer);
$logger->info("Log me!");
}
public function testWriteIsCalled()
{
$mock = $this->getMockBuilder('Apix\Log\Logger\PhpMailer')
->disableOriginalConstructor()
->setMethods(array('write'))
->getMock();
$mock->expects($this->exactly(2))->method('write');
$mock->info('Log me!');
$mock->error('Log me too!');
}
}