Passed
Branch refactor-markdown-helper (02b3eb)
by Caen
04:15
created

test_can_parse_markdown_file()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 14
rs 9.9332
1
<?php
2
3
namespace Hyde\Framework\Testing\Feature;
4
5
use Hyde\Framework\Hyde;
6
use Hyde\Framework\Models\MarkdownDocument;
7
use Hyde\Framework\Modules\Markdown\MarkdownFileParser;
8
use Hyde\Testing\TestCase;
9
10
class MarkdownFileParserTest extends TestCase
11
{
12
    protected function setUp(): void
13
    {
14
        parent::setUp();
15
16
        file_put_contents(Hyde::path('_posts/test-post.md'), '---
17
title: My New Post
18
category: blog
19
author: Mr. Hyde
20
---
21
22
# My New Post
23
24
This is a post stub used in the automated tests
25
');
26
    }
27
28
    protected function tearDown(): void
29
    {
30
        unlink(Hyde::path('_posts/test-post.md'));
31
32
        parent::tearDown();
33
    }
34
35
    public function test_can_parse_markdown_file()
36
    {
37
        $document = (new MarkdownFileParser(Hyde::path('_posts/test-post.md')))->get();
38
        $this->assertInstanceOf(MarkdownDocument::class, $document);
39
40
        $this->assertEquals([
41
            'title' => 'My New Post',
42
            'category' => 'blog',
43
            'author' => 'Mr. Hyde',
44
        ], $document->matter);
45
46
        $this->assertEquals(
47
            '# My New PostThis is a post stub used in the automated tests',
48
            str_replace(["\n", "\r"], '', $document->body)
49
        );
50
    }
51
52
    public function test_parsed_markdown_post_contains_valid_front_matter()
53
    {
54
        $post = (new MarkdownFileParser(Hyde::path('_posts/test-post.md')))->get();
55
        $this->assertEquals('My New Post', $post->matter['title']);
56
        $this->assertEquals('Mr. Hyde', $post->matter['author']);
57
        $this->assertEquals('blog', $post->matter['category']);
58
    }
59
}
60