1
|
|
|
<?php |
2
|
|
|
namespace Redaxscript\Tests; |
3
|
|
|
|
4
|
|
|
use org\bovigo\vfs\vfsStream as Stream; |
5
|
|
|
use org\bovigo\vfs\vfsStreamFile as StreamFile; |
6
|
|
|
use org\bovigo\vfs\vfsStreamWrapper as StreamWrapper; |
7
|
|
|
use Redaxscript\Mailer; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* MailerTest |
11
|
|
|
* |
12
|
|
|
* @since 2.2.0 |
13
|
|
|
* |
14
|
|
|
* @package Redaxscript |
15
|
|
|
* @category Tests |
16
|
|
|
* @author Henry Ruhs |
17
|
|
|
* |
18
|
|
|
* @covers Redaxscript\Mailer |
19
|
|
|
* |
20
|
|
|
* @requires OS Linux |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
class MailerTest extends TestCaseAbstract |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* setUp |
27
|
|
|
* |
28
|
|
|
* @since 3.1.0 |
29
|
|
|
*/ |
30
|
|
|
|
31
|
|
|
public function setUp() : void |
32
|
|
|
{ |
33
|
|
|
parent::setUp(); |
34
|
|
|
$optionArray = $this->getOptionArray(); |
35
|
|
|
$installer = $this->installerFactory(); |
36
|
|
|
$installer->init(); |
37
|
|
|
$installer->rawCreate(); |
38
|
|
|
$installer->insertSettings($optionArray); |
39
|
|
|
Stream::setup('root'); |
40
|
|
|
$file = new StreamFile('attachment.zip'); |
41
|
|
|
StreamWrapper::getRoot()->addChild($file); |
|
|
|
|
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* tearDown |
46
|
|
|
* |
47
|
|
|
* @since 3.1.0 |
48
|
|
|
*/ |
49
|
|
|
|
50
|
|
|
public function tearDown() : void |
51
|
|
|
{ |
52
|
|
|
$this->dropDatabase(); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* testSend |
57
|
|
|
* |
58
|
|
|
* @since 2.2.0 |
59
|
|
|
* |
60
|
|
|
* @param array $toArray |
61
|
|
|
* @param array $fromArray |
62
|
|
|
* @param string $subject |
63
|
|
|
* @param string|array $body |
64
|
|
|
* |
65
|
|
|
* @dataProvider providerAutoloader |
66
|
|
|
*/ |
67
|
|
|
|
68
|
|
|
public function testSend(array $toArray = [], array $fromArray = [], string $subject = null, $body = null) : void |
69
|
|
|
{ |
70
|
|
|
/* setup */ |
71
|
|
|
|
72
|
|
|
$mailer = new Mailer(); |
73
|
|
|
$mailer->init($toArray, $fromArray, $subject, $body); |
74
|
|
|
|
75
|
|
|
/* actual */ |
76
|
|
|
|
77
|
|
|
$actual = $mailer->send(); |
78
|
|
|
|
79
|
|
|
/* compare */ |
80
|
|
|
|
81
|
|
|
$this->assertTrue($actual); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* testSendAttachment |
86
|
|
|
* |
87
|
|
|
* @since 3.1.0 |
88
|
|
|
* |
89
|
|
|
* @param array $toArray |
90
|
|
|
* @param array $fromArray |
91
|
|
|
* @param string $subject |
92
|
|
|
* @param string|array $body |
93
|
|
|
* |
94
|
|
|
* @requires OS Linux |
95
|
|
|
* |
96
|
|
|
* @dataProvider providerAutoloader |
97
|
|
|
*/ |
98
|
|
|
|
99
|
|
|
public function testSendAttachment(array $toArray = [], array $fromArray = [], string $subject = null, $body = null) : void |
100
|
|
|
{ |
101
|
|
|
/* setup */ |
102
|
|
|
|
103
|
|
|
$attachmentArray = |
104
|
|
|
[ |
105
|
|
|
Stream::url('root' . DIRECTORY_SEPARATOR . 'attachment.zip') |
106
|
|
|
]; |
107
|
|
|
$mailer = new Mailer(); |
108
|
|
|
$mailer->init($toArray, $fromArray, $subject, $body, $attachmentArray); |
109
|
|
|
|
110
|
|
|
/* actual */ |
111
|
|
|
|
112
|
|
|
$actual = $mailer->send(); |
113
|
|
|
|
114
|
|
|
/* compare */ |
115
|
|
|
|
116
|
|
|
$this->assertTrue($actual); |
117
|
|
|
} |
118
|
|
|
} |
119
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: