1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Micro framework package. |
7
|
|
|
* |
8
|
|
|
* (c) Stanislau Komar <[email protected]> |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
11
|
|
|
* file that was distributed with this source code. |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
namespace Micro\Plugin\Twig\Test\Unit\Business\Loader; |
15
|
|
|
|
16
|
|
|
use Micro\Plugin\Twig\Business\Loader\TemplateLoader; |
17
|
|
|
use Micro\Plugin\Twig\Plugin\TwigTemplatePluginInterface; |
18
|
|
|
use PHPUnit\Framework\TestCase; |
19
|
|
|
use Twig\Environment; |
20
|
|
|
use Twig\Loader\FilesystemLoader; |
21
|
|
|
use Twig\Loader\LoaderInterface; |
22
|
|
|
|
23
|
|
|
class TemplateLoaderTest extends TestCase |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @param class-string $loaderMock |
|
|
|
|
27
|
|
|
* |
28
|
|
|
* @dataProvider dataProvider |
29
|
|
|
*/ |
30
|
|
|
public function testLoad(string $loaderMock, string|null $exception): void |
31
|
|
|
{ |
32
|
|
|
if ($exception) { |
33
|
|
|
$this->expectException($exception); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
$templateLoader = new TemplateLoader(); |
37
|
|
|
$templatePath = [ |
38
|
|
|
'/a', |
39
|
|
|
]; |
40
|
|
|
$fakePlugin = new \stdClass(); |
41
|
|
|
$plugin = $this->createMock(TwigTemplatePluginInterface::class); |
42
|
|
|
$loader = $this->createMock($loaderMock); |
43
|
|
|
|
44
|
|
|
if (FilesystemLoader::class === $loaderMock) { |
45
|
|
|
$loader |
46
|
|
|
->expects($this->once()) |
47
|
|
|
->method('addPath') |
48
|
|
|
->with($templatePath[0], FilesystemLoader::MAIN_NAMESPACE); |
49
|
|
|
|
50
|
|
|
$plugin->expects($this->once())->method('getTwigNamespace')->willReturn(null); |
51
|
|
|
$plugin->expects($this->once())->method('getTwigTemplatePaths')->willReturn($templatePath); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
$twigEnv = $this->createMock(Environment::class); |
55
|
|
|
$twigEnv->expects($this->once())->method('getLoader')->willReturn($loader); |
56
|
|
|
|
57
|
|
|
$templateLoader->load($twigEnv, $fakePlugin); |
58
|
|
|
$templateLoader->load($twigEnv, $plugin); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
public function dataProvider(): array |
62
|
|
|
{ |
63
|
|
|
return [ |
64
|
|
|
[FilesystemLoader::class, null], |
65
|
|
|
[LoaderInterface::class, \InvalidArgumentException::class], |
66
|
|
|
]; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|