@@ -29,6 +29,9 @@ class ThemePackageInfoTest extends \PHPUnit_Framework_TestCase
29
29
*/
30
30
private $ dirReadFactory ;
31
31
32
+ /** @var \Magento\Framework\Serialize\Serializer\Json|\PHPUnit_Framework_MockObject_MockObject */
33
+ private $ serializerMock ;
34
+
32
35
protected function setUp ()
33
36
{
34
37
$ this ->componentRegistrar = $ this ->getMock (
@@ -47,20 +50,27 @@ protected function setUp()
47
50
false
48
51
);
49
52
$ this ->dirReadFactory ->expects ($ this ->any ())->method ('create ' )->willReturn ($ this ->dirRead );
53
+ $ this ->serializerMock = $ this ->getMockBuilder (\Magento \Framework \Serialize \Serializer \Json::class)
54
+ ->getMock ();
50
55
$ this ->themePackageInfo = new ThemePackageInfo (
51
56
$ this ->componentRegistrar ,
52
- $ this ->dirReadFactory
57
+ $ this ->dirReadFactory ,
58
+ $ this ->serializerMock
53
59
);
54
60
}
55
61
56
62
public function testGetPackageName ()
57
63
{
64
+ $ themeFileContents = '{"name": "package"} ' ;
58
65
$ this ->componentRegistrar ->expects ($ this ->once ())->method ('getPath ' )->willReturn ('path/to/A ' );
59
66
$ this ->dirRead ->expects ($ this ->once ())->method ('isExist ' )->with ('composer.json ' )->willReturn (true );
60
67
$ this ->dirRead ->expects ($ this ->once ())
61
68
->method ('readFile ' )
62
69
->with ('composer.json ' )
63
- ->willReturn ('{"name": "package"} ' );
70
+ ->willReturn ($ themeFileContents );
71
+ $ this ->serializerMock ->expects ($ this ->once ())
72
+ ->method ('unserialize ' )
73
+ ->willReturn (json_decode ($ themeFileContents , true ));
64
74
$ this ->assertEquals ('package ' , $ this ->themePackageInfo ->getPackageName ('themeA ' ));
65
75
}
66
76
@@ -74,9 +84,13 @@ public function testGetPackageNameNonExist()
74
84
75
85
public function testGetFullThemePath ()
76
86
{
87
+ $ themeFileContents = '{"name": "package"} ' ;
77
88
$ this ->componentRegistrar ->expects ($ this ->once ())->method ('getPaths ' )->willReturn (['themeA ' => 'path/to/A ' ]);
78
89
$ this ->dirRead ->expects ($ this ->once ())->method ('isExist ' )->willReturn (true );
79
- $ this ->dirRead ->expects ($ this ->once ())->method ('readFile ' )->willReturn ('{"name": "package"} ' );
90
+ $ this ->dirRead ->expects ($ this ->once ())->method ('readFile ' )->willReturn ($ themeFileContents );
91
+ $ this ->serializerMock ->expects ($ this ->once ())
92
+ ->method ('unserialize ' )
93
+ ->willReturn (json_decode ($ themeFileContents , true ));
80
94
$ this ->assertEquals ('themeA ' , $ this ->themePackageInfo ->getFullThemePath ('package ' ));
81
95
// call one more time to make sure only initialize once
82
96
$ this ->assertEquals ('themeA ' , $ this ->themePackageInfo ->getFullThemePath ('package ' ));
@@ -90,14 +104,14 @@ public function testGetFullThemePathNonExist()
90
104
$ this ->assertEquals ('' , $ this ->themePackageInfo ->getFullThemePath ('package-other ' ));
91
105
}
92
106
93
- /**
94
- * @expectedException \Zend_Json_Exception
95
- */
96
107
public function testGetPackageNameInvalidJson ()
97
108
{
98
109
$ this ->componentRegistrar ->expects ($ this ->once ())->method ('getPath ' )->willReturn ('path/to/A ' );
99
110
$ this ->dirRead ->expects ($ this ->once ())->method ('isExist ' )->willReturn (true );
100
111
$ this ->dirRead ->expects ($ this ->once ())->method ('readFile ' )->willReturn ('{"name": } ' );
101
- $ this ->themePackageInfo ->getPackageName ('themeA ' );
112
+ $ this ->serializerMock ->expects ($ this ->once ())
113
+ ->method ('unserialize ' )
114
+ ->willReturn (null );
115
+ $ this ->assertEquals ('' , $ this ->themePackageInfo ->getPackageName ('themeA ' ));
102
116
}
103
117
}
0 commit comments