|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Lichtenwallner (https://lichtenwallner.at) |
|
4
|
|
|
* |
|
5
|
|
|
* @see https://github.com/jolicht/markdown-cms for the canonical source repository |
|
6
|
|
|
* @license https://github.com/jolicht/markdown-cms/blob/master/LICENSE MIT |
|
7
|
|
|
* @copyright Copyright (c) Johannes Lichtenwallner |
|
8
|
|
|
*/ |
|
9
|
|
|
declare(strict_types = 1); |
|
10
|
|
|
namespace JolichtTest\MarkdownCms\Markdown; |
|
11
|
|
|
|
|
12
|
|
|
use Jolicht\MarkdownCms\Markdown\MarkdownDocumentParser; |
|
13
|
|
|
use Mni\FrontYAML\Parser; |
|
14
|
|
|
use Mni\FrontYAML\Document; |
|
15
|
|
|
use PHPUnit\Framework\TestCase; |
|
16
|
|
|
|
|
17
|
|
|
class MarkdownDocumentParserTest extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
private $parser, $frontYamlParser; |
|
|
|
|
|
|
20
|
|
|
|
|
21
|
|
|
protected function setUp() |
|
22
|
|
|
{ |
|
23
|
|
|
$this->frontYamlParser = $this->getMockBuilder(Parser::class) |
|
24
|
|
|
->setMethods(['parse']) |
|
25
|
|
|
->disableOriginalConstructor() |
|
26
|
|
|
->getMock(); |
|
27
|
|
|
$this->parser = new MarkdownDocumentParser($this->frontYamlParser); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testGetFrontYamlParser() |
|
31
|
|
|
{ |
|
32
|
|
|
$this->assertSame($this->frontYamlParser, $this->parser->getFrontYamlParser()); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function testParse() |
|
36
|
|
|
{ |
|
37
|
|
|
$params = [ |
|
38
|
|
|
'id' => 'testId' |
|
39
|
|
|
]; |
|
40
|
|
|
|
|
41
|
|
|
$frontYamlDocument = new Document($params, 'testContent'); |
|
42
|
|
|
$this->frontYamlParser->expects($this->once()) |
|
43
|
|
|
->method('parse') |
|
44
|
|
|
->with($this->equalTo('testDocumentContent')) |
|
45
|
|
|
->will($this->returnValue($frontYamlDocument)); |
|
46
|
|
|
|
|
47
|
|
|
$markdownDocument = ($this->parser)('testDocumentContent'); |
|
48
|
|
|
$this->assertSame($params, $markdownDocument->getParams()); |
|
49
|
|
|
$this->assertSame('testContent', $markdownDocument->getContent()); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
} |
Only declaring a single property per statement allows you to later on add doc comments more easily.
It is also recommended by PSR2, so it is a common style that many people expect.