Passed
Push — master ( 72d47d...8357d2 )
by Aimeos
13:03 queued 05:09
created

SwiftTest::tearDown()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2014-2022
6
 */
7
8
9
namespace Aimeos\Base\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\Base\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\Base\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 testFrom()
48
	{
49
		$this->mock->expects( $this->once() )->method( 'addFrom' )
50
			->with( $this->stringContains( 'a@b' ), $this->stringContains( 'test' ) );
51
52
		$result = $this->object->from( 'a@b', 'test' );
53
		$this->assertSame( $this->object, $result );
54
	}
55
56
57
	public function testTo()
58
	{
59
		$this->mock->expects( $this->once() )->method( 'addTo' )
60
			->with( $this->stringContains( 'a@b' ), $this->stringContains( 'test' ) );
61
62
		$result = $this->object->to( 'a@b', 'test' );
63
		$this->assertSame( $this->object, $result );
64
	}
65
66
67
	public function testCc()
68
	{
69
		$this->mock->expects( $this->once() )->method( 'addCc' )
70
			->with( $this->stringContains( 'a@b' ), $this->stringContains( 'test' ) );
71
72
		$result = $this->object->cc( 'a@b', 'test' );
73
		$this->assertSame( $this->object, $result );
74
	}
75
76
77
	public function testBcc()
78
	{
79
		$this->mock->expects( $this->once() )->method( 'addBcc' )
80
			->with( $this->stringContains( 'a@b' ) );
81
82
		$result = $this->object->bcc( 'a@b' );
83
		$this->assertSame( $this->object, $result );
84
	}
85
86
87
	public function testReplyTo()
88
	{
89
		$this->mock->expects( $this->once() )->method( 'addReplyTo' )
90
			->with( $this->stringContains( 'a@b' ), $this->stringContains( 'test' ) );
91
92
		$result = $this->object->replyTo( 'a@b', 'test' );
93
		$this->assertSame( $this->object, $result );
94
	}
95
96
97
	public function testHeader()
98
	{
99
		$result = $this->object->header( '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 testSender()
112
	{
113
		$this->mock->expects( $this->once() )->method( 'setSender' )
114
			->with( $this->stringContains( 'a@b' ), $this->stringContains( 'test' ) );
115
116
		$result = $this->object->sender( 'a@b', 'test' );
117
		$this->assertSame( $this->object, $result );
118
	}
119
120
121
	public function testSubject()
122
	{
123
		$this->mock->expects( $this->once() )->method( 'setSubject' )
124
			->with( $this->stringContains( 'test' ) );
125
126
		$result = $this->object->subject( 'test' );
127
		$this->assertSame( $this->object, $result );
128
	}
129
130
131
	public function testText()
132
	{
133
		$this->mock->expects( $this->once() )->method( 'addPart' )
134
			->with( $this->stringContains( 'test' ) );
135
136
		$result = $this->object->text( 'test' );
137
		$this->assertSame( $this->object, $result );
138
	}
139
140
141
	public function testHtml()
142
	{
143
		$this->mock->expects( $this->once() )->method( 'setBody' )
144
			->with( $this->stringContains( 'test' ) );
145
146
		$result = $this->object->html( 'test' );
147
		$this->assertSame( $this->object, $result );
148
	}
149
150
151
	public function testAttach()
152
	{
153
		$this->markTestIncomplete( 'Swift_Attachment::newInstance() cannot be tested' );
154
	}
155
156
157
	public function testEmbed()
158
	{
159
		$this->markTestIncomplete( 'Swift_EmbeddedFile::newInstance() cannot be tested' );
160
	}
161
162
163
	public function testObject()
164
	{
165
		$this->assertInstanceOf( 'Swift_Message', $this->object->object() );
166
	}
167
168
169
	public function testClone()
170
	{
171
		$result = clone $this->object;
172
		$this->assertInstanceOf( '\\Aimeos\\Base\\Mail\\Message\\Iface', $result );
173
	}
174
}
175