ArrayAttachmentParserTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 3
dl 0
loc 59
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 17 1
A idAndNameAreOverriddenIfNameIsProvided() 0 12 1
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