Completed
Push — master ( ebe4b3...b11075 )
by Martin
05:17
created

LocalDataTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
/*
4
 * This is part of the webuni/commonmark-table-extension package.
5
 *
6
 * (c) Martin Hasoň <[email protected]>
7
 * (c) Webuni s.r.o. <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Webuni\CommonMark\TableExtension\Tests\Functional;
14
15
use League\CommonMark\DocParser;
16
use League\CommonMark\ElementRendererInterface;
17
use League\CommonMark\Environment;
18
use League\CommonMark\HtmlRenderer;
19
use Webuni\CommonMark\TableExtension\TableExtension;
20
21
class LocalDataTest extends \PHPUnit_Framework_TestCase
22
{
23
    /* @var Environment */
24
    private $environment;
25
    private $parser;
26
27
    protected function setUp()
28
    {
29
        $this->environment = Environment::createCommonMarkEnvironment();
30
        $this->environment->addExtension(new TableExtension());
31
32
        $this->parser = new DocParser($this->environment);
33
    }
34
35
    /**
36
     * @dataProvider dataProvider
37
     */
38
    public function testRenderer($markdown, $html, $testName)
39
    {
40
        $renderer = new HtmlRenderer($this->environment);
41
        $this->assertCommonMark($renderer, $markdown, $html, $testName);
42
    }
43
44
    /**
45
     * @return array
46
     */
47
    public function dataProvider()
48
    {
49
        $ret = [];
50
        foreach (glob(__DIR__.'/data/*.md') as $markdownFile) {
51
            $testName = basename($markdownFile, '.md');
52
            $markdown = file_get_contents($markdownFile);
53
            $html = file_get_contents(__DIR__.'/data/'.$testName.'.html');
54
55
            $ret[] = [$markdown, $html, $testName];
56
        }
57
58
        return $ret;
59
    }
60
61
    protected function assertCommonMark(ElementRendererInterface $renderer, $markdown, $html, $testName)
62
    {
63
        $documentAST = $this->parser->parse($markdown);
64
        $actualResult = $renderer->renderBlock($documentAST);
65
66
        $failureMessage = sprintf('Unexpected result for "%s" test', $testName);
67
        $failureMessage .= "\n=== markdown ===============\n".$markdown;
68
        $failureMessage .= "\n=== expected ===============\n".$html;
69
        $failureMessage .= "\n=== got ====================\n".$actualResult;
70
71
        $this->assertEquals($html, $actualResult, $failureMessage);
72
    }
73
}
74