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\Configuration; |
15
|
|
|
|
16
|
|
|
use League\Uri\Uri; |
17
|
|
|
use phpDocumentor\Path; |
18
|
|
|
use phpDocumentor\Transformer\Writer\Twig\EnvironmentFactory; |
19
|
|
|
use PHPUnit\Framework\TestCase; |
20
|
|
|
use function chdir; |
21
|
|
|
use function dirname; |
22
|
|
|
use function realpath; |
23
|
|
|
|
24
|
|
|
final class ProvideTemplateOverridePathMiddlewareTest extends TestCase |
25
|
|
|
{ |
26
|
|
|
public function test_the_override_path_is_a_subfolder_of_the_folder_with_the_loaded_config_file() : void |
27
|
|
|
{ |
28
|
|
|
// Cannot use vfsStream because code breaks out of virtual filesystems to support PHAR file. |
29
|
|
|
$configurationFilePath = __DIR__ . '/../../../../phpdoc.dist.xml'; |
30
|
|
|
$overridePath = new Path(realpath(dirname($configurationFilePath) . '/.phpdoc/template')); |
31
|
|
|
|
32
|
|
|
$environmentFactory = $this->prophesize(EnvironmentFactory::class); |
33
|
|
|
$environmentFactory->withTemplateOverridesAt($overridePath)->shouldBeCalledOnce(); |
34
|
|
|
|
35
|
|
|
$middleware = new ProvideTemplateOverridePathMiddleware($environmentFactory->reveal()); |
36
|
|
|
$middleware->__invoke([], Uri::createFromString($configurationFilePath)); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function test_the_override_path_is_a_subfolder_of_cwd_when_there_is_no_loaded_config_file() : void |
40
|
|
|
{ |
41
|
|
|
// Cannot use vfsStream because code breaks out of virtual filesystems to support PHAR file; so we chdir into |
42
|
|
|
// this project's folder. We know there is a .phpdoc/template folder there |
43
|
|
|
$folderContainingAPhpDocMetaFolder = __DIR__ . '/../../../..'; |
44
|
|
|
chdir($folderContainingAPhpDocMetaFolder); |
45
|
|
|
$overridePath = new Path(realpath($folderContainingAPhpDocMetaFolder . '/.phpdoc/template')); |
46
|
|
|
|
47
|
|
|
$environmentFactory = $this->prophesize(EnvironmentFactory::class); |
48
|
|
|
$environmentFactory->withTemplateOverridesAt($overridePath)->shouldBeCalledOnce(); |
49
|
|
|
|
50
|
|
|
$middleware = new ProvideTemplateOverridePathMiddleware($environmentFactory->reveal()); |
51
|
|
|
$middleware->__invoke([], null); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function test_the_override_path_is_not_set_when_override_folder_does_not_exist() : void |
55
|
|
|
{ |
56
|
|
|
// This is obviously a fake, this folder does not have a config file |
57
|
|
|
$configurationFilePath = __DIR__ . '/phpdoc.dist.xml'; |
58
|
|
|
|
59
|
|
|
$environmentFactory = $this->prophesize(EnvironmentFactory::class); |
60
|
|
|
$environmentFactory->withTemplateOverridesAt()->shouldNotBeCalled(); |
61
|
|
|
|
62
|
|
|
$middleware = new ProvideTemplateOverridePathMiddleware($environmentFactory->reveal()); |
63
|
|
|
$middleware->__invoke([], Uri::createFromString($configurationFilePath)); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|