This repository was archived by the owner on Jan 30, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathMboxInterfaceTest.php
158 lines (124 loc) · 3.94 KB
/
MboxInterfaceTest.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
/**
* Zend Framework (http://framework.zend.com/)
*
* @link http://github.com/zendframework/zf2 for the canonical source repository
* @copyright Copyright (c) 2005-2016 Zend Technologies USA Inc. (http://www.zend.com)
* @license http://framework.zend.com/license/new-bsd New BSD License
*/
namespace ZendTest\Mail\Storage;
use PHPUnit\Framework\TestCase;
use Zend\Mail;
use Zend\Mail\Storage;
use Zend\Mail\Storage\Message;
/**
* @group Zend_Mail
* @covers Zend\Mail\Storage\Mbox<extended>
*/
class MboxInterfaceTest extends TestCase
{
protected $mboxFile;
public function setUp()
{
$this->mboxFile = __DIR__ . '/../_files/test.mbox/INBOX';
}
public function testCount()
{
$list = new Storage\Mbox(['filename' => $this->mboxFile]);
$count = count($list);
$this->assertEquals(7, $count);
}
public function testIsset()
{
$list = new Storage\Mbox(['filename' => $this->mboxFile]);
$this->assertTrue(isset($list[1]));
}
public function testNotIsset()
{
$list = new Storage\Mbox(['filename' => $this->mboxFile]);
$this->assertFalse(isset($list[10]));
}
public function testArrayGet()
{
$list = new Storage\Mbox(['filename' => $this->mboxFile]);
$subject = $list[1]->subject;
$this->assertEquals('Simple Message', $subject);
}
public function testArraySetFail()
{
$list = new Storage\Mbox(['filename' => $this->mboxFile]);
$this->expectException('Zend\Mail\Storage\Exception\RuntimeException');
$list[1] = 'test';
}
public function testIterationKey()
{
$list = new Storage\Mbox(['filename' => $this->mboxFile]);
$pos = 1;
foreach ($list as $key => $message) {
$this->assertEquals($key, $pos, "wrong key in iteration $pos");
++$pos;
}
}
public function testIterationIsMessage()
{
$list = new Storage\Mbox(['filename' => $this->mboxFile]);
foreach ($list as $key => $message) {
$this->assertInstanceOf(
'Zend\Mail\Storage\Message\MessageInterface',
$message,
'value in iteration is not a mail message'
);
}
}
public function testIterationRounds()
{
$list = new Storage\Mbox(['filename' => $this->mboxFile]);
$count = 0;
foreach ($list as $key => $message) {
++$count;
}
$this->assertEquals(7, $count);
}
public function testIterationWithSeek()
{
$list = new Storage\Mbox(['filename' => $this->mboxFile]);
$count = 0;
foreach (new \LimitIterator($list, 1, 3) as $key => $message) {
++$count;
}
$this->assertEquals(3, $count);
}
public function testIterationWithSeekCapped()
{
$list = new Storage\Mbox(['filename' => $this->mboxFile]);
$count = 0;
foreach (new \LimitIterator($list, 3, 7) as $key => $message) {
++$count;
}
$this->assertEquals(5, $count);
}
public function testFallback()
{
$list = new Storage\Mbox(['filename' => $this->mboxFile]);
$result = $list->noop();
$this->assertTrue($result);
}
public function testWrongVariable()
{
$list = new Storage\Mbox(['filename' => $this->mboxFile]);
$this->expectException('Zend\Mail\Storage\Exception\InvalidArgumentException');
$list->thisdoesnotexist;
}
public function testGetHeaders()
{
$list = new Storage\Mbox(['filename' => $this->mboxFile]);
$headers = $list[1]->getHeaders();
$this->assertNotEmpty($headers);
}
public function testWrongHeader()
{
$list = new Storage\Mbox(['filename' => $this->mboxFile]);
$this->expectException('Zend\Mail\Storage\Exception\InvalidArgumentException');
$list[1]->thisdoesnotexist;
}
}