exceptionIsThrownIfAttachmentHasInvalidType()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace AcMailerTest\Attachment\Parser;
5
6
use AcMailer\Attachment\Parser\FilePathAttachmentParser;
7
use AcMailer\Exception\InvalidAttachmentException;
8
use PHPUnit\Framework\TestCase;
9
use Prophecy\Prophecy\ObjectProphecy;
10
use Zend\Mime\Mime;
11
12
class FilePathAttachmentParserTest extends TestCase
13
{
14
    /**
15
     * @var FilePathAttachmentParser
16
     */
17
    private $parser;
18
    /**
19
     * @var ObjectProphecy
20
     */
21
    private $finfo;
22
23
    public function setUp()
24
    {
25
        $this->finfo = $this->prophesize(\finfo::class);
26
        $this->parser = new FilePathAttachmentParser($this->finfo->reveal());
27
    }
28
29
    /**
30
     * @test
31
     */
32
    public function exceptionIsThrownIfAttachmentHasInvalidType()
33
    {
34
        $this->expectException(InvalidAttachmentException::class);
35
        $this->expectExceptionMessage('Provided attachment is not valid. Expected "file path"');
36
        $this->parser->parse('');
37
    }
38
39
    /**
40
     * @param string|null $attachmentName
41
     * @test
42
     * @dataProvider provideAttachmentNames
43
     */
44
    public function providedAttachmentIsParsedIntoPart(string $attachmentName = null)
45
    {
46
        $attachment = __DIR__ . '/../../attachments/file1';
47
48
        $getMimeType = $this->finfo->file($attachment)->willReturn('text/plain');
49
50
        $part = $this->parser->parse($attachment, $attachmentName);
51
52
        $this->assertEquals($part->type, 'text/plain');
53
        $this->assertEquals($part->id, $attachmentName ?? \basename($attachment));
54
        $this->assertEquals($part->filename, $attachmentName ?? \basename($attachment));
55
        $this->assertEquals($part->encoding, Mime::ENCODING_BASE64);
56
        $this->assertEquals($part->disposition, Mime::DISPOSITION_ATTACHMENT);
57
        $getMimeType->shouldHaveBeenCalled();
58
    }
59
60
    public function provideAttachmentNames(): array
61
    {
62
        return [
63
            [null],
64
            ['the_name'],
65
        ];
66
    }
67
}
68