Completed
Push — master ( dfede2...367c5a )
by Martin
03:32
created

FrontMatterTest::testParseYaml()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 9
Ratio 100 %

Importance

Changes 0
Metric Value
dl 9
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 3
1
<?php
2
3
/*
4
 * This is part of the webuni/front-matter package.
5
 *
6
 * (c) Martin Hasoň <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Webuni\FrontMatter\Tests;
13
14
use Webuni\FrontMatter\Document;
15
use Webuni\FrontMatter\FrontMatter;
16
use Webuni\FrontMatter\Processor\JsonProcessor;
17
18
class FrontMatterTest extends \PHPUnit_Framework_TestCase
19
{
20
    /**
21
     * @dataProvider getYaml
22
     */
23 View Code Duplication
    public function testParseYaml($string, $data, $content)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
24
    {
25
        $frontMatter = new FrontMatter();
26
        $document = $frontMatter->parse($string);
27
28
        $this->assertInstanceOf(Document::class, $document);
29
        $this->assertEquals($data, $document->getData());
30
        $this->assertEquals($content, $document->getContent());
31
    }
32
33
    /**
34
     * @dataProvider getYaml
35
     */
36 View Code Duplication
    public function testDumpYaml($string, $data, $content)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37
    {
38
        $frontMatter = new FrontMatter();
39
        $document = new Document($content, $data);
40
41
        $this->assertEquals($string, $frontMatter->dump($document));
42
    }
43
44
    /**
45
     * @dataProvider getSeparator
46
     */
47 View Code Duplication
    public function testParseYamlWithCustomSeparator($string, $data, $content)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
    {
49
        $frontMatter = new FrontMatter(null, '<!--', '-->');
50
        $document = $frontMatter->parse($string);
51
52
        $this->assertInstanceOf(Document::class, $document);
53
        $this->assertEquals($data, $document->getData());
54
        $this->assertEquals($content, $document->getContent());
55
    }
56
57
    /**
58
     * @dataProvider getSeparator
59
     */
60 View Code Duplication
    public function testDumpYamlWithCustomSeparator($string, $data, $content)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
    {
62
        $frontMatter = new FrontMatter(null, '<!--', '-->');
63
        $document = new Document($content, $data);
64
65
        $this->assertEquals($string, $frontMatter->dump($document));
66
    }
67
68
    /**
69
     * @dataProvider getJson
70
     */
71 View Code Duplication
    public function testParseJson($string, $data, $content)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
72
    {
73
        $frontMatter = new FrontMatter(new JsonProcessor());
74
75
        $document = $frontMatter->parse($string);
76
77
        $this->assertInstanceOf(Document::class, $document);
78
        $this->assertEquals($data, $document->getData());
79
        $this->assertEquals($content, $document->getContent());
80
    }
81
82
    /**
83
     * @dataProvider getJson
84
     */
85 View Code Duplication
    public function testDumpToJson($string, $data, $content)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
86
    {
87
        $frontMatter = new FrontMatter(new JsonProcessor());
88
89
        $document = new Document($content, $data);
90
        $this->assertEquals($string, $frontMatter->dump($document));
91
    }
92
93 View Code Duplication
    public function getYaml()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
94
    {
95
        return [
96
            ['foo', [], 'foo'],
97
            ["---\nfoo: bar\n---\n", ['foo' => 'bar'], ''],
98
            ["---\nfoo: bar\n---\ntext", ['foo' => 'bar'], 'text'],
99
        ];
100
    }
101
102 View Code Duplication
    public function getSeparator()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
103
    {
104
        return [
105
            ['foo', [], 'foo'],
106
            ["<!--\nfoo: bar\n-->\n", ['foo' => 'bar'], ''],
107
            ["<!--\nfoo: bar\n-->\ntext", ['foo' => 'bar'], 'text'],
108
        ];
109
    }
110
111 View Code Duplication
    public function getJson()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
112
    {
113
        return [
114
            ['foo', [], 'foo'],
115
            ["---\n{\"foo\":\"bar\"}\n---\n", (object) ['foo' => 'bar'], ''],
116
            ["---\n{\"foo\":\"bar\"}\n---\ntext", (object) ['foo' => 'bar'], 'text'],
117
        ];
118
    }
119
}
120