1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of phpDocumentor. |
4
|
|
|
* |
5
|
|
|
* For the full copyright and license information, please view the LICENSE |
6
|
|
|
* file that was distributed with this source code. |
7
|
|
|
* |
8
|
|
|
* @copyright 2010-2015 Mike van Riel<[email protected]> |
9
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
10
|
|
|
* @link http://phpdoc.org |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace phpDocumentor\Application; |
14
|
|
|
|
15
|
|
|
use League\Event\EmitterInterface; |
16
|
|
|
use League\Flysystem\Filesystem; |
17
|
|
|
use League\Flysystem\Memory\MemoryAdapter; |
18
|
|
|
use League\Tactician\CommandBus; |
19
|
|
|
use Mockery as m; |
20
|
|
|
use phpDocumentor\Application\Render; |
21
|
|
|
use phpDocumentor\Application\RenderHandler; |
22
|
|
|
use phpDocumentor\DomainModel\Parser\Documentation; |
23
|
|
|
use phpDocumentor\DomainModel\Renderer\Assets; |
24
|
|
|
use phpDocumentor\Infrastructure\FileSystemFactory; |
25
|
|
|
use phpDocumentor\DomainModel\Parser\Version\Number; |
26
|
|
|
use phpDocumentor\DomainModel\Renderer\Template\Action; |
27
|
|
|
use phpDocumentor\DomainModel\Renderer\RenderActionCompleted; |
28
|
|
|
use phpDocumentor\DomainModel\Renderer\RenderingFinished; |
29
|
|
|
use phpDocumentor\DomainModel\Renderer\RenderingStarted; |
30
|
|
|
use phpDocumentor\DomainModel\Renderer\Template; |
31
|
|
|
use phpDocumentor\DomainModel\Renderer\TemplateFactory; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @coversDefaultClass phpDocumentor\Application\RenderHandler |
35
|
|
|
* @covers ::<private> |
36
|
|
|
*/ |
37
|
|
|
final class RenderHandlerTest extends \PHPUnit_Framework_TestCase |
38
|
|
|
{ |
39
|
|
|
/** @var TemplateFactory|m\MockInterface */ |
40
|
|
|
private $templateFactory; |
41
|
|
|
|
42
|
|
|
/** @var CommandBus|m\MockInterface */ |
43
|
|
|
private $commandBus; |
44
|
|
|
|
45
|
|
|
/** @var FileSystemFactory|m\MockInterface */ |
46
|
|
|
private $filesystemFactory; |
47
|
|
|
|
48
|
|
|
/** @var EmitterInterface|m\MockInterface */ |
49
|
|
|
private $emitter; |
50
|
|
|
|
51
|
|
|
/** @var Assets|m\MockInterface */ |
52
|
|
|
private $assets; |
53
|
|
|
|
54
|
|
|
/** @var RenderHandler|m\MockInterface */ |
55
|
|
|
private $handler; |
56
|
|
|
|
57
|
|
|
public function setUp() |
58
|
|
|
{ |
59
|
|
|
$this->templateFactory = m::mock(TemplateFactory::class); |
60
|
|
|
$this->commandBus = m::mock(CommandBus::class); |
61
|
|
|
$this->filesystemFactory = m::mock(FileSystemFactory::class); |
62
|
|
|
$this->emitter = m::mock(EmitterInterface::class); |
63
|
|
|
$this->assets = m::mock(Assets::class); |
64
|
|
|
|
65
|
|
|
$this->handler = new RenderHandler( |
|
|
|
|
66
|
|
|
$this->templateFactory, |
67
|
|
|
$this->commandBus, |
68
|
|
|
$this->filesystemFactory, |
69
|
|
|
$this->emitter, |
70
|
|
|
$this->assets |
71
|
|
|
); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @covers ::__invoke |
76
|
|
|
*/ |
77
|
|
|
public function testIfTemplateActionsAreExecutedWhenRenderingATemplate() |
78
|
|
|
{ |
79
|
|
|
$documentation = new Documentation(new Number('1.0')); |
80
|
|
|
$target = m::mock(Filesystem::class); |
81
|
|
|
$templates = [['name' => 'template']]; |
82
|
|
|
$renderActionCommand = m::mock(Action::class); |
83
|
|
|
|
84
|
|
|
$command = new Render($documentation, $target, $templates); |
|
|
|
|
85
|
|
|
|
86
|
|
|
$this->emitter->shouldReceive('emit')->once()->with(m::type(RenderActionCompleted::class)); |
|
|
|
|
87
|
|
|
$this->emitter->shouldReceive('emit')->once()->with(m::type(RenderingStarted::class)); |
88
|
|
|
$this->emitter->shouldReceive('emit')->once()->with(m::type(RenderingFinished::class)); |
89
|
|
|
|
90
|
|
|
$this->filesystemFactory->shouldReceive('create')->andReturn(new Filesystem(new MemoryAdapter())); |
91
|
|
|
$this->templateFactory |
92
|
|
|
->shouldReceive('createFromName') |
93
|
|
|
->andReturn(new Template('name', [], [$renderActionCommand])); |
|
|
|
|
94
|
|
|
|
95
|
|
|
$this->commandBus->shouldReceive('handle')->once()->with($renderActionCommand); |
|
|
|
|
96
|
|
|
|
97
|
|
|
$this->handler->__invoke($command); |
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* @covers ::__invoke |
102
|
|
|
*/ |
103
|
|
|
public function testIfRenderingFailsIfTemplateWasNotFound() |
104
|
|
|
{ |
105
|
|
|
$this->setExpectedException(\InvalidArgumentException::class, 'The template "template" could not be found'); |
106
|
|
|
|
107
|
|
|
$documentation = new Documentation(new Number('1.0')); |
108
|
|
|
$target = m::mock(Filesystem::class); |
109
|
|
|
$templates = [['name' => 'template']]; |
110
|
|
|
|
111
|
|
|
$command = new Render($documentation, $target, $templates); |
|
|
|
|
112
|
|
|
|
113
|
|
|
$this->emitter->shouldReceive('emit')->never()->with(m::type(RenderActionCompleted::class)); |
|
|
|
|
114
|
|
|
$this->emitter->shouldReceive('emit')->once()->with(m::type(RenderingStarted::class)); |
115
|
|
|
$this->emitter->shouldReceive('emit')->never()->with(m::type(RenderingFinished::class)); |
116
|
|
|
|
117
|
|
|
$this->filesystemFactory->shouldReceive('create')->andReturn(new Filesystem(new MemoryAdapter())); |
118
|
|
|
$this->templateFactory |
119
|
|
|
->shouldReceive('createFromName') |
120
|
|
|
->andReturn(null); |
121
|
|
|
|
122
|
|
|
$this->commandBus->shouldReceive('handle')->never(); |
|
|
|
|
123
|
|
|
|
124
|
|
|
$this->handler->__invoke($command); |
|
|
|
|
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..