Passed
Push — master ( 72c793...7f699f )
by Kirill
03:22
created

ConfigTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 40
c 1
b 0
f 0
dl 0
loc 84
rs 10
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testDependencies() 0 17 1
A testNamespace() 0 11 1
A testEngines() 0 20 1
A testCache() 0 11 1
A testDependenciesError() 0 13 1
1
<?php
2
3
/**
4
 * Spiral Framework.
5
 *
6
 * @license   MIT
7
 * @author    Anton Titov (Wolfy-J)
8
 */
9
10
declare(strict_types=1);
11
12
namespace Spiral\Tests\Views;
13
14
use PHPUnit\Framework\TestCase;
15
use Spiral\Core\Container;
16
use Spiral\Core\Container\Autowire;
17
use Spiral\Views\Config\ViewsConfig;
18
use Spiral\Views\Context\ValueDependency;
19
use Spiral\Views\Engine\Native\NativeEngine;
20
use Spiral\Views\Exception\ConfigException;
21
22
class ConfigTest extends TestCase
23
{
24
    public function testCache(): void
25
    {
26
        $config = new ViewsConfig([
27
            'cache' => [
28
                'enable'    => true,
29
                'directory' => '/tmp',
30
            ],
31
        ]);
32
33
        $this->assertTrue($config->isCacheEnabled());
34
        $this->assertSame('/tmp/', $config->getCacheDirectory());
35
    }
36
37
    public function testNamespace(): void
38
    {
39
        $config = new ViewsConfig([
40
            'namespaces' => [
41
                'default' => [__DIR__],
42
            ],
43
        ]);
44
45
        $this->assertSame([
46
            'default' => [__DIR__],
47
        ], $config->getNamespaces());
48
    }
49
50
    public function testEngines(): void
51
    {
52
        $container = new Container();
53
54
        $config = new ViewsConfig([
55
            'engines' => [new Autowire(NativeEngine::class)],
56
        ]);
57
58
        $this->assertInstanceOf(
59
            NativeEngine::class,
60
            $config->getEngines()[0]->resolve($container)
61
        );
62
63
        $config = new ViewsConfig([
64
            'engines' => [NativeEngine::class],
65
        ]);
66
67
        $this->assertInstanceOf(
68
            NativeEngine::class,
69
            $config->getEngines()[0]->resolve($container)
70
        );
71
    }
72
73
    public function testDependencies(): void
74
    {
75
        $container = new Container();
76
        $container->bindSingleton(
77
            'localeDependency',
78
            $dependency = new ValueDependency('locale', 'en', ['en', 'ru'])
0 ignored issues
show
Bug introduced by
$dependency = new Spiral...en', array('en', 'ru')) of type Spiral\Views\Context\ValueDependency is incompatible with the type array|callable|string expected by parameter $resolver of Spiral\Core\Container::bindSingleton(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

78
            /** @scrutinizer ignore-type */ $dependency = new ValueDependency('locale', 'en', ['en', 'ru'])
Loading history...
79
        );
80
81
        $config = new ViewsConfig([
82
            'dependencies' => [
83
                'localeDependency',
84
            ],
85
        ]);
86
87
        $this->assertSame(
88
            $dependency,
89
            $config->getDependencies()[0]->resolve($container)
90
        );
91
    }
92
93
    public function testDependenciesError(): void
94
    {
95
        $this->expectException(ConfigException::class);
96
97
        $container = new Container();
0 ignored issues
show
Unused Code introduced by
The assignment to $container is dead and can be removed.
Loading history...
98
99
        $config = new ViewsConfig([
100
            'dependencies' => [
101
                $this,
102
            ],
103
        ]);
104
105
        $config->getDependencies();
106
    }
107
}
108