10
10
use \Magento \Framework \Filesystem \DriverPool ;
11
11
12
12
/**
13
- * Class ValidatorTest
14
- * @package Magento\Framework\View\Test\Unit\Element\Template\File
13
+ * Tests for Magento\Framework\View\Element\Template\File\Validator class.
15
14
*/
16
15
class ValidatorTest extends \PHPUnit \Framework \TestCase
17
16
{
18
17
/**
19
- * Resolver object
18
+ * Resolver object.
20
19
*
21
20
* @var \Magento\Framework\View\Element\Template\File\Validator
22
21
*/
23
- private $ _validator ;
22
+ private $ validator ;
24
23
25
24
/**
26
- * Mock for view file system
25
+ * Mock for view file system.
27
26
*
28
27
* @var \Magento\Framework\FileSystem|\PHPUnit_Framework_MockObject_MockObject
29
28
*/
30
- private $ _fileSystemMock ;
29
+ private $ fileSystemMock ;
31
30
32
31
/**
33
- * Mock for scope config
32
+ * Mock for scope config.
34
33
*
35
34
* @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
36
35
*/
37
- private $ _scopeConfigMock ;
36
+ private $ scopeConfigMock ;
38
37
39
38
/**
40
- * Mock for root directory reader
39
+ * Mock for root directory reader.
41
40
*
42
41
* @var \Magento\Framework\Filesystem\Directory\ReadInterface|\PHPUnit_Framework_MockObject_MockObject
43
42
*/
44
43
private $ rootDirectoryMock ;
45
44
46
45
/**
47
- * Mock for compiled directory reader
46
+ * Mock for compiled directory reader.
48
47
*
49
48
* @var \Magento\Framework\Filesystem\Directory\ReadInterface|\PHPUnit_Framework_MockObject_MockObject
50
49
*/
@@ -56,18 +55,16 @@ class ValidatorTest extends \PHPUnit\Framework\TestCase
56
55
private $ componentRegistrar ;
57
56
58
57
/**
59
- * Test Setup
60
- *
61
- * @return void
58
+ * @inheritdoc
62
59
*/
63
60
protected function setUp ()
64
61
{
65
- $ this ->_fileSystemMock = $ this ->createMock (\Magento \Framework \Filesystem::class);
66
- $ this ->_scopeConfigMock = $ this ->createMock (\Magento \Framework \App \Config \ScopeConfigInterface::class);
62
+ $ this ->fileSystemMock = $ this ->createMock (\Magento \Framework \Filesystem::class);
63
+ $ this ->scopeConfigMock = $ this ->createMock (\Magento \Framework \App \Config \ScopeConfigInterface::class);
67
64
$ this ->rootDirectoryMock = $ this ->createMock (\Magento \Framework \Filesystem \Directory \ReadInterface::class);
68
65
$ this ->compiledDirectoryMock = $ this ->createMock (\Magento \Framework \Filesystem \Directory \ReadInterface::class);
69
66
70
- $ this ->_fileSystemMock ->expects ($ this ->any ())
67
+ $ this ->fileSystemMock ->expects ($ this ->any ())
71
68
->method ('getDirectoryRead ' )
72
69
->will ($ this ->returnValueMap (
73
70
[
@@ -87,39 +84,46 @@ protected function setUp()
87
84
$ this ->returnValueMap (
88
85
[
89
86
[ComponentRegistrar::MODULE , ['/magento/app/code/Some/Module ' ]],
90
- [ComponentRegistrar::THEME , ['/magento/themes/default ' ]]
87
+ [ComponentRegistrar::THEME , ['/magento/themes/default ' ]],
91
88
]
92
89
)
93
90
);
94
- $ this ->_validator = new \Magento \Framework \View \Element \Template \File \Validator (
95
- $ this ->_fileSystemMock ,
96
- $ this ->_scopeConfigMock ,
97
- $ this ->componentRegistrar
91
+
92
+ $ fileDriverMock = $ this ->createMock (\Magento \Framework \Filesystem \Driver \File::class);
93
+ $ fileDriverMock ->expects ($ this ->any ())
94
+ ->method ('getRealPath ' )
95
+ ->willReturnArgument (0 );
96
+
97
+ $ this ->validator = new \Magento \Framework \View \Element \Template \File \Validator (
98
+ $ this ->fileSystemMock ,
99
+ $ this ->scopeConfigMock ,
100
+ $ this ->componentRegistrar ,
101
+ null ,
102
+ $ fileDriverMock
98
103
);
99
104
}
100
105
101
106
/**
102
- * Test is file valid
107
+ * Test is file valid.
103
108
*
104
109
* @param string $file
105
110
* @param bool $expectedResult
106
- *
107
- * @dataProvider testIsValidDataProvider
108
- *
109
111
* @return void
112
+ *
113
+ * @dataProvider isValidDataProvider
110
114
*/
111
- public function testIsValid ($ file , $ expectedResult )
115
+ public function testIsValid (string $ file , bool $ expectedResult )
112
116
{
113
117
$ this ->rootDirectoryMock ->expects ($ this ->any ())->method ('isFile ' )->will ($ this ->returnValue (true ));
114
- $ this ->assertEquals ($ expectedResult , $ this ->_validator ->isValid ($ file ));
118
+ $ this ->assertEquals ($ expectedResult , $ this ->validator ->isValid ($ file ));
115
119
}
116
120
117
121
/**
118
- * Data provider for testIsValid
122
+ * Data provider for testIsValid.
119
123
*
120
- * @return []
124
+ * @return array
121
125
*/
122
- public function testIsValidDataProvider ()
126
+ public function isValidDataProvider () : array
123
127
{
124
128
return [
125
129
'empty ' => ['' , false ],
0 commit comments