1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Yiisoft\View\Tests; |
6
|
|
|
|
7
|
|
|
use hiqdev\composer\config\Builder; |
8
|
|
|
use PHPUnit\Framework\TestCase as BaseTestCase; |
9
|
|
|
use Psr\Container\ContainerInterface; |
10
|
|
|
use Psr\EventDispatcher\EventDispatcherInterface; |
11
|
|
|
use Psr\EventDispatcher\ListenerProviderInterface; |
12
|
|
|
use Psr\Log\LoggerInterface; |
13
|
|
|
use Yiisoft\Aliases\Aliases; |
14
|
|
|
use Yiisoft\Di\Container; |
15
|
|
|
use Yiisoft\Files\FileHelper; |
16
|
|
|
use Yiisoft\View\Theme; |
17
|
|
|
use Yiisoft\View\View; |
18
|
|
|
use Yiisoft\View\WebView; |
19
|
|
|
|
20
|
|
|
abstract class TestCase extends BaseTestCase |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var Aliases $aliases |
24
|
|
|
*/ |
25
|
|
|
protected $aliases; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var ContainerInterface $container |
29
|
|
|
*/ |
30
|
|
|
private $container; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var EventDispatcherInterface $eventDispatcher |
34
|
|
|
*/ |
35
|
|
|
protected $eventDispatcher; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var LoggerInterface $logger |
39
|
|
|
*/ |
40
|
|
|
protected $logger; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var Theme $theme |
44
|
|
|
*/ |
45
|
|
|
protected $theme; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var WebView $webView |
49
|
|
|
*/ |
50
|
|
|
protected $webView; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var ListenerProviderInterface |
54
|
|
|
*/ |
55
|
|
|
protected $listenerProvider; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* setUp |
59
|
|
|
* |
60
|
|
|
* @return void |
61
|
|
|
*/ |
62
|
|
|
protected function setUp(): void |
63
|
|
|
{ |
64
|
|
|
parent::setUp(); |
65
|
|
|
|
66
|
|
|
$config = require Builder::path('tests'); |
67
|
|
|
|
68
|
|
|
$this->container = new Container($config); |
69
|
|
|
|
70
|
|
|
$this->aliases = $this->container->get(Aliases::class); |
71
|
|
|
$this->eventDispatcher = $this->container->get(EventDispatcherInterface::class); |
72
|
|
|
$this->listenerProvider = $this->container->get(ListenerProviderInterface::class); |
73
|
|
|
$this->logger = $this->container->get(LoggerInterface::class); |
74
|
|
|
$this->webView = $this->container->get(WebView::class); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* tearDown |
79
|
|
|
* |
80
|
|
|
* @return void |
81
|
|
|
*/ |
82
|
|
|
protected function tearDown(): void |
83
|
|
|
{ |
84
|
|
|
$this->container = null; |
85
|
|
|
parent::tearDown(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Asserting two strings equality ignoring line endings. |
90
|
|
|
* @param string $expected |
91
|
|
|
* @param string $actual |
92
|
|
|
* @param string $message |
93
|
|
|
* |
94
|
|
|
* @return void |
95
|
|
|
*/ |
96
|
|
|
protected function assertEqualsWithoutLE(string $expected, string $actual, string $message = ''): void |
97
|
|
|
{ |
98
|
|
|
$expected = str_replace("\r\n", "\n", $expected); |
99
|
|
|
$actual = str_replace("\r\n", "\n", $actual); |
100
|
|
|
|
101
|
|
|
$this->assertEquals($expected, $actual, $message); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Asserting same ignoring slash. |
106
|
|
|
* |
107
|
|
|
* @param string $expected |
108
|
|
|
* @param string $actual |
109
|
|
|
* |
110
|
|
|
* @return void |
111
|
|
|
*/ |
112
|
|
|
protected function assertSameIgnoringSlash(string $expected, string $actual): void |
113
|
|
|
{ |
114
|
|
|
$expected = str_replace(['/', '\\'], '/', $expected); |
115
|
|
|
$actual = str_replace(['/', '\\'], '/', $actual); |
116
|
|
|
$this->assertSame($expected, $actual); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* Create view tests. |
121
|
|
|
* |
122
|
|
|
* @param string $basePath |
123
|
|
|
* @param Theme $theme |
124
|
|
|
* |
125
|
|
|
* @return View |
126
|
|
|
*/ |
127
|
|
|
protected function createView($basePath, Theme $theme = null): View |
128
|
|
|
{ |
129
|
|
|
return new View($basePath, $theme ?: new Theme(), $this->eventDispatcher, $this->logger); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
protected function touch(string $path): void |
133
|
|
|
{ |
134
|
|
|
FileHelper::createDirectory(dirname($path)); |
135
|
|
|
|
136
|
|
|
touch($path); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|