10
10
use Magento \Framework \App \Area ;
11
11
use Magento \Framework \App \CacheInterface ;
12
12
use Magento \Framework \App \DeploymentConfig ;
13
- use Magento \Framework \ObjectManagerInterface ;
14
13
use Magento \Framework \Serialize \Serializer \Json ;
15
14
use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
16
15
use Magento \Framework \View \Design \ThemeInterface ;
@@ -31,21 +30,24 @@ class ThemeProviderTest extends TestCase
31
30
/** Theme ID used by tests */
32
31
const THEME_ID = 755 ;
33
32
34
- /** @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager */
33
+ /** @var ObjectManagerHelper */
35
34
private $ objectManager ;
36
35
37
- /** @var \Magento\Theme\Model\ResourceModel\Theme\CollectionFactory| MockObject */
36
+ /** @var \Magento\Theme\Model\ResourceModel\Theme\CollectionFactory& MockObject */
38
37
private $ collectionFactory ;
39
38
40
- /** @var \Magento\Theme\Model\ThemeFactory| MockObject */
39
+ /** @var \Magento\Theme\Model\ThemeFactory& MockObject */
41
40
private $ themeFactory ;
42
41
43
- /** @var CacheInterface| MockObject */
42
+ /** @var CacheInterface& MockObject */
44
43
private $ cache ;
45
44
46
- /** @var Json| MockObject */
45
+ /** @var Json& MockObject */
47
46
private $ serializer ;
48
47
48
+ /** @var DeploymentConfig&MockObject */
49
+ private DeploymentConfig $ deploymentConfig ;
50
+
49
51
/** @var ThemeProvider|MockObject */
50
52
private $ themeProvider ;
51
53
@@ -64,13 +66,17 @@ protected function setUp(): void
64
66
->disableOriginalConstructor ()
65
67
->getMockForAbstractClass ();
66
68
$ this ->serializer = $ this ->createMock (Json::class);
69
+ $ this ->deploymentConfig = $ this ->getMockBuilder (DeploymentConfig::class)
70
+ ->disableOriginalConstructor ()
71
+ ->getMock ();
67
72
$ this ->themeProvider = $ this ->objectManager ->getObject (
68
73
ThemeProvider::class,
69
74
[
70
75
'collectionFactory ' => $ this ->collectionFactory ,
71
76
'themeFactory ' => $ this ->themeFactory ,
72
77
'cache ' => $ this ->cache ,
73
- 'serializer ' => $ this ->serializer
78
+ 'serializer ' => $ this ->serializer ,
79
+ 'deploymentConfig ' => $ this ->deploymentConfig ,
74
80
]
75
81
);
76
82
$ this ->theme = $ this ->createMock (Theme::class);
@@ -85,7 +91,6 @@ public function testGetByFullPath()
85
91
$ this ->theme ->expects ($ this ->exactly (2 ))
86
92
->method ('toArray ' )
87
93
->willReturn ($ themeArray );
88
-
89
94
$ collectionMock = $ this ->createMock (Collection::class);
90
95
$ collectionMock ->expects ($ this ->once ())
91
96
->method ('getThemeByFullPath ' )
@@ -98,22 +103,9 @@ public function testGetByFullPath()
98
103
->method ('serialize ' )
99
104
->with ($ themeArray )
100
105
->willReturn ('serialized theme ' );
101
-
102
- $ deploymentConfig = $ this ->getMockBuilder (DeploymentConfig::class)
103
- ->disableOriginalConstructor ()
104
- ->getMock ();
105
- $ deploymentConfig ->expects ($ this ->once ())
106
+ $ this ->deploymentConfig ->expects ($ this ->once ())
106
107
->method ('isDbAvailable ' )
107
108
->willReturn (true );
108
-
109
- $ objectManagerMock = $ this ->getMockForAbstractClass (ObjectManagerInterface::class);
110
- $ objectManagerMock ->expects ($ this ->any ())
111
- ->method ('get ' )
112
- ->willReturnMap ([
113
- [DeploymentConfig::class, $ deploymentConfig ],
114
- ]);
115
- \Magento \Framework \App \ObjectManager::setInstance ($ objectManagerMock );
116
-
117
109
$ this ->assertSame (
118
110
$ this ->theme ,
119
111
$ this ->themeProvider ->getThemeByFullPath (self ::THEME_PATH ),
@@ -128,21 +120,9 @@ public function testGetByFullPath()
128
120
129
121
public function testGetByFullPathWithCache ()
130
122
{
131
- $ deploymentConfig = $ this ->getMockBuilder (DeploymentConfig::class)
132
- ->disableOriginalConstructor ()
133
- ->getMock ();
134
- $ deploymentConfig ->expects ($ this ->once ())
123
+ $ this ->deploymentConfig ->expects ($ this ->once ())
135
124
->method ('isDbAvailable ' )
136
125
->willReturn (true );
137
-
138
- $ objectManagerMock = $ this ->getMockForAbstractClass (ObjectManagerInterface::class);
139
- $ objectManagerMock ->expects ($ this ->any ())
140
- ->method ('get ' )
141
- ->willReturnMap ([
142
- [DeploymentConfig::class, $ deploymentConfig ],
143
- ]);
144
- \Magento \Framework \App \ObjectManager::setInstance ($ objectManagerMock );
145
-
146
126
$ serializedTheme = '{"theme_data":"theme_data"} ' ;
147
127
$ themeArray = ['theme_data ' => 'theme_data ' ];
148
128
$ this ->theme ->expects ($ this ->once ())
@@ -152,17 +132,14 @@ public function testGetByFullPathWithCache()
152
132
$ this ->themeFactory ->expects ($ this ->once ())
153
133
->method ('create ' )
154
134
->willReturn ($ this ->theme );
155
-
156
135
$ this ->serializer ->expects ($ this ->once ())
157
136
->method ('unserialize ' )
158
137
->with ($ serializedTheme )
159
138
->willReturn ($ themeArray );
160
-
161
139
$ this ->cache ->expects ($ this ->once ())
162
140
->method ('load ' )
163
141
->with ('theme ' . self ::THEME_PATH )
164
142
->willReturn ($ serializedTheme );
165
-
166
143
$ this ->assertSame (
167
144
$ this ->theme ,
168
145
$ this ->themeProvider ->getThemeByFullPath (self ::THEME_PATH ),
0 commit comments