1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* phpDocumentor |
4
|
|
|
* |
5
|
|
|
* PHP Version 5.3 |
6
|
|
|
* |
7
|
|
|
* @copyright 2010-2018 Mike van Riel / Naenius (http://www.naenius.com) |
8
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php MIT |
9
|
|
|
* @link http://phpdoc.org |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace phpDocumentor\Transformer\Template; |
13
|
|
|
|
14
|
|
|
use JMS\Serializer\Serializer; |
15
|
|
|
use Mockery as m; |
16
|
|
|
use org\bovigo\vfs\vfsStream; |
17
|
|
|
use phpDocumentor\Transformer\Template; |
18
|
|
|
|
19
|
|
|
class FactoryTest extends \Mockery\Adapter\Phpunit\MockeryTestCase |
20
|
|
|
{ |
21
|
|
|
/** @var m\MockInterface|PathResolver */ |
22
|
|
|
private $pathResolverMock; |
23
|
|
|
|
24
|
|
|
/** @var m\MockInterface|Serializer */ |
25
|
|
|
private $serializerMock; |
26
|
|
|
|
27
|
|
|
/** @var Factory */ |
28
|
|
|
private $fixture; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Sets up the fixture with mocked dependencies. |
32
|
|
|
*/ |
33
|
|
|
protected function setUp() |
34
|
|
|
{ |
35
|
|
|
$this->pathResolverMock = m::mock('phpDocumentor\Transformer\Template\PathResolver'); |
36
|
|
|
$this->serializerMock = m::mock('JMS\Serializer\Serializer'); |
37
|
|
|
|
38
|
|
|
$this->fixture = new Factory($this->pathResolverMock, $this->serializerMock); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @covers phpDocumentor\Transformer\Template\Factory::__construct |
43
|
|
|
*/ |
44
|
|
|
public function testIfDependenciesAreCorrectlyRegisteredOnInitialization() |
45
|
|
|
{ |
46
|
|
|
$this->assertAttributeSame($this->pathResolverMock, 'pathResolver', $this->fixture); |
47
|
|
|
$this->assertAttributeSame($this->serializerMock, 'serializer', $this->fixture); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* @covers phpDocumentor\Transformer\Template\Factory::get |
52
|
|
|
* @covers phpDocumentor\Transformer\Template\Factory::fetchTemplateXmlFromPath |
53
|
|
|
* @covers phpDocumentor\Transformer\Template\Factory::createTemplateFromXml |
54
|
|
|
*/ |
55
|
|
|
public function testRetrieveInstantiatedTemplate() |
56
|
|
|
{ |
57
|
|
|
// Arrange |
58
|
|
|
$templateName = 'clean'; |
59
|
|
|
$template = new Template($templateName); |
60
|
|
|
vfsStream::setup('exampleDir')->addChild(vfsStream::newFile('template.xml')->setContent('xml')); |
61
|
|
|
$this->pathResolverMock->shouldReceive('resolve')->with($templateName)->andReturn(vfsStream::url('exampleDir')); |
|
|
|
|
62
|
|
|
$this->serializerMock |
|
|
|
|
63
|
|
|
->shouldReceive('deserialize') |
64
|
|
|
->with('xml', 'phpDocumentor\Transformer\Template', 'xml') |
65
|
|
|
->andReturn($template); |
66
|
|
|
|
67
|
|
|
// Act |
68
|
|
|
$result = $this->fixture->get($templateName); |
69
|
|
|
|
70
|
|
|
// Assert |
71
|
|
|
$this->assertSame($template, $result); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @covers phpDocumentor\Transformer\Template\Factory::getTemplatePath |
76
|
|
|
*/ |
77
|
|
|
public function testReturnTemplatePathFromResolver() |
78
|
|
|
{ |
79
|
|
|
// Arrange |
80
|
|
|
$expected = 'test'; |
81
|
|
|
$this->pathResolverMock->shouldReceive('getTemplatePath')->andReturn($expected); |
|
|
|
|
82
|
|
|
|
83
|
|
|
// Act |
84
|
|
|
$result = $this->fixture->getTemplatePath(); |
85
|
|
|
|
86
|
|
|
// Assert |
87
|
|
|
$this->assertSame($expected, $result); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @covers phpDocumentor\Transformer\Template\Factory::getAllNames |
92
|
|
|
*/ |
93
|
|
|
public function testRetrieveAllTemplateNames() |
94
|
|
|
{ |
95
|
|
|
// Arrange |
96
|
|
|
$expected = ['template1', 'template2']; |
97
|
|
|
$root = vfsStream::setup('exampleDir'); |
98
|
|
|
$root->addChild(vfsStream::newDirectory($expected[0])); |
99
|
|
|
$root->addChild(vfsStream::newFile('aFile.txt')); |
100
|
|
|
$root->addChild(vfsStream::newDirectory($expected[1])); |
101
|
|
|
$this->pathResolverMock->shouldReceive('getTemplatePath')->andReturn(vfsStream::url('exampleDir')); |
|
|
|
|
102
|
|
|
|
103
|
|
|
// Act |
104
|
|
|
$result = $this->fixture->getAllNames(); |
105
|
|
|
|
106
|
|
|
// Assert |
107
|
|
|
$this->assertSame($expected, $result); |
108
|
|
|
} |
109
|
|
|
} |
110
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: