FilePostRepositoryTest   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 115
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2
Metric Value
wmc 10
lcom 1
cbo 2
dl 0
loc 115
rs 10

10 Methods

Rating   Name   Duplication   Size   Complexity  
A testStore() 0 14 1
A testStoreTitleException() 0 13 1
A testStoreException() 0 14 1
A testGetAll() 0 6 1
A testFind() 0 6 1
A testFindNotExist() 0 6 1
A testUpdate() 0 14 1
A testUpdateNotExist() 0 7 1
A testDestroy() 0 6 1
A testDestroyNotExist() 0 5 1
1
<?php
2
3
use Flaviozantut\Storage\Posts\FilePostRepository as PostRepository;
4
5
class FilePostRepositoryTest extends TestCase
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
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