idAndNameAreOverriddenIfNameIsProvided()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 7
nc 1
nop 0
1
<?php
2
declare(strict_types=1);
3
4
namespace AcMailerTest\Attachment\Parser;
5
6
use AcMailer\Attachment\Parser\ArrayAttachmentParser;
7
use AcMailer\Exception\InvalidAttachmentException;
8
use PHPUnit\Framework\TestCase;
9
use Zend\Mime\Mime;
10
11
class ArrayAttachmentParserTest extends TestCase
12
{
13
    /**
14
     * @var ArrayAttachmentParser
15
     */
16
    private $parser;
17
18
    public function setUp()
19
    {
20
        $this->parser = new ArrayAttachmentParser();
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 "array"');
30
        $this->parser->parse('');
31
    }
32
33
    /**
34
     * @test
35
     */
36
    public function providedAttachmentIsParsedIntoPart()
37
    {
38
        $attachment = [
39
            'id' => 'something',
40
            'filename' => 'something_else',
41
            'content' => 'Hello',
42
            'encoding' => Mime::ENCODING_7BIT,
43
        ];
44
45
        $part = $this->parser->parse($attachment);
46
47
        $this->assertEquals($part->id, 'something');
48
        $this->assertEquals($part->filename, 'something_else');
49
        $this->assertEquals($part->getContent(), 'Hello');
50
        $this->assertEquals($part->encoding, Mime::ENCODING_7BIT);
51
        $this->assertEquals($part->disposition, Mime::DISPOSITION_ATTACHMENT);
52
    }
53
54
    /**
55
     * @test
56
     */
57
    public function idAndNameAreOverriddenIfNameIsProvided()
58
    {
59
        $attachment = [
60
            'id' => 'something',
61
            'filename' => 'something_else',
62
        ];
63
64
        $part = $this->parser->parse($attachment, 'the_name');
65
66
        $this->assertEquals($part->id, 'the_name');
67
        $this->assertEquals($part->filename, 'the_name');
68
    }
69
}
70