1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/** |
6
|
|
|
* This file is part of phpDocumentor. |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
* |
11
|
|
|
* @link http://phpdoc.org |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace phpDocumentor\Transformer\Writer\Twig; |
15
|
|
|
|
16
|
|
|
use phpDocumentor\Descriptor\ProjectDescriptor; |
17
|
|
|
use phpDocumentor\Faker\Faker; |
18
|
|
|
use phpDocumentor\Transformer\Router\Router; |
19
|
|
|
use PHPUnit\Framework\TestCase; |
20
|
|
|
use Twig\Environment; |
21
|
|
|
use Twig\Extension\DebugExtension; |
22
|
|
|
use Twig\Loader\ChainLoader; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @coversDefaultClass \phpDocumentor\Transformer\Writer\Twig\EnvironmentFactory |
26
|
|
|
* @covers ::__construct |
27
|
|
|
* @covers ::<private> |
28
|
|
|
*/ |
29
|
|
|
final class EnvironmentFactoryTest extends TestCase |
30
|
|
|
{ |
31
|
|
|
use Faker; |
32
|
|
|
|
33
|
|
|
/** @var Router */ |
34
|
|
|
private $router; |
35
|
|
|
|
36
|
|
|
/** @var EnvironmentFactory */ |
37
|
|
|
private $factory; |
38
|
|
|
|
39
|
|
|
protected function setUp() : void |
40
|
|
|
{ |
41
|
|
|
$this->router = $this->prophesize(Router::class); |
42
|
|
|
|
43
|
|
|
$this->factory = new EnvironmentFactory( |
44
|
|
|
new LinkRenderer($this->router->reveal()) |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @uses \phpDocumentor\Descriptor\ProjectDescriptor |
50
|
|
|
* @uses \phpDocumentor\Transformer\Writer\Twig\LinkRenderer |
51
|
|
|
* |
52
|
|
|
* @covers ::create |
53
|
|
|
*/ |
54
|
|
|
public function testItCreatesATwigEnvironmentWithThephpDocumentorExtension() : void |
55
|
|
|
{ |
56
|
|
|
$transformation = $this->faker()->transformation(); |
|
|
|
|
57
|
|
|
|
58
|
|
|
$environment = $this->factory->create(new ProjectDescriptor('name'), $transformation, '/home'); |
59
|
|
|
|
60
|
|
|
$this->assertInstanceOf(Environment::class, $environment); |
61
|
|
|
$this->assertCount(4, $environment->getExtensions()); |
62
|
|
|
$this->assertTrue($environment->hasExtension(Extension::class)); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @uses \phpDocumentor\Descriptor\ProjectDescriptor |
67
|
|
|
* @uses \phpDocumentor\Transformer\Writer\Twig\LinkRenderer |
68
|
|
|
* |
69
|
|
|
* @covers ::create |
70
|
|
|
*/ |
71
|
|
|
public function testItCreatesATwigEnvironmentWithTheCorrectTemplateLoaders() : void |
72
|
|
|
{ |
73
|
|
|
$transformation = $this->faker()->transformation(); |
|
|
|
|
74
|
|
|
|
75
|
|
|
$mountManager = $transformation->template()->files(); |
76
|
|
|
|
77
|
|
|
$environment = $this->factory->create(new ProjectDescriptor('name'), $transformation, '/home'); |
78
|
|
|
|
79
|
|
|
/** @var ChainLoader $loader */ |
80
|
|
|
$loader = $environment->getLoader(); |
81
|
|
|
|
82
|
|
|
$this->assertInstanceOf(ChainLoader::class, $loader); |
83
|
|
|
$this->assertEquals( |
84
|
|
|
[ |
85
|
|
|
new FlySystemLoader($mountManager->getFilesystem('templates'), '', 'base'), |
86
|
|
|
new FlySystemLoader($mountManager->getFilesystem('template')), |
87
|
|
|
], |
88
|
|
|
$loader->getLoaders() |
89
|
|
|
); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @uses \phpDocumentor\Descriptor\ProjectDescriptor |
94
|
|
|
* @uses \phpDocumentor\Transformer\Writer\Twig\LinkRenderer |
95
|
|
|
* @uses \phpDocumentor\Transformer\Template\Parameter |
96
|
|
|
* |
97
|
|
|
* @covers ::create |
98
|
|
|
*/ |
99
|
|
|
public function testTheCreatedEnvironmentHasTheDebugExtension() : void |
100
|
|
|
{ |
101
|
|
|
$transformation = $this->faker()->transformation(); |
|
|
|
|
102
|
|
|
|
103
|
|
|
$environment = $this->factory->create(new ProjectDescriptor('name'), $transformation, '/home'); |
104
|
|
|
|
105
|
|
|
$this->assertFalse($environment->getCache()); |
106
|
|
|
$this->assertTrue($environment->isDebug()); |
107
|
|
|
$this->assertTrue($environment->isAutoReload()); |
108
|
|
|
$this->assertInstanceOf(Environment::class, $environment); |
109
|
|
|
$this->assertCount(5, $environment->getExtensions()); |
110
|
|
|
$this->assertTrue($environment->hasExtension(Extension::class)); |
111
|
|
|
$this->assertTrue($environment->hasExtension(DebugExtension::class)); |
112
|
|
|
} |
113
|
|
|
} |
114
|
|
|
|
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: