|
1 | 1 | <?php |
2 | 2 |
|
3 | 3 | use DirectoryTree\ImapEngine\Attachment; |
4 | | -use GuzzleHttp\Psr7\LazyOpenStream; |
| 4 | +use GuzzleHttp\Psr7\Utils; |
5 | 5 |
|
6 | 6 | test('extension', function () { |
7 | | - $stream = new LazyOpenStream('test.jpg', 'r'); |
| 7 | + $stream = Utils::streamFor(''); |
8 | 8 |
|
9 | 9 | $ext = (new Attachment('test.jpg', null, 'image/jpeg', 'attachment', $stream))->extension(); |
10 | 10 |
|
11 | 11 | expect($ext)->toBe('jpg'); |
12 | 12 | }); |
13 | 13 |
|
14 | 14 | test('extension with content type', function () { |
15 | | - $stream = new LazyOpenStream('test', 'r'); |
| 15 | + $stream = Utils::streamFor(''); |
16 | 16 |
|
17 | 17 | $ext = (new Attachment('test', null, 'image/jpeg', 'attachment', $stream))->extension(); |
18 | 18 |
|
19 | 19 | expect($ext)->toBe('jpg'); |
20 | 20 | }); |
| 21 | + |
| 22 | +test('contents can be read multiple times', function () { |
| 23 | + $stream = Utils::streamFor('Hello World!'); |
| 24 | + |
| 25 | + $attachment = new Attachment('test.txt', null, 'text/plain', 'attachment', $stream); |
| 26 | + |
| 27 | + expect($attachment->contents())->toBe('Hello World!'); |
| 28 | + expect($attachment->contents())->toBe('Hello World!'); |
| 29 | +}); |
| 30 | + |
| 31 | +test('save writes contents after reading contents', function () { |
| 32 | + $stream = Utils::streamFor('Hello World!'); |
| 33 | + |
| 34 | + $attachment = new Attachment('test.txt', null, 'text/plain', 'attachment', $stream); |
| 35 | + |
| 36 | + $path = tempnam(sys_get_temp_dir(), 'imap-engine-attachment-'); |
| 37 | + |
| 38 | + $attachment->contents(); |
| 39 | + $attachment->save($path); |
| 40 | + |
| 41 | + expect(file_get_contents($path))->toBe('Hello World!'); |
| 42 | + |
| 43 | + unlink($path); |
| 44 | +}); |
0 commit comments