Passed
Push — main ( a567d8...0d9107 )
by Alex
02:04 queued 37s
created

NameTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
dl 0
loc 51
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testGivenAValidNameAValidVOIsReturned() 0 11 1
A testGivenAnInvalidEmailAnExceptionIsThrown() 0 10 1
A testGivenTwoNotEqualNamesEqualReturnsFalse() 0 11 1
A testGivenTwoEqualNamesEqualReturnsTrue() 0 11 1
1
<?php
2
3
namespace StraTDeS\VO\Tests\Single;
4
5
use StraTDeS\VO\Single\Name;
6
use PHPUnit\Framework\TestCase;
7
8
class NameTest extends TestCase
9
{
10
    public function testGivenAValidNameAValidVOIsReturned(): void
11
    {
12
        // Arrange
13
        $name = "John Smith";
14
15
        // Act
16
        $nameVO = Name::fromValue($name);
17
18
        // Assert
19
        $this->assertInstanceOf(Name::class, $nameVO);
20
        $this->assertEquals($name, $nameVO->value());
21
    }
22
23
    public function testGivenAnInvalidEmailAnExceptionIsThrown(): void
24
    {
25
        $this->expectException(\InvalidArgumentException::class);
26
        $this->expectExceptionMessage("Name value must have at least one character");
27
28
        // Arrange
29
        $name = "";
30
31
        // Act
32
        Name::fromValue($name);
33
    }
34
35
    public function testGivenTwoEqualNamesEqualReturnsTrue(): void
36
    {
37
        // Arrange
38
        $name1 = Name::fromValue("John Smith");
39
        $name2 = Name::fromValue("John Smith");
40
41
        // Act
42
        $equal = $name1->equal($name2);
43
44
        // Assert
45
        $this->assertTrue($equal);
46
    }
47
48
    public function testGivenTwoNotEqualNamesEqualReturnsFalse(): void
49
    {
50
        // Arrange
51
        $name1 = Name::fromValue("John Smith");
52
        $name2 = Name::fromValue("William Wallace");
53
54
        // Act
55
        $equal = $name1->equal($name2);
56
57
        // Assert
58
        $this->assertFalse($equal);
59
    }
60
}
61