|
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\ContentType; |
|
11
|
|
|
|
|
12
|
|
|
use PHPUnit\Framework\TestCase; |
|
13
|
|
|
use Jolicht\MarkdownCms\ContentType\EntryParser; |
|
14
|
|
|
use Jolicht\MarkdownCms\Markdown\MarkdownDocumentParser; |
|
15
|
|
|
use Jolicht\MarkdownCms\ContentType\ContentCreator; |
|
16
|
|
|
use Jolicht\MarkdownCms\Markdown\MarkdownDocument; |
|
17
|
|
|
use Jolicht\MarkdownCms\ContentType\ContentTypeInterface; |
|
18
|
|
|
|
|
19
|
|
|
class EntryParserTest extends TestCase |
|
20
|
|
|
{ |
|
21
|
|
|
private $parser, $mdDocumentParser, $contentCreator, $config; |
|
|
|
|
|
|
22
|
|
|
|
|
23
|
|
|
protected function setUp() |
|
24
|
|
|
{ |
|
25
|
|
|
$this->config = [ |
|
26
|
|
|
'testId' => [ |
|
27
|
|
|
'src' => 'test.md' |
|
28
|
|
|
] |
|
29
|
|
|
]; |
|
30
|
|
|
$this->contentCreator = $this->getMockBuilder(ContentCreator::class) |
|
31
|
|
|
->setMethods(['__invoke']) |
|
32
|
|
|
->disableOriginalConstructor() |
|
33
|
|
|
->getMock(); |
|
34
|
|
|
$this->mdDocumentParser = $this->getMockBuilder(MarkdownDocumentParser::class) |
|
35
|
|
|
->setMethods(['__invoke']) |
|
36
|
|
|
->disableOriginalConstructor() |
|
37
|
|
|
->getMock(); |
|
38
|
|
|
$this->parser = new EntryParser($this->contentCreator, $this->mdDocumentParser, $this->config, |
|
39
|
|
|
__DIR__ . '/_files/'); |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
public function testGetContentDir() |
|
43
|
|
|
{ |
|
44
|
|
|
$this->assertSame(__DIR__ . '/_files', $this->parser->getContentDir()); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testGetContentCreator() |
|
48
|
|
|
{ |
|
49
|
|
|
$this->assertSame($this->contentCreator, $this->parser->getContentCreator()); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
public function testGetMarkdownDocumentParser() |
|
53
|
|
|
{ |
|
54
|
|
|
$this->assertSame($this->mdDocumentParser, $this->parser->getMarkdownDocumentParser()); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
public function testGetConfig() |
|
58
|
|
|
{ |
|
59
|
|
|
$this->assertSame($this->config, $this->parser->getConfig()); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function testInvoke() |
|
63
|
|
|
{ |
|
64
|
|
|
$contentType = $this->createMock(ContentTypeInterface::class); |
|
65
|
|
|
$markdownDocument = new MarkdownDocument([], 'testContent'); |
|
66
|
|
|
$this->mdDocumentParser->expects($this->once()) |
|
67
|
|
|
->method('__invoke') |
|
68
|
|
|
->with($this->equalTo('testContent')) |
|
69
|
|
|
->will($this->returnValue($markdownDocument)); |
|
70
|
|
|
|
|
71
|
|
|
$this->contentCreator->expects($this->once()) |
|
72
|
|
|
->method('__invoke') |
|
73
|
|
|
->with($this->equalTo($markdownDocument)) |
|
74
|
|
|
->will($this->returnValue($contentType)); |
|
75
|
|
|
|
|
76
|
|
|
$this->assertSame($contentType, $this->parser->__invoke('testId')); |
|
77
|
|
|
} |
|
78
|
|
|
} |
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.