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\ResourceAttachmentParser;
7
use AcMailer\Exception\InvalidAttachmentException;
8
use PHPUnit\Framework\TestCase;
9
use Zend\Mime\Mime;
10
11
class ResourceAttachmentParserTest extends TestCase
12
{
13
    /**
14
     * @var ResourceAttachmentParser
15
     */
16
    private $parser;
17
18
    public function setUp()
19
    {
20
        $this->parser = new ResourceAttachmentParser();
21
    }
22
23
    /**
24
     * @test
25
     */
26
    public function exceptionIsThrownIfAttachmentHasInvalidType()
27
    {
28
        $this->expectException(InvalidAttachmentException::class);
29
        $this->expectExceptionMessage('Provided attachment is not valid. Expected "resource"');
30
        $this->parser->parse('');
31
    }
32
33
    /**
34
     * @param string|null $attachmentName
35
     * @test
36
     * @dataProvider provideAttachmentNames
37
     */
38
    public function providedAttachmentIsParsedIntoPart(string $attachmentName = null)
39
    {
40
        $attachment = fopen(__DIR__ . '/../../attachments/file2', 'r+b');
41
42
        $part = $this->parser->parse($attachment, $attachmentName);
43
44
        $this->assertEquals($part->id, $attachmentName ?? 'file2');
45
        $this->assertEquals($part->filename, $attachmentName ?? 'file2');
46
        $this->assertEquals($part->encoding, Mime::ENCODING_BASE64);
47
        $this->assertEquals($part->disposition, Mime::DISPOSITION_ATTACHMENT);
48
    }
49
50
    public function provideAttachmentNames(): array
51
    {
52
        return [
53
            [null],
54
            ['the_name'],
55
        ];
56
    }
57
}
58