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\Action; |
11
|
|
|
|
12
|
|
|
use PHPUnit\Framework\TestCase; |
13
|
|
|
use Jolicht\MarkdownCms\Action\SingleBlogEntryAction; |
14
|
|
|
use Zend\Expressive\Template\TemplateRendererInterface; |
15
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
16
|
|
|
use Psr\Http\Message\ResponseInterface; |
17
|
|
|
use Jolicht\MarkdownCms\ContentType\ContentTypeInterface; |
18
|
|
|
use Zend\Diactoros\Response\HtmlResponse; |
19
|
|
|
use Jolicht\MarkdownCms\ContentType\EntryParser; |
20
|
|
|
|
21
|
|
|
class SingleBlogEntryActionTest extends TestCase |
22
|
|
|
{ |
23
|
|
|
private $action, $templateRenderer, $entryParser, $markdownCmsConfig; |
|
|
|
|
24
|
|
|
|
25
|
|
|
protected function setUp() |
26
|
|
|
{ |
27
|
|
|
$this->templateRenderer = $this->prophesize(TemplateRendererInterface::class); |
28
|
|
|
$this->entryParser = $this->prophesize(EntryParser::class); |
29
|
|
|
$this->markdownCmsConfig = [ |
30
|
|
|
'options' => [ |
31
|
|
|
'content_dir' => 'testContentDir' |
32
|
|
|
], |
33
|
|
|
]; |
34
|
|
|
|
35
|
|
|
$this->action = new SingleBlogEntryAction( |
36
|
|
|
$this->templateRenderer->reveal(), |
37
|
|
|
$this->entryParser->reveal(), |
38
|
|
|
$this->markdownCmsConfig |
39
|
|
|
); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
public function testInvoke() |
44
|
|
|
{ |
45
|
|
|
$request = $this->prophesize(ServerRequestInterface::class); |
46
|
|
|
$request |
47
|
|
|
->getAttribute('id') |
48
|
|
|
->willReturn('testId'); |
49
|
|
|
|
50
|
|
|
$entry = $this->prophesize(ContentTypeInterface::class); |
51
|
|
|
$entry |
52
|
|
|
->getTemplate() |
53
|
|
|
->willReturn('app::template.twig'); |
54
|
|
|
|
55
|
|
|
$this->entryParser |
56
|
|
|
->__invoke('testId') |
57
|
|
|
->willReturn($entry->reveal()); |
58
|
|
|
|
59
|
|
|
$this->templateRenderer |
60
|
|
|
->render('app::template.twig', ['entry' => $entry->reveal()]) |
61
|
|
|
->willReturn(''); |
62
|
|
|
|
63
|
|
|
$response = ($this->action)( |
64
|
|
|
$request->reveal(), |
65
|
|
|
$this->prophesize(ResponseInterface::class)->reveal() |
66
|
|
|
); |
67
|
|
|
|
68
|
|
|
$this->assertInstanceOf(HtmlResponse::class, $response); |
69
|
|
|
} |
70
|
|
|
} |
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.