|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
use Flaviozantut\Storage\Posts\FilePostRepository as PostRepository; |
|
4
|
|
|
|
|
5
|
|
|
class FilePostRepositoryTest extends TestCase |
|
|
|
|
|
|
6
|
|
|
{ |
|
7
|
|
|
public function testStore() |
|
8
|
|
|
{ |
|
9
|
|
|
$repository = new PostRepository($this->getFixture('')); |
|
10
|
|
|
$post = $repository->store([ |
|
11
|
|
|
'post' => 'Hello from Skorry post', |
|
12
|
|
|
'type' => 'article', |
|
13
|
|
|
'title' => 'Hello Skorry', |
|
14
|
|
|
'date' => '', |
|
15
|
|
|
'comments' => true, |
|
16
|
|
|
'external_url' => false, |
|
17
|
|
|
'categories' => [''], |
|
18
|
|
|
]); |
|
19
|
|
|
$this->assertStringMatchesFormat('%s', $post); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* @expectedException Exception |
|
24
|
|
|
*/ |
|
25
|
|
|
public function testStoreTitleException() |
|
26
|
|
|
{ |
|
27
|
|
|
$repository = new PostRepository($this->getFixture('')); |
|
28
|
|
|
$post = $repository->store([ |
|
29
|
|
|
'post' => 'Hello from Skorry post', |
|
30
|
|
|
'type' => 'article', |
|
31
|
|
|
'date' => '', |
|
32
|
|
|
'comments' => true, |
|
33
|
|
|
'external_url' => false, |
|
34
|
|
|
'categories' => [''], |
|
35
|
|
|
]); |
|
36
|
|
|
$this->assertTrue($post); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @expectedException Exception |
|
41
|
|
|
*/ |
|
42
|
|
|
public function testStoreException() |
|
43
|
|
|
{ |
|
44
|
|
|
$repository = new PostRepository($this->getFixture('')); |
|
45
|
|
|
$post = $repository->store([ |
|
46
|
|
|
'post' => 'Hello from Skorry post', |
|
47
|
|
|
'type' => 'article', |
|
48
|
|
|
'title' => 'Hello Skorry', |
|
49
|
|
|
'date' => '', |
|
50
|
|
|
'comments' => true, |
|
51
|
|
|
'external_url' => false, |
|
52
|
|
|
'categories' => [''], |
|
53
|
|
|
]); |
|
54
|
|
|
$this->assertTrue($post); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function testGetAll() |
|
58
|
|
|
{ |
|
59
|
|
|
$repository = new PostRepository($this->getFixture('')); |
|
60
|
|
|
$posts = $repository->all(); |
|
61
|
|
|
$this->assertEquals('hello-skorry.md', $posts[0]->id); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function testFind() |
|
65
|
|
|
{ |
|
66
|
|
|
$repository = new PostRepository($this->getFixture('')); |
|
67
|
|
|
$post = $repository->find('hello-skorry.md'); |
|
68
|
|
|
$this->assertEquals('hello-skorry.md', $post->id); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function testFindNotExist() |
|
72
|
|
|
{ |
|
73
|
|
|
$repository = new PostRepository($this->getFixture('')); |
|
74
|
|
|
$post = $repository->find('foo'); |
|
75
|
|
|
$this->assertNull($post); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
public function testUpdate() |
|
79
|
|
|
{ |
|
80
|
|
|
$repository = new PostRepository($this->getFixture('')); |
|
81
|
|
|
$post = $repository->update('hello-skorry.md', [ |
|
82
|
|
|
'post' => 'Hello from Skorry post', |
|
83
|
|
|
'type' => 'article', |
|
84
|
|
|
'title' => 'Hello Skorry', |
|
85
|
|
|
'date' => '', |
|
86
|
|
|
'comments' => true, |
|
87
|
|
|
'external_url' => false, |
|
88
|
|
|
'categories' => [''], |
|
89
|
|
|
]); |
|
90
|
|
|
$this->assertTrue($post); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
/** |
|
94
|
|
|
* @expectedException Exception |
|
95
|
|
|
*/ |
|
96
|
|
|
public function testUpdateNotExist() |
|
97
|
|
|
{ |
|
98
|
|
|
$repository = new PostRepository($this->getFixture('')); |
|
99
|
|
|
$post = $repository->update('not-exist-file.md', [ |
|
100
|
|
|
|
|
101
|
|
|
]); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
public function testDestroy() |
|
105
|
|
|
{ |
|
106
|
|
|
$repository = new PostRepository($this->getFixture('')); |
|
107
|
|
|
$post = $repository->destroy('hello-skorry.md'); |
|
108
|
|
|
$this->assertTrue($post); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* @expectedException Exception |
|
113
|
|
|
*/ |
|
114
|
|
|
public function testDestroyNotExist() |
|
115
|
|
|
{ |
|
116
|
|
|
$repository = new PostRepository($this->getFixture('')); |
|
117
|
|
|
$post = $repository->destroy('not-exist-file.md'); |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.