MailResultTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A defaultValuesAreApplied() 0 12 1
A customValuesAreApplied() 0 9 2
A provideResultData() 0 8 1
A exceptionReturnsExpectedValue() 0 7 1
A provideExceptions() 0 7 1
1
<?php
2
declare(strict_types=1);
3
4
namespace AcMailerTest\Result;
5
6
use AcMailer\Model\Email;
7
use AcMailer\Result\MailResult;
8
use AcMailer\Result\ResultInterface;
9
use PHPUnit\Framework\TestCase;
10
11
/**
12
 * Mail result test case
13
 * @author Alejandro Celaya Alastrué
14
 * @link http://www.alejandrocelaya.com
15
 */
16
class MailResultTest extends TestCase
17
{
18
    /**
19
     * @var ResultInterface
20
     */
21
    private $mailResult;
22
23
    /**
24
     * @test
25
     */
26
    public function defaultValuesAreApplied()
27
    {
28
        $email = new Email();
29
30
        $this->mailResult = new MailResult($email);
31
32
        $this->assertTrue($this->mailResult->isValid());
33
        $this->assertFalse($this->mailResult->isCancelled());
34
        $this->assertSame($email, $this->mailResult->getEmail());
35
        $this->assertFalse($this->mailResult->hasException());
36
        $this->assertNull($this->mailResult->getException());
37
    }
38
39
    /**
40
     * @test
41
     * @dataProvider provideResultData
42
     * @param bool $isValid
43
     * @param \Throwable|null $e
44
     */
45
    public function customValuesAreApplied(bool $isValid, \Throwable $e = null)
46
    {
47
        $this->mailResult = new MailResult(new Email(), $isValid, $e);
48
49
        $this->assertEquals($isValid, $this->mailResult->isValid());
50
        $this->assertEquals($e !== null, $this->mailResult->hasException());
51
        $this->assertEquals($e, $this->mailResult->getException());
52
        $this->assertEquals(! $isValid && $e === null, $this->mailResult->isCancelled());
53
    }
54
55
    public function provideResultData(): array
56
    {
57
        return [
58
            [true, null],
59
            [false, null],
60
            [false, new \Exception()],
61
        ];
62
    }
63
64
    /**
65
     * @test
66
     * @dataProvider provideExceptions
67
     * @param bool $hasException
68
     * @param \Throwable|null $e
69
     */
70
    public function exceptionReturnsExpectedValue(bool $hasException, \Throwable $e = null)
71
    {
72
        $this->mailResult = new MailResult(new Email(), false, $e);
73
74
        $this->assertEquals($hasException, $this->mailResult->hasException());
75
        $this->assertEquals($e, $this->mailResult->getException());
76
    }
77
78
    public function provideExceptions(): array
79
    {
80
        return [
81
            [true, new \Exception()],
82
            [false, null],
83
        ];
84
    }
85
}
86