@@ -27,6 +27,11 @@ class DirTest extends \PHPUnit_Framework_TestCase
27
27
*/
28
28
protected $ directoryMock ;
29
29
30
+ /**
31
+ * @var \Magento\Framework\Module\Dir\ResolverInterface|\PHPUnit_Framework_MockObject_MockObject
32
+ */
33
+ protected $ dirResolverMock ;
34
+
30
35
protected function setUp ()
31
36
{
32
37
$ this ->filesystemMock = $ this ->getMock ('Magento\Framework\Filesystem ' , [], [], '' , false , false );
@@ -39,8 +44,14 @@ protected function setUp()
39
44
false
40
45
);
41
46
$ this ->_stringMock = $ this ->getMock ('Magento\Framework\Stdlib\String ' , [], [], '' , false , false );
42
-
43
- $ this ->_stringMock ->expects ($ this ->once ())->method ('upperCaseWords ' )->will ($ this ->returnValue ('Test/Module ' ));
47
+ $ this ->dirResolverMock = $ this ->getMock (
48
+ 'Magento\Framework\Module\Dir\ResolverInterface ' ,
49
+ [],
50
+ [],
51
+ '' ,
52
+ false ,
53
+ false
54
+ );
44
55
45
56
$ this ->filesystemMock ->expects (
46
57
$ this ->once ()
@@ -50,11 +61,27 @@ protected function setUp()
50
61
$ this ->returnValue ($ this ->directoryMock )
51
62
);
52
63
53
- $ this ->_model = new \Magento \Framework \Module \Dir ($ this ->filesystemMock , $ this ->_stringMock );
64
+ $ this ->_model = new \Magento \Framework \Module \Dir (
65
+ $ this ->filesystemMock ,
66
+ $ this ->_stringMock ,
67
+ $ this ->dirResolverMock
68
+ );
54
69
}
55
70
56
71
public function testGetDirModuleRoot ()
57
72
{
73
+ $ this ->dirResolverMock ->expects (
74
+ $ this ->once ()
75
+ )->method (
76
+ 'getModulePath '
77
+ )->with (
78
+ 'Test_Module '
79
+ )->will (
80
+ $ this ->returnValue (null )
81
+ );
82
+
83
+ $ this ->_stringMock ->expects ($ this ->once ())->method ('upperCaseWords ' )->will ($ this ->returnValue ('Test/Module ' ));
84
+
58
85
$ this ->directoryMock ->expects (
59
86
$ this ->once ()
60
87
)->method (
@@ -64,20 +91,39 @@ public function testGetDirModuleRoot()
64
91
)->will (
65
92
$ this ->returnValue ('/Test/Module ' )
66
93
);
94
+
67
95
$ this ->assertEquals ('/Test/Module ' , $ this ->_model ->getDir ('Test_Module ' ));
68
96
}
69
97
98
+ public function testGetDirModuleRootFromResolver ()
99
+ {
100
+ $ this ->dirResolverMock ->expects (
101
+ $ this ->once ()
102
+ )->method (
103
+ 'getModulePath '
104
+ )->with (
105
+ 'Test_Module2 '
106
+ )->will (
107
+ $ this ->returnValue ('/path/to/module ' )
108
+ );
109
+
110
+ $ this ->assertEquals ('/path/to/module ' , $ this ->_model ->getDir ('Test_Module2 ' ));
111
+ }
112
+
70
113
public function testGetDirModuleSubDir ()
71
114
{
115
+ $ this ->_stringMock ->expects ($ this ->once ())->method ('upperCaseWords ' )->will ($ this ->returnValue ('Test/Module ' ));
116
+
72
117
$ this ->directoryMock ->expects (
73
118
$ this ->once ()
74
119
)->method (
75
120
'getAbsolutePath '
76
121
)->with (
77
- 'Test/Module/etc '
122
+ 'Test/Module '
78
123
)->will (
79
- $ this ->returnValue ('/Test/Module/etc ' )
124
+ $ this ->returnValue ('/Test/Module ' )
80
125
);
126
+
81
127
$ this ->assertEquals ('/Test/Module/etc ' , $ this ->_model ->getDir ('Test_Module ' , 'etc ' ));
82
128
}
83
129
@@ -87,6 +133,8 @@ public function testGetDirModuleSubDir()
87
133
*/
88
134
public function testGetDirModuleSubDirUnknown ()
89
135
{
136
+ $ this ->_stringMock ->expects ($ this ->once ())->method ('upperCaseWords ' )->will ($ this ->returnValue ('Test/Module ' ));
137
+
90
138
$ this ->_model ->getDir ('Test_Module ' , 'unknown ' );
91
139
}
92
140
}
0 commit comments