Test Setup Failed
Pull Request — master (#1)
by Davis
02:38
created

TestPost::postConstructor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 9
rs 9.6666
c 1
b 0
f 0
cc 1
eloc 6
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\Post;
13
use DavisPeixoto\BlogCore\Entity\Author;
14
use DavisPeixoto\BlogCore\Entity\Tag;
15
use PHPUnit_Framework_TestCase;
16
use Ramsey\Uuid\Uuid;
17
18
class TestPost extends PHPUnit_Framework_TestCase
19
{
20
    /**
21
     * @Post $post
22
     */
23
    private $post;
24
25
    public function setUp()
26
    {
27
        $this->post = new Post(Uuid::uuid4(), 'A Post', 'Lorem ipsum', new Author(Uuid::uuid4(), 'Davis', '[email protected]', 'Some string', new DateTime()), [], null);
28
    }
29
30
    /**
31
     * @param $uuid
32
     * @param $title
33
     * @param $body
34
     * @param $author
35
     * @param $tags
36
     * @param $publishDate
37
     * @param $expected
38
     * @param $message
39
     * @dataProvider postConstructor
40
     */
41
    public function testConstructor($uuid, $title, $body, $author, $tags, $publishDate, $expected, $message)
42
    {
43
        $post = new Post($uuid, $title, $body, $author, $tags, $publishDate);
44
        $this->assertInstanceOf($expected, $post, $message);
45
    }
46
47
    /**
48
     * @param $date
49
     * @param $expected
50
     * @param $message
51
     * @dataProvider publishDateProvider
52
     */
53
    public function testPublishDates($date, $expected, $message)
54
    {
55
        $this->post->setPublishDate($date);
56
        $this->assertEquals($expected, $this->post->getPublishDate(), $message);
57
    }
58
59
    /**
60
     * @param $tag
61
     * @param $expected
62
     * @param $message
63
     * @dataProvider addTagProvider
64
     */
65
    public function testAddTag($tag, $expected, $message)
66
    {
67
        $this->post->addTag($tag);
68
        $this->assertEquals($expected, $this->post->getTags(), $message);
69
    }
70
71
    /**
72
     * @param $tags
73
     * @param $tag
74
     * @param $expected
75
     * @param $message
76
     * @dataProvider removeTagProvider
77
     */
78
    public function testRemoveTag($tags, $tag, $expected, $message)
79
    {
80
        $this->post->setTags($tags);
81
        $this->post->removeTag($tag);
82
        $this->assertEquals($expected, $this->post->getTags(), $message);
83
    }
84
85
    public function postConstructor()
86
    {
87
        return [
88
            [Uuid::uuid4(), 'A Post', 'Lorem ipsum', new Author(Uuid::uuid4(), 'Davis', '[email protected]', 'Some string', new DateTime()), [], null, Post::class, 'no tags, no publish date'],
89
            [Uuid::uuid4(), 'A Post', 'Lorem ipsum', new Author(Uuid::uuid4(), 'Davis', '[email protected]', 'Some string', new DateTime()), [new Tag(Uuid::uuid4(),'tag1'), new Tag(Uuid::uuid4(),'tag2')], null, Post::class, 'have tags, unpublished'],
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 200 characters; contains 250 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
90
            [Uuid::uuid4(), 'A Post', 'Lorem ipsum', new Author(Uuid::uuid4(), 'Davis', '[email protected]', 'Some string', new DateTime()), [], new DateTime(), Post::class, 'no tags, published'],
91
            [Uuid::uuid4(), 'A Post', 'Lorem ipsum', new Author(Uuid::uuid4(), 'Davis', '[email protected]', 'Some string', new DateTime()), [new Tag(Uuid::uuid4(),'tag1'), new Tag(Uuid::uuid4(),'tag2')], new DateTime(), Post::class, 'tags, published (most common scenario)']
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 200 characters; contains 275 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
92
        ];
93
    }
94
95
    public function publishDateProvider()
96
    {
97
        $date1 = new DateTime();
98
99
        return [
100
            [null, null, 'Null test'],
101
            [$date1, $date1, 'Positive test']
102
        ];
103
    }
104
105
    public function addTagProvider()
106
    {
107
        return [
108
            [],
109
        ];
110
    }
111
112
    public function removeTagProvider()
113
    {
114
        return [
115
            [],
116
        ];
117
    }
118
}
119