Passed
Push — master ( b328f8...27b7aa )
by Aimeos
02:15
created

SwiftTest::testSend()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
c 0
b 0
f 0
dl 0
loc 4
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2014-2020
6
 */
7
8
9
namespace Aimeos\MW\Mail\Message;
10
11
12
class SwiftTest extends \PHPUnit\Framework\TestCase
13
{
14
	private $object;
15
	private $mailer;
16
	private $mock;
17
18
19
	protected function setUp() : void
20
	{
21
		if( class_exists( 'Swift_Message' ) === false ) {
22
			$this->markTestSkipped( 'Class Swift_Message not found' );
23
		}
24
25
		$this->mailer = $this->getMockBuilder( '\Aimeos\MW\Mail\Swift' )
26
			->disableOriginalConstructor()
27
			->setMethods( ['send'] )
28
			->getMock();
29
30
		$this->mock = $this->getMockBuilder( 'Swift_Message' )
31
			->setMethods( [
32
				'addFrom', 'addTo', 'addCc', 'addBcc',
33
				'addReplyTo', 'addTextHeader', 'setSender',
34
				'setSubject', 'setBody', 'addPart'
35
			] )->getMock();
36
37
		$this->object = new \Aimeos\MW\Mail\Message\Swift( $this->mailer, $this->mock, 'UTF-8' );
38
	}
39
40
41
	protected function tearDown() : void
42
	{
43
		unset( $this->object, $this->mailer );
44
	}
45
46
47
	public function testAddFrom()
48
	{
49
		$this->mock->expects( $this->once() )->method( 'addFrom' )
50
			->with( $this->stringContains( 'a@b' ), $this->stringContains( 'test' ) );
51
52
		$result = $this->object->addFrom( 'a@b', 'test' );
53
		$this->assertSame( $this->object, $result );
54
	}
55
56
57
	public function testAddTo()
58
	{
59
		$this->mock->expects( $this->once() )->method( 'addTo' )
60
			->with( $this->stringContains( 'a@b' ), $this->stringContains( 'test' ) );
61
62
		$result = $this->object->addTo( 'a@b', 'test' );
63
		$this->assertSame( $this->object, $result );
64
	}
65
66
67
	public function testAddCc()
68
	{
69
		$this->mock->expects( $this->once() )->method( 'addCc' )
70
			->with( $this->stringContains( 'a@b' ), $this->stringContains( 'test' ) );
71
72
		$result = $this->object->addCc( 'a@b', 'test' );
73
		$this->assertSame( $this->object, $result );
74
	}
75
76
77
	public function testAddBcc()
78
	{
79
		$this->mock->expects( $this->once() )->method( 'addBcc' )
80
			->with( $this->stringContains( 'a@b' ), $this->stringContains( 'test' ) );
81
82
		$result = $this->object->addBcc( 'a@b', 'test' );
83
		$this->assertSame( $this->object, $result );
84
	}
85
86
87
	public function testAddReplyTo()
88
	{
89
		$this->mock->expects( $this->once() )->method( 'addReplyTo' )
90
			->with( $this->stringContains( 'a@b' ), $this->stringContains( 'test' ) );
91
92
		$result = $this->object->addReplyTo( 'a@b', 'test' );
93
		$this->assertSame( $this->object, $result );
94
	}
95
96
97
	public function testAddHeader()
98
	{
99
		$result = $this->object->addHeader( 'test', 'value' );
100
		$this->assertSame( $this->object, $result );
101
	}
102
103
104
	public function testSend()
105
	{
106
		$this->mailer->expects( $this->once() )->method( 'send' );
107
		$this->assertSame( $this->object, $this->object->send() );
108
	}
109
110
111
	public function testSetSender()
112
	{
113
		$this->mock->expects( $this->once() )->method( 'setSender' )
114
			->with( $this->stringContains( 'a@b' ), $this->stringContains( 'test' ) );
115
116
		$result = $this->object->setSender( 'a@b', 'test' );
117
		$this->assertSame( $this->object, $result );
118
	}
119
120
121
	public function testSetSubject()
122
	{
123
		$this->mock->expects( $this->once() )->method( 'setSubject' )
124
			->with( $this->stringContains( 'test' ) );
125
126
		$result = $this->object->setSubject( 'test' );
127
		$this->assertSame( $this->object, $result );
128
	}
129
130
131
	public function testSetBody()
132
	{
133
		$this->mock->expects( $this->once() )->method( 'addPart' )
134
			->with( $this->stringContains( 'test' ) );
135
136
		$result = $this->object->setBody( 'test' );
137
		$this->assertSame( $this->object, $result );
138
	}
139
140
141
	public function testSetBodyHtml()
142
	{
143
		$this->mock->expects( $this->once() )->method( 'setBody' )
144
			->with( $this->stringContains( 'test' ) );
145
146
		$result = $this->object->setBodyHtml( 'test' );
147
		$this->assertSame( $this->object, $result );
148
	}
149
150
151
	public function testAddAttachment()
152
	{
153
		$this->markTestIncomplete( 'Swift_Attachment::newInstance() cannot be tested' );
154
	}
155
156
157
	public function testEmbedAttachment()
158
	{
159
		$this->markTestIncomplete( 'Swift_EmbeddedFile::newInstance() cannot be tested' );
160
	}
161
162
163
	public function testGetObject()
164
	{
165
		$this->assertInstanceOf( 'Swift_Message', $this->object->getObject() );
166
	}
167
168
169
	public function testClone()
170
	{
171
		$result = clone $this->object;
172
		$this->assertInstanceOf( '\\Aimeos\\MW\\Mail\\Message\\Iface', $result );
173
	}
174
}
175