Passed
Push — master ( 253018...166e4e )
by Davis
38s
created

TestAuthor::constructorException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: davis
5
 * Date: 7/23/17
6
 * Time: 7:25 PM
7
 */
8
9
namespace DavisPeixoto\BlogCore\Tests\Entity;
10
11
use DateTime;
12
use DavisPeixoto\BlogCore\Entity\Author;
13
use PHPUnit\Framework\TestCase;
14
use Ramsey\Uuid\Exception\InvalidUuidStringException;
15
use Ramsey\Uuid\Uuid;
16
17
class TestAuthor extends TestCase
18
{
19
    /**
20
     * @param $uuid
21
     * @param $name
22
     * @param $email
23
     * @param $bio
24
     * @param $birthdate
25
     * @param $expected
26
     * @param $message
27
     * @dataProvider authorConstructorProvider
28
     */
29
    public function testConstructor($uuid, $name, $email, $bio, $birthdate, $expected, $message)
30
    {
31
        $author = new Author($name, $email, $bio, $uuid, $birthdate);
32
        $this->assertInstanceOf($expected, $author, $message);
33
        $this->assertEquals(true, Uuid::isValid($author->getId()));
34
    }
35
36
    /**
37
     * @param $uuid
38
     * @param $name
39
     * @param $email
40
     * @param $bio
41
     * @param $birthdate
42
     * @dataProvider constructorException
43
     */
44
    public function testInvalidId($uuid, $name, $email, $bio, $birthdate)
45
    {
46
        $this->expectException(InvalidUuidStringException::class);
47
        new Author($name, $email, $bio, $uuid, $birthdate);
48
    }
49
50
    /**
51
     * @param Author $author
52
     * @param $newEmailAddress
53
     * @param $expected
54
     * @param $message
55
     * @dataProvider emailProvider
56
     */
57
    public function testEmailShouldBeValid(Author $author, $newEmailAddress, $expected, $message)
58
    {
59
        $author->setEmail($newEmailAddress);
60
        $email = $author->getEmail();
61
        $this->assertEquals($expected, $email, $message);
62
    }
63
64
    public function authorConstructorProvider()
65
    {
66
        return [
67
            [
68
                Uuid::uuid4()->toString(),
69
                'Davis',
70
                '[email protected]',
71
                'Some string',
72
                new DateTime(),
73
                Author::class,
74
                'Regular test',
75
            ],
76
            ['', 'Davis', '[email protected]', 'Some string', new DateTime(), Author::class, 'new author'],
77
            [null, 'Davis', '[email protected]', 'Some string', new DateTime(), Author::class, 'new author'],
78
        ];
79
    }
80
81
    public function constructorException()
82
    {
83
        $uuidv5 = Uuid::uuid5(Uuid::NAMESPACE_DNS, 'bar');
84
85
        return [
86
            ['non-valid-uuid', 'Davis', '[email protected]', 'Some string', new DateTime()],
87
            [$uuidv5->toString(), 'Davis', '[email protected]', 'Some string', new DateTime()],
88
        ];
89
    }
90
91
    public function emailProvider()
92
    {
93
        $author = new Author('Davis', '[email protected]', 'Foo', null, new DateTime());
94
95
        return [
96
            [$author, 'example.org', '[email protected]', 'Negative test'],
97
            [$author, '[email protected]', '[email protected]', 'Positive test'],
98
            [$author, '$#[email protected]$#', '[email protected]', 'Positive test - dirty email']
99
        ];
100
    }
101
}
102