5
5
*/
6
6
namespace Magento \PageCache \Test \Unit \Model ;
7
7
8
+ use Magento \Framework \Serialize \Serializer \Json ;
9
+ use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
8
10
use Magento \PageCache \Model \Config ;
9
11
10
12
class ConfigTest extends \PHPUnit_Framework_TestCase
11
13
{
12
14
/**
13
15
* @var \Magento\PageCache\Model\Config
14
16
*/
15
- protected $ _model ;
17
+ private $ config ;
16
18
17
19
/**
18
20
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\Config\ScopeConfigInterface
19
21
*/
20
- protected $ _coreConfigMock ;
22
+ private $ coreConfigMock ;
21
23
22
24
/**
23
25
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\App\Cache\StateInterface
24
26
*/
25
- protected $ _cacheState ;
27
+ private $ cacheState ;
26
28
27
29
/**
28
30
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\Module\Dir\Reader
29
31
*/
30
- protected $ moduleReader ;
32
+ private $ moduleReader ;
33
+
34
+ /**
35
+ * @var \PHPUnit_Framework_MockObject_MockObject|Json
36
+ */
37
+ private $ serializerMock ;
31
38
32
39
/**
33
40
* setUp all mocks and data function
34
41
*/
35
42
protected function setUp ()
36
43
{
44
+ $ objectManager = new ObjectManager ($ this );
37
45
$ readFactoryMock = $ this ->getMock (
38
46
\Magento \Framework \Filesystem \Directory \ReadFactory::class,
39
47
[],
40
48
[],
41
49
'' ,
42
50
false
43
51
);
44
- $ this ->_coreConfigMock = $ this ->getMock (\Magento \Framework \App \Config \ScopeConfigInterface::class);
45
- $ this ->_cacheState = $ this ->getMockForAbstractClass (\Magento \Framework \App \Cache \StateInterface::class);
52
+ $ this ->coreConfigMock = $ this ->getMock (\Magento \Framework \App \Config \ScopeConfigInterface::class);
53
+ $ this ->cacheState = $ this ->getMockForAbstractClass (\Magento \Framework \App \Cache \StateInterface::class);
46
54
47
55
$ modulesDirectoryMock = $ this ->getMock (
48
56
\Magento \Framework \Filesystem \Directory \Write::class,
@@ -65,7 +73,7 @@ protected function setUp()
65
73
)->will (
66
74
$ this ->returnValue (file_get_contents (__DIR__ . '/_files/test.vcl ' ))
67
75
);
68
- $ this ->_coreConfigMock ->expects (
76
+ $ this ->coreConfigMock ->expects (
69
77
$ this ->any ()
70
78
)->method (
71
79
'getValue '
@@ -94,18 +102,23 @@ protected function setUp()
94
102
\Magento \PageCache \Model \Config::XML_VARNISH_PAGECACHE_DESIGN_THEME_REGEX ,
95
103
\Magento \Store \Model \ScopeInterface::SCOPE_STORE ,
96
104
null ,
97
- serialize ([[ ' regexp ' => ' (?i)pattern ' , ' value ' => ' value_for_pattern ' ]])
105
+ ' serializedConfig '
98
106
],
99
107
]
100
108
)
101
109
);
102
110
103
111
$ this ->moduleReader = $ this ->getMock (\Magento \Framework \Module \Dir \Reader::class, [], [], '' , false );
104
- $ this ->_model = new \Magento \PageCache \Model \Config (
105
- $ readFactoryMock ,
106
- $ this ->_coreConfigMock ,
107
- $ this ->_cacheState ,
108
- $ this ->moduleReader
112
+ $ this ->serializerMock = $ this ->getMock (Json::class, [], [], '' , false );
113
+ $ this ->config = $ objectManager ->getObject (
114
+ \Magento \PageCache \Model \Config::class,
115
+ [
116
+ 'readFactory ' => $ readFactoryMock ,
117
+ 'scopeConfig ' => $ this ->coreConfigMock ,
118
+ 'cacheState ' => $ this ->cacheState ,
119
+ 'reader ' => $ this ->moduleReader ,
120
+ 'serializer ' => $ this ->serializerMock ,
121
+ ]
109
122
);
110
123
}
111
124
@@ -117,30 +130,34 @@ public function testGetVcl()
117
130
$ this ->moduleReader ->expects ($ this ->once ())
118
131
->method ('getModuleDir ' )
119
132
->willReturn ('/magento/app/code/Magento/PageCache ' );
120
- $ test = $ this ->_model ->getVclFile (Config::VARNISH_3_CONFIGURATION_PATH );
133
+ $ this ->serializerMock ->expects ($ this ->once ())
134
+ ->method ('unserialize ' )
135
+ ->with ('serializedConfig ' )
136
+ ->willReturn ([['regexp ' => '(?i)pattern ' , 'value ' => 'value_for_pattern ' ]]);
137
+ $ test = $ this ->config ->getVclFile (Config::VARNISH_3_CONFIGURATION_PATH );
121
138
$ this ->assertEquals (file_get_contents (__DIR__ . '/_files/result.vcl ' ), $ test );
122
139
}
123
140
124
141
public function testGetTll ()
125
142
{
126
- $ this ->_coreConfigMock ->expects ($ this ->once ())->method ('getValue ' )->with (Config::XML_PAGECACHE_TTL );
127
- $ this ->_model ->getTtl ();
143
+ $ this ->coreConfigMock ->expects ($ this ->once ())->method ('getValue ' )->with (Config::XML_PAGECACHE_TTL );
144
+ $ this ->config ->getTtl ();
128
145
}
129
146
130
147
/**
131
148
* Whether a cache type is enabled
132
149
*/
133
150
public function testIsEnabled ()
134
151
{
135
- $ this ->_cacheState ->expects ($ this ->at (0 ))
152
+ $ this ->cacheState ->expects ($ this ->at (0 ))
136
153
->method ('isEnabled ' )
137
154
->with (\Magento \PageCache \Model \Cache \Type::TYPE_IDENTIFIER )
138
155
->will ($ this ->returnValue (true ));
139
- $ this ->_cacheState ->expects ($ this ->at (1 ))
156
+ $ this ->cacheState ->expects ($ this ->at (1 ))
140
157
->method ('isEnabled ' )
141
158
->with (\Magento \PageCache \Model \Cache \Type::TYPE_IDENTIFIER )
142
159
->will ($ this ->returnValue (false ));
143
- $ this ->assertTrue ($ this ->_model ->isEnabled ());
144
- $ this ->assertFalse ($ this ->_model ->isEnabled ());
160
+ $ this ->assertTrue ($ this ->config ->isEnabled ());
161
+ $ this ->assertFalse ($ this ->config ->isEnabled ());
145
162
}
146
163
}
0 commit comments