Completed
Branch master (7dba2f)
by Alejandro
06:12
created

EmailTest   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 4 1
A setBodyThrowsExceptionIfValueIsNotValid() 0 5 1
A provideInvalidBodies() 0 8 1
A setInvalidAttachmentsThrowsException() 0 5 1
A provideInvalidAttachments() 0 8 1
A providedNamesAreSavedForAttachments() 0 8 1
A attachmentsAreProperlyComputed() 0 13 1
1
<?php
2
declare(strict_types=1);
3
4
namespace AcMailerTest\Model;
5
6
use AcMailer\Exception\InvalidArgumentException;
7
use AcMailer\Model\Email;
8
use PHPUnit\Framework\TestCase;
9
use Zend\Mime\Part;
10
11
class EmailTest extends TestCase
12
{
13
    /**
14
     * @var Email
15
     */
16
    private $email;
17
18
    public function setUp()
19
    {
20
        $this->email = new Email();
21
    }
22
23
    /**
24
     * @param $invalidBody
25
     * @test
26
     * @dataProvider provideInvalidBodies
27
     */
28
    public function setBodyThrowsExceptionIfValueIsNotValid($invalidBody)
29
    {
30
        $this->expectException(InvalidArgumentException::class);
31
        $this->email->setBody($invalidBody);
32
    }
33
34
    public function provideInvalidBodies(): array
35
    {
36
        return [
37
            [null],
38
            [new \stdClass()],
39
            [new \Exception()],
40
        ];
41
    }
42
43
    /**
44
     * @param array $invalidAttachments
45
     * @test
46
     * @dataProvider provideInvalidAttachments
47
     */
48
    public function setInvalidAttachmentsThrowsException(array $invalidAttachments)
49
    {
50
        $this->expectException(InvalidArgumentException::class);
51
        $this->email->setAttachments($invalidAttachments);
52
    }
53
54
    public function provideInvalidAttachments(): array
55
    {
56
        return [
57
            [['foo', null]],
58
            [[new \stdClass()]],
59
            [[new Part(), 5]],
60
        ];
61
    }
62
63
    /**
64
     * @test
65
     */
66
    public function providedNamesAreSavedForAttachments()
67
    {
68
        $this->email->addAttachments([
69
            'foo' => __FILE__,
70
        ]);
71
72
        $this->assertArrayHasKey('foo', $this->email->getAttachments());
73
    }
74
75
    /**
76
     * @test
77
     */
78
    public function attachmentsAreProperlyComputed()
79
    {
80
        $this->email->addAttachment(__DIR__ . '/../attachments/file1');
81
        $this->email->addAttachment(__DIR__ . '/../attachments/file2');
82
        $this->email->setAttachmentsDir([
83
            'path' => __DIR__ . '/../attachments/dir',
84
            'recursive' => true,
85
        ]);
86
87
        $computed = $this->email->getComputedAttachments();
88
89
        $this->assertCount(4, $computed);
90
    }
91
}
92