Completed
Push — master ( c4ca74...5a127a )
by Martin
05:21
created

LocalDataTest::dataProvider()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 13
rs 9.4285
cc 2
eloc 8
nc 2
nop 0
1
<?php
2
3
/*
4
 * This is part of the webuni/commonmark-attributes-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\AttributesExtension\Tests\Functional;
14
15
use League\CommonMark\Converter;
16
use League\CommonMark\DocParser;
17
use League\CommonMark\Environment;
18
use League\CommonMark\HtmlRenderer;
19
use Webuni\CommonMark\AttributesExtension\AttributesExtension;
20
use Webuni\CommonMark\TableExtension\TableExtension;
21
22
class LocalDataTest extends \PHPUnit_Framework_TestCase
23
{
24
    protected $converter;
25
26
    protected function setUp()
27
    {
28
        $environment = Environment::createCommonMarkEnvironment();
29
        $environment->addExtension(new AttributesExtension());
30
        $environment->addExtension(new TableExtension());
31
32
        $this->converter = new Converter(new DocParser($environment), new HtmlRenderer($environment));
33
    }
34
35
    /**
36
     * @dataProvider dataProvider
37
     */
38
    public function testExample($markdown, $html, $testName)
39
    {
40
        $actualResult = $this->converter->convertToHtml($markdown);
41
42
        $failureMessage = sprintf('Unexpected result for "%s" test', $testName);
43
        $failureMessage .= "\n=== markdown ===============\n".$markdown;
44
        $failureMessage .= "\n=== expected ===============\n".$html;
45
        $failureMessage .= "\n=== got ====================\n".$actualResult;
46
47
        $this->assertEquals($html, $actualResult, $failureMessage);
48
    }
49
50
    /**
51
     * @return array
52
     */
53
    public function dataProvider()
54
    {
55
        $ret = [];
56
        foreach (glob(__DIR__.'/data/*.md') as $markdownFile) {
57
            $testName = basename($markdownFile, '.md');
58
            $markdown = file_get_contents($markdownFile);
59
            $html = file_get_contents(__DIR__.'/data/'.$testName.'.html');
60
61
            $ret[] = [$markdown, $html, $testName];
62
        }
63
64
        return $ret;
65
    }
66
}
67