MimePartAttachmentParserTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A exceptionIsThrownIfAttachmentHasInvalidType() 0 8 1
A providedPartIsReturned() 0 10 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\MimePartAttachmentParser;
7
use AcMailer\Exception\InvalidAttachmentException;
8
use PHPUnit\Framework\TestCase;
9
use Zend\Mime\Part;
10
11
class MimePartAttachmentParserTest extends TestCase
12
{
13
    /**
14
     * @var MimePartAttachmentParser
15
     */
16
    private $parser;
17
18
    public function setUp()
19
    {
20
        $this->parser = new MimePartAttachmentParser();
21
    }
22
23
    /**
24
     * @test
25
     */
26
    public function exceptionIsThrownIfAttachmentHasInvalidType()
27
    {
28
        $this->expectException(InvalidAttachmentException::class);
29
        $this->expectExceptionMessage(
30
            \sprintf('Provided attachment is not valid. Expected "%s"', Part::class)
31
        );
32
        $this->parser->parse('');
33
    }
34
35
    /**
36
     * @param string|null $attachmentName
37
     * @test
38
     * @dataProvider provideAttachmentNames
39
     */
40
    public function providedPartIsReturned(string $attachmentName = null)
41
    {
42
        $part = new Part();
43
44
        $result = $this->parser->parse($part, $attachmentName);
45
46
        $this->assertSame($part, $result);
47
        $this->assertEquals($part->id, $attachmentName);
48
        $this->assertEquals($part->filename, $attachmentName);
49
    }
50
51
    public function provideAttachmentNames(): array
52
    {
53
        return [
54
            [null],
55
            ['the_name'],
56
        ];
57
    }
58
}
59