Passed
Pull Request — master (#72)
by Wilmer
01:24
created

TestCase   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 117
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 27
dl 0
loc 117
rs 10
c 0
b 0
f 0

6 Methods

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