Skip to content

Commit bd21e74

Browse files
committed
More tests
1 parent b525cf8 commit bd21e74

File tree

7 files changed

+221
-0
lines changed

7 files changed

+221
-0
lines changed

tests/AttachmentTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
use DirectoryTree\ImapEngine\Attachment;
4+
use GuzzleHttp\Psr7\LazyOpenStream;
5+
6+
test('extension', function () {
7+
$stream = new LazyOpenStream('test.jpg', 'r');
8+
9+
$ext = (new Attachment('test.jpg', 'image/jpeg', $stream))->extension();
10+
11+
expect($ext)->toBe('jpg');
12+
});
13+
14+
test('extension with content type', function () {
15+
$stream = new LazyOpenStream('test', 'r');
16+
17+
$ext = (new Attachment('test', 'image/jpeg', $stream))->extension();
18+
19+
expect($ext)->toBe('jpg');
20+
});
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
use DirectoryTree\ImapEngine\Connection\Responses\ContinuationResponse;
4+
use DirectoryTree\ImapEngine\Connection\Tokens\Atom;
5+
6+
test('data', function () {
7+
$response = new ContinuationResponse([
8+
new Atom('a'),
9+
new Atom('b'),
10+
new Atom('c'),
11+
]);
12+
13+
expect($response->data())->toEqual([
14+
new Atom('b'),
15+
new Atom('c'),
16+
]);
17+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
use DirectoryTree\ImapEngine\Connection\Responses\Data\ListData;
4+
use DirectoryTree\ImapEngine\Connection\Tokens\Atom;
5+
6+
test('toString', function () {
7+
$response = new ListData([
8+
new Atom('a'),
9+
new Atom('b'),
10+
new Atom('c'),
11+
]);
12+
13+
expect((string) $response)->toEqual('(a b c)');
14+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
use DirectoryTree\ImapEngine\Connection\Responses\Data\ResponseCodeData;
4+
use DirectoryTree\ImapEngine\Connection\Tokens\Atom;
5+
6+
test('toString', function () {
7+
$response = new ResponseCodeData([
8+
new Atom('a'),
9+
new Atom('b'),
10+
new Atom('c'),
11+
]);
12+
13+
expect((string) $response)->toEqual('[a b c]');
14+
});
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<?php
2+
3+
use DirectoryTree\ImapEngine\Connection\Responses\Response;
4+
use DirectoryTree\ImapEngine\Connection\Tokens\Atom;
5+
6+
test('tokens', function () {
7+
$response = new Response([
8+
new Atom('a'),
9+
new Atom('b'),
10+
new Atom('c'),
11+
]);
12+
13+
expect($response->tokens())->toEqual([
14+
new Atom('a'),
15+
new Atom('b'),
16+
new Atom('c'),
17+
]);
18+
});
19+
20+
test('toArray', function () {
21+
$response = new Response([
22+
new Atom('a'),
23+
new Atom('b'),
24+
new Atom('c'),
25+
]);
26+
27+
expect($response->toArray())->toEqual([
28+
'a',
29+
'b',
30+
'c',
31+
]);
32+
});
33+
34+
test('toString', function () {
35+
$response = new Response([
36+
new Atom('a'),
37+
new Atom('b'),
38+
new Atom('c'),
39+
]);
40+
41+
expect($response->__toString())->toEqual('a b c');
42+
});
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
<?php
2+
3+
use DirectoryTree\ImapEngine\Connection\Responses\TaggedResponse;
4+
use DirectoryTree\ImapEngine\Connection\Tokens\Atom;
5+
6+
test('tag', function () {
7+
$response = new TaggedResponse([
8+
new Atom('a'),
9+
new Atom('b'),
10+
new Atom('c'),
11+
]);
12+
13+
expect($response->tag())->toEqual(
14+
new Atom('a')
15+
);
16+
});
17+
18+
test('status', function () {
19+
$response = new TaggedResponse([
20+
new Atom('a'),
21+
new Atom('b'),
22+
new Atom('c'),
23+
]);
24+
25+
expect($response->status())->toEqual([
26+
new Atom('b'),
27+
]);
28+
});
29+
30+
test('data', function () {
31+
$response = new TaggedResponse([
32+
new Atom('a'),
33+
new Atom('b'),
34+
new Atom('c'),
35+
]);
36+
37+
expect($response->data())->toEqual([
38+
new Atom('c'),
39+
]);
40+
});
41+
42+
test('successful', function () {
43+
$response = new TaggedResponse([
44+
new Atom('a'),
45+
new Atom('OK'),
46+
]);
47+
48+
expect($response->successful())->toBeTrue();
49+
50+
$response = new TaggedResponse([
51+
new Atom('a'),
52+
new Atom('NO'),
53+
]);
54+
55+
expect($response->successful())->toBeFalse();
56+
57+
$response = new TaggedResponse([
58+
new Atom('a'),
59+
new Atom('BAD'),
60+
]);
61+
62+
expect($response->successful())->toBeFalse();
63+
});
64+
65+
test('failed', function () {
66+
$response = new TaggedResponse([
67+
new Atom('a'),
68+
new Atom('OK'),
69+
]);
70+
71+
expect($response->failed())->toBeFalse();
72+
73+
$response = new TaggedResponse([
74+
new Atom('a'),
75+
new Atom('NO'),
76+
]);
77+
78+
expect($response->failed())->toBeTrue();
79+
80+
$response = new TaggedResponse([
81+
new Atom('a'),
82+
new Atom('BAD'),
83+
]);
84+
85+
expect($response->failed())->toBeTrue();
86+
});
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
use DirectoryTree\ImapEngine\Connection\Responses\UntaggedResponse;
4+
use DirectoryTree\ImapEngine\Connection\Tokens\Atom;
5+
6+
test('type', function () {
7+
$response = new UntaggedResponse([
8+
new Atom('a'),
9+
new Atom('b'),
10+
new Atom('c'),
11+
]);
12+
13+
expect($response->type())->toEqual(
14+
new Atom('b')
15+
);
16+
});
17+
18+
test('data', function () {
19+
$response = new UntaggedResponse([
20+
new Atom('a'),
21+
new Atom('b'),
22+
new Atom('c'),
23+
]);
24+
25+
expect($response->data())->toEqual([
26+
new Atom('c'),
27+
]);
28+
});

0 commit comments

Comments
 (0)