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