|
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\Parser\Observer; |
|
11
|
|
|
|
|
12
|
|
|
use PHPUnit\Framework\TestCase; |
|
13
|
|
|
use Jolicht\MarkdownCms\Parser\Observer\SaveContentConfigObserver; |
|
14
|
|
|
use Zend\Config\Writer\PhpArray; |
|
15
|
|
|
|
|
16
|
|
|
class SaveContentConfigObserverTest extends TestCase |
|
17
|
|
|
{ |
|
18
|
|
|
private $observer, $configWriter; |
|
19
|
|
|
|
|
20
|
|
|
protected function setUp() |
|
21
|
|
|
{ |
|
22
|
|
|
$this->configWriter = new PhpArray(); |
|
23
|
|
|
$this->observer = new SaveContentConfigObserver($this->configWriter, __DIR__ . '/_files/markdown-cms.global.php'); |
|
24
|
|
|
} |
|
25
|
|
|
|
|
26
|
|
|
public function testGetConfigWriter() |
|
27
|
|
|
{ |
|
28
|
|
|
$this->assertSame($this->configWriter, $this->observer->getConfigWriter()); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
public function testGetTargetPath() |
|
32
|
|
|
{ |
|
33
|
|
|
$this->assertSame(__DIR__ . '/_files/markdown-cms.global.php', $this->observer->getTargetPath()); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function testInvoke() |
|
37
|
|
|
{ |
|
38
|
|
|
$targetPath =$this->observer->getTargetPath(); |
|
39
|
|
|
if (file_exists($targetPath)) { |
|
40
|
|
|
unlink($targetPath); |
|
41
|
|
|
} |
|
42
|
|
|
$config = [ |
|
43
|
|
|
'markdown_cms' => [ |
|
44
|
|
|
'testKey' => 'testEntry' |
|
45
|
|
|
] |
|
46
|
|
|
]; |
|
47
|
|
|
|
|
48
|
|
|
$expected = [ |
|
49
|
|
|
'markdown_cms' => [ |
|
50
|
|
|
'content' => $config |
|
51
|
|
|
] |
|
52
|
|
|
]; |
|
53
|
|
|
|
|
54
|
|
|
$this->observer->__invoke($config); |
|
55
|
|
|
$this->assertFileExists($targetPath); |
|
56
|
|
|
$this->assertEquals($expected, include $targetPath); |
|
57
|
|
|
} |
|
58
|
|
|
} |