|
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']) |
|
|
|
|
|
|
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(); |
|
|
|
|
|
|
98
|
|
|
|
|
99
|
|
|
$config = new ViewsConfig([ |
|
100
|
|
|
'dependencies' => [ |
|
101
|
|
|
$this, |
|
102
|
|
|
], |
|
103
|
|
|
]); |
|
104
|
|
|
|
|
105
|
|
|
$config->getDependencies(); |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|