Passed
Branch v1.5-release (4e8d3b)
by Stanislau
03:27
created

TemplateLoaderTest::dataProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
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
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string.
Loading history...
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