ResourceAttachmentParserTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 47
c 0
b 0
f 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A exceptionIsThrownIfAttachmentHasInvalidType() 0 6 1
A providedAttachmentIsParsedIntoPart() 0 11 1
A provideAttachmentNames() 0 7 1
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