Test Setup Failed
Pull Request — master (#1)
by Davis
01:54
created

TestPost::publishDateProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
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\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
//            ['X', null, 'Negative Test']
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
103
        ];
104
    }
105
106
    public function addTagProvider()
107
    {
108
        $tag1 = new Tag(Uuid::uuid4(), 'tag 1');
109
110
        return [
111
            [$tag1, [$tag1], 'Positive Test'],
112
            [null, null, 'Negative Test']
113
        ];
114
    }
115
116
    public function removeTagProvider()
117
    {
118
        $tag1 = new Tag(Uuid::uuid4(), 'tag 1');
119
        $tag2 = new Tag(Uuid::uuid4(), 'tag 2');
120
121
        return [
122
            [[$tag1], $tag1, [], 'positive test, all tags removed'],
123
            [[$tag1, $tag2], $tag1, [$tag2], 'positive test, removing one tag'],
124
            [[$tag1], $tag2, [$tag1], 'negative test, removing non-existent tag'],
125
        ];
126
    }
127
}
128