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 JolichtTeset\MarkdownCms\Parser; |
11
|
|
|
|
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
use Jolicht\MarkdownCms\Parser\ParseContentExecutor; |
14
|
|
|
use Jolicht\MarkdownCms\Parser\ContentParser; |
15
|
|
|
use Jolicht\MarkdownCms\Parser\Observer\ParsedContentObserverInterface; |
16
|
|
|
|
17
|
|
|
class ParseContentExecutorTest extends TestCase |
18
|
|
|
{ |
19
|
|
|
private $executor, $contentParser; |
|
|
|
|
20
|
|
|
|
21
|
|
|
protected function setUp() |
22
|
|
|
{ |
23
|
|
|
$this->contentParser = $this->getMockBuilder(ContentParser::class) |
24
|
|
|
->setMethods(['__invoke']) |
25
|
|
|
->disableOriginalConstructor() |
26
|
|
|
->getMock(); |
27
|
|
|
$this->executor = new ParseContentExecutor($this->contentParser); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
public function testGetContentParser() |
31
|
|
|
{ |
32
|
|
|
$this->assertSame($this->contentParser, $this->executor->getContentParser()); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testGetObservers() |
36
|
|
|
{ |
37
|
|
|
$this->assertSame([], $this->executor->getObservers()); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testAddObserver() |
41
|
|
|
{ |
42
|
|
|
$observer = $this->getMockBuilder(ParsedContentObserverInterface::class)->getMock(); |
43
|
|
|
$this->executor->addObserver($observer); |
44
|
|
|
$this->assertSame([$observer], $this->executor->getObservers()); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testNotifyObservers() |
48
|
|
|
{ |
49
|
|
|
$observer = $this->getMockBuilder(ParsedContentObserverInterface::class) |
50
|
|
|
->setMethods(['__invoke']) |
51
|
|
|
->getMock(); |
52
|
|
|
|
53
|
|
|
$config = ['testConfig']; |
54
|
|
|
|
55
|
|
|
$this->contentParser->expects($this->once()) |
56
|
|
|
->method('__invoke') |
57
|
|
|
->will($this->returnValue($config)); |
58
|
|
|
|
59
|
|
|
$observer->expects(($this->once())) |
60
|
|
|
->method('__invoke') |
61
|
|
|
->with($this->equalTo($config)); |
62
|
|
|
|
63
|
|
|
$this->executor->addObserver($observer); |
64
|
|
|
$this->executor->__invoke(); |
65
|
|
|
} |
66
|
|
|
} |
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.