Passed
Pull Request — main (#8)
by Alex
03:11 queued 01:35
created

testGivenAValidEmailAValidVOIsReturned()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 11
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace StraTDeS\VO\Tests\Single;
4
5
use StraTDeS\VO\Single\Email;
6
use PHPUnit\Framework\TestCase;
7
8
class EmailTest extends TestCase
9
{
10
    public function testGivenAValidEmailAValidVOIsReturned(): void
11
    {
12
        // Arrange
13
        $email = "[email protected]";
14
15
        // Act
16
        $emailVO = Email::fromValue($email);
17
18
        // Assert
19
        $this->assertInstanceOf(Email::class, $emailVO);
20
        $this->assertEquals($email, $emailVO->value());
21
    }
22
23
    public function testGivenAnInvalidEmailAnExceptionIsThrown(): void
24
    {
25
        $this->expectException(\InvalidArgumentException::class);
26
        $this->expectExceptionMessage("foo@bar is not a valid email");
27
28
        // Arrange
29
        $email = "foo@bar";
30
31
        // Act
32
        Email::fromValue($email);
33
    }
34
35
    public function testGivenTwoEqualEmailsEqualReturnsTrue(): void
36
    {
37
        // Arrange
38
        $email1 = Email::fromValue("[email protected]");
39
        $email2 = Email::fromValue("[email protected]");
40
41
        // Act
42
        $equal = $email1->equal($email2);
43
44
        // Assert
45
        $this->assertTrue($equal);
46
    }
47
48
    public function testGivenTwoNotEqualEmailsEqualReturnsFalse(): void
49
    {
50
        // Arrange
51
        $email1 = Email::fromValue("[email protected]");
52
        $email2 = Email::fromValue("[email protected]");
53
54
        // Act
55
        $equal = $email1->equal($email2);
56
57
        // Assert
58
        $this->assertFalse($equal);
59
    }
60
}
61