|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Yii\Widgets\Tests; |
|
6
|
|
|
|
|
7
|
|
|
use Yiisoft\Composer\Config\Builder; |
|
8
|
|
|
use PHPUnit\Framework\TestCase as BaseTestCase; |
|
9
|
|
|
use Psr\Container\ContainerInterface; |
|
10
|
|
|
use Yiisoft\Aliases\Aliases; |
|
11
|
|
|
use Yiisoft\Asset\AssetBundle; |
|
12
|
|
|
use Yiisoft\Asset\AssetManager; |
|
13
|
|
|
use Yiisoft\Cache\CacheInterface; |
|
14
|
|
|
use Yiisoft\Di\Container; |
|
15
|
|
|
use Yiisoft\View\WebView; |
|
16
|
|
|
use Yiisoft\Widget\WidgetFactory; |
|
17
|
|
|
|
|
18
|
|
|
abstract class TestCase extends BaseTestCase |
|
19
|
|
|
{ |
|
20
|
|
|
protected Aliases $aliases; |
|
21
|
|
|
protected CacheInterface $cache; |
|
22
|
|
|
private ContainerInterface $container; |
|
23
|
|
|
protected WebView $webView; |
|
24
|
|
|
|
|
25
|
|
|
protected function setUp(): void |
|
26
|
|
|
{ |
|
27
|
|
|
parent::setUp(); |
|
28
|
|
|
|
|
29
|
|
|
$config = require Builder::path('tests'); |
|
30
|
|
|
|
|
31
|
|
|
$this->container = new Container($config); |
|
32
|
|
|
|
|
33
|
|
|
$this->aliases = $this->container->get(Aliases::class); |
|
34
|
|
|
$this->cache = $this->container->get(CacheInterface::class); |
|
35
|
|
|
$this->webView = $this->container->get(WebView::class); |
|
36
|
|
|
|
|
37
|
|
|
WidgetFactory::initialize($this->container, []); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
protected function tearDown(): void |
|
41
|
|
|
{ |
|
42
|
|
|
unset($this->container, $this->webView); |
|
43
|
|
|
parent::tearDown(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Asserting two strings equality ignoring line endings. |
|
48
|
|
|
* @param string $expected |
|
49
|
|
|
* @param string $actual |
|
50
|
|
|
* @param string $message |
|
51
|
|
|
* |
|
52
|
|
|
* @return void |
|
53
|
|
|
*/ |
|
54
|
|
|
protected function assertEqualsWithoutLE(string $expected, string $actual, string $message = ''): void |
|
55
|
|
|
{ |
|
56
|
|
|
$expected = str_replace("\r\n", "\n", $expected); |
|
57
|
|
|
$actual = str_replace("\r\n", "\n", $actual); |
|
58
|
|
|
|
|
59
|
|
|
$this->assertEquals($expected, $actual, $message); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Asserting same ignoring slash. |
|
64
|
|
|
* |
|
65
|
|
|
* @param string $expected |
|
66
|
|
|
* @param string $actual |
|
67
|
|
|
* |
|
68
|
|
|
* @return void |
|
69
|
|
|
*/ |
|
70
|
|
|
protected function assertSameIgnoringSlash(string $expected, string $actual): void |
|
71
|
|
|
{ |
|
72
|
|
|
$expected = str_replace(['/', '\\'], '/', $expected); |
|
73
|
|
|
$actual = str_replace(['/', '\\'], '/', $actual); |
|
74
|
|
|
$this->assertSame($expected, $actual); |
|
75
|
|
|
} |
|
76
|
|
|
} |
|
77
|
|
|
|