1 | <?php |
||
11 | class ImapHelperTest extends AbstractTest |
||
12 | { |
||
13 | /** |
||
14 | * @var ImapHelper |
||
15 | */ |
||
16 | private $imapHelper; |
||
17 | |||
18 | /** |
||
19 | * @var array |
||
20 | */ |
||
21 | private $messages = []; |
||
22 | |||
23 | /** |
||
24 | * @param string $name |
||
25 | * @param array $data |
||
26 | * @param string $dataName |
||
27 | */ |
||
28 | public function __construct($name = null, array $data = [], $dataName = '') |
||
35 | |||
36 | |||
37 | /** |
||
38 | * @param int $messageId |
||
39 | * |
||
40 | * @return \PHPUnit_Framework_MockObject_MockObject|\Zend\Mail\Storage\Message |
||
41 | */ |
||
42 | public function createImapStorageMessage($messageId) |
||
43 | { |
||
44 | $messageData = $this->messages[$messageId]; |
||
45 | |||
46 | $message = $this |
||
47 | ->getMockBuilder(Message::class) |
||
48 | ->disableOriginalConstructor() |
||
49 | ->disableOriginalClone() |
||
50 | ->getMock(); |
||
51 | |||
52 | $message |
||
53 | ->expects($this->any()) |
||
54 | ->method('getHeader') |
||
55 | ->will($this->returnCallback(function ($index, $type) use ($messageData) { |
||
56 | if ($type != 'string') { |
||
57 | return null; |
||
58 | } |
||
59 | |||
60 | if ($index == 'subject') { |
||
61 | return utf8_encode($messageData[$index]); |
||
62 | } |
||
63 | |||
64 | return $messageData[$index]; |
||
65 | })); |
||
66 | |||
67 | $message |
||
68 | ->expects($this->any()) |
||
69 | ->method('isMultipart') |
||
70 | ->will($this->returnValue(false)); |
||
71 | |||
72 | $message |
||
73 | ->expects($this->any()) |
||
74 | ->method('getContent') |
||
75 | ->will($this->returnValue($this->messages[$messageId]['plainText'])); |
||
76 | |||
77 | $message |
||
78 | ->expects($this->any()) |
||
79 | ->method('getHeaderField') |
||
80 | ->will($this->returnValue('text/plain')) |
||
81 | ->with($this->equalTo('Content-Type')); |
||
82 | |||
83 | return $message; |
||
84 | } |
||
85 | |||
86 | /** |
||
87 | * This test is only for validating correct decoding of the message (subject/plaintext/received) |
||
88 | */ |
||
89 | public function testMailParse() |
||
90 | { |
||
91 | $imapAdapter = $this->createImapAdapter(); |
||
92 | |||
93 | /** @var \PHPUnit_Framework_MockObject_MockObject|ImapExtension $imapExtension */ |
||
94 | $imapExtension = $imapAdapter->getInstance(); |
||
95 | |||
96 | $imapExtension |
||
97 | ->expects($this->any()) |
||
98 | ->method('search') |
||
99 | ->will($this->returnValue([0])); |
||
100 | |||
101 | $imapExtension |
||
102 | ->expects($this->any()) |
||
103 | ->method('getMessage') |
||
104 | ->will($this->returnValue($this->createImapRawMessage( |
||
105 | base64_decode(file_get_contents(__DIR__.'/data/messages/raw/multipart')) |
||
106 | ))); |
||
107 | |||
108 | $messages = $this->imapHelper->fetchMails($imapAdapter, null, true, true); |
||
109 | $message = $messages[0]; |
||
110 | |||
111 | $this->assertEquals('ORDER #12345678 - CONFIRMATION', $message['subject']); |
||
112 | $this->assertEquals(1404914391, $message['received']); |
||
113 | $this->assertEquals('test'.chr(10).chr(10), $message['plainText']); |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * This test is only for validating correct decoding of the attachments |
||
118 | */ |
||
119 | public function testMailAttachmentParse() |
||
120 | { |
||
121 | $imapAdapter = $this->createImapAdapter(); |
||
122 | |||
123 | /** @var \PHPUnit_Framework_MockObject_MockObject|ImapExtension $imapExtension */ |
||
124 | $imapExtension = $imapAdapter->getInstance(); |
||
125 | |||
126 | $imapExtension |
||
127 | ->expects($this->any()) |
||
128 | ->method('search') |
||
129 | ->will($this->returnValue([0])); |
||
130 | |||
131 | $imapExtension |
||
132 | ->expects($this->any()) |
||
133 | ->method('getMessage') |
||
134 | ->will($this->returnValue($this->createImapRawMessage( |
||
135 | base64_decode(file_get_contents(__DIR__.'/data/messages/raw/with-attachment')) |
||
136 | ))); |
||
137 | |||
138 | $messages = $this->imapHelper->fetchMails($imapAdapter, null, true, true); |
||
139 | $attachment = $messages[0]['attachments'][0]; |
||
140 | |||
141 | $this->assertEquals('application/x-zip-compressed', $attachment['mime']); |
||
142 | $this->assertEquals('finaltest_tobias-nitsche_de.zip', $attachment['filename']); |
||
143 | $this->assertEquals(3962, strlen($attachment['content'])); |
||
144 | } |
||
145 | |||
146 | /** |
||
147 | * test for assuming domain names and ordernumbersof email |
||
148 | */ |
||
149 | public function testMailAssume() |
||
186 | |||
187 | /** |
||
188 | * @param string $raw |
||
189 | * |
||
190 | * @return Message |
||
191 | */ |
||
192 | protected function createImapRawMessage($raw) |
||
196 | } |
||
197 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..