providedPartIsReturned()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 6
nc 1
nop 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