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 DavisPeixoto\BlogCore\Entity\Post; |
14
|
|
|
use DavisPeixoto\BlogCore\Entity\Trail; |
15
|
|
|
use PHPUnit\Framework\TestCase; |
16
|
|
|
use Ramsey\Uuid\Uuid; |
17
|
|
|
|
18
|
|
|
class TestTrail extends TestCase |
19
|
|
|
{ |
20
|
|
|
/** |
21
|
|
|
* @var Trail $trail |
22
|
|
|
*/ |
23
|
|
|
private $trail; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var Post $post1 |
27
|
|
|
*/ |
28
|
|
|
private $post1; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var Post $post2 |
32
|
|
|
*/ |
33
|
|
|
private $post2; |
34
|
|
|
|
35
|
|
|
public function setUp() |
36
|
|
|
{ |
37
|
|
|
$this->post1 = new Post('Post 1', 'Lorem ipsum', new Author( |
38
|
|
|
'Davis', |
39
|
|
|
'[email protected]', |
40
|
|
|
'Some string', |
41
|
|
|
null, |
42
|
|
|
new DateTime() |
43
|
|
|
), null, [], null); |
44
|
|
|
$this->post2 = new Post('Post 2', 'Lorem ipsum', new Author( |
45
|
|
|
'John Doe', |
46
|
|
|
'[email protected]', |
47
|
|
|
'Some string', |
48
|
|
|
Uuid::uuid4()->toString(), |
49
|
|
|
new DateTime() |
50
|
|
|
), null, [], null); |
51
|
|
|
$this->trail = new Trail('A Trail', 'Lorem ipsum sit dolor amet', null, []); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param string|null $uuid |
56
|
|
|
* @param string $name |
57
|
|
|
* @param string $description |
58
|
|
|
* @param Post[] $posts |
59
|
|
|
* @param string $expected |
60
|
|
|
* @param string $message |
61
|
|
|
* @dataProvider trailConstructor |
62
|
|
|
*/ |
63
|
|
|
public function testConstructor($uuid, $name, $description, $posts, $expected, $message) |
64
|
|
|
{ |
65
|
|
|
$post = new Trail($name, $description, $uuid, $posts); |
66
|
|
|
$this->assertInstanceOf($expected, $post, $message); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param Post[] $posts |
71
|
|
|
* @param Post $post |
72
|
|
|
* @param string $expected |
73
|
|
|
* @param string $message |
74
|
|
|
* @dataProvider addPostProvider |
75
|
|
|
*/ |
76
|
|
|
public function testAddPost($posts, $post, $expected, $message) |
77
|
|
|
{ |
78
|
|
|
$this->trail->setPosts($posts); |
79
|
|
|
$this->trail->addPost($post); |
80
|
|
|
$this->assertEquals($expected, $this->trail->getPosts(), $message); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param Post[] $posts |
85
|
|
|
* @param Post $post |
86
|
|
|
* @param string $expected |
87
|
|
|
* @param string $message |
88
|
|
|
* @dataProvider removePostProvider |
89
|
|
|
*/ |
90
|
|
|
public function testRemovePost($posts, $post, $expected, $message) |
91
|
|
|
{ |
92
|
|
|
$this->trail->setPosts($posts); |
93
|
|
|
$this->trail->removePost($post); |
94
|
|
|
$this->assertEquals($expected, $this->trail->getPosts(), $message); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
public function trailConstructor() |
98
|
|
|
{ |
99
|
|
|
$this->setUp(); |
100
|
|
|
|
101
|
|
|
return [ |
102
|
|
|
['', 'A Trail', 'Lorem ipsum sit dolor amet', [], Trail::class, 'no posts'], |
103
|
|
|
[null, 'A Trail', 'Lorem ipsum sit dolor amet', [$this->post1], Trail::class, 'one post'], |
104
|
|
|
[ |
105
|
|
|
Uuid::uuid4()->toString(), |
106
|
|
|
'A Trail', |
107
|
|
|
'Lorem ipsum sit dolor amet', |
108
|
|
|
[$this->post1, $this->post2], |
109
|
|
|
Trail::class, |
110
|
|
|
'more posts', |
111
|
|
|
] |
112
|
|
|
]; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function addPostProvider() |
116
|
|
|
{ |
117
|
|
|
$this->setUp(); |
118
|
|
|
|
119
|
|
|
return [ |
120
|
|
|
[[], $this->post1, [$this->post1], 'positive test, on null, first post added'], |
121
|
|
|
[ |
122
|
|
|
[$this->post1], |
123
|
|
|
$this->post2, |
124
|
|
|
[$this->post1, $this->post2], |
125
|
|
|
'positive test, adding a new post to existing posts vector', |
126
|
|
|
], |
127
|
|
|
[ |
128
|
|
|
[$this->post1, $this->post2], |
129
|
|
|
$this->post1, |
130
|
|
|
[$this->post1, $this->post2], |
131
|
|
|
'negative test, posts should not be duplicated', |
132
|
|
|
] |
133
|
|
|
]; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
public function removePostProvider() |
137
|
|
|
{ |
138
|
|
|
$this->setUp(); |
139
|
|
|
|
140
|
|
|
return [ |
141
|
|
|
[[$this->post1], $this->post1, [], 'positive test, all tags removed'], |
142
|
|
|
[[$this->post1, $this->post2], $this->post1, [$this->post2], 'positive test, removing one tag'], |
143
|
|
|
[[$this->post1], $this->post2, [$this->post1], 'negative test, removing non-existent tag'] |
144
|
|
|
]; |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
|