1
1
<?php
2
2
/**
3
- * Copyright © Magento, Inc. All rights reserved.
4
- * See COPYING.txt for license details .
3
+ * Copyright 2019 Adobe
4
+ * All Rights Reserved .
5
5
*/
6
6
declare (strict_types=1 );
7
7
8
8
namespace Magento \Framework \Cache \Test \Unit ;
9
9
10
+ use Magento \Framework \App \DeploymentConfig ;
10
11
use Magento \Framework \Cache \LockGuardedCacheLoader ;
11
12
use Magento \Framework \Lock \LockManagerInterface ;
12
- use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
13
13
use PHPUnit \Framework \MockObject \MockObject ;
14
14
use PHPUnit \Framework \TestCase ;
15
15
@@ -20,25 +20,27 @@ class LockGuardedCacheLoaderTest extends TestCase
20
20
*/
21
21
private $ lockManagerInterfaceMock ;
22
22
23
+ /**
24
+ * @var DeploymentConfig|MockObject
25
+ */
26
+ private $ deploymentConfigMock ;
27
+
23
28
/**
24
29
* @var LockGuardedCacheLoader
25
30
*/
26
- private $ LockGuardedCacheLoader ;
31
+ private $ lockGuardedCacheLoader ;
27
32
28
33
/**
29
34
* @inheritDoc
30
35
*/
31
36
protected function setUp (): void
32
37
{
33
- $ this ->lockManagerInterfaceMock = $ this ->getMockForAbstractClass (LockManagerInterface::class);
38
+ $ this ->lockManagerInterfaceMock = $ this ->createMock (LockManagerInterface::class);
39
+ $ this ->deploymentConfigMock = $ this ->createMock (DeploymentConfig::class);
34
40
35
- $ objectManager = new ObjectManagerHelper ($ this );
36
-
37
- $ this ->LockGuardedCacheLoader = $ objectManager ->getObject (
38
- LockGuardedCacheLoader::class,
39
- [
40
- 'locker ' => $ this ->lockManagerInterfaceMock
41
- ]
41
+ $ this ->lockGuardedCacheLoader = new LockGuardedCacheLoader (
42
+ $ this ->lockManagerInterfaceMock ,
43
+ deploymentConfig: $ this ->deploymentConfigMock
42
44
);
43
45
}
44
46
@@ -63,12 +65,16 @@ public function testOptimisticDataRead(): void
63
65
return true ;
64
66
};
65
67
68
+ $ this ->deploymentConfigMock ->expects ($ this ->once ())
69
+ ->method ('get ' )
70
+ ->with ('cache/allow_parallel_generation ' )
71
+ ->willReturn (false );
66
72
$ this ->lockManagerInterfaceMock ->expects ($ this ->never ())->method ('lock ' );
67
73
$ this ->lockManagerInterfaceMock ->expects ($ this ->never ())->method ('unlock ' );
68
74
69
75
$ this ->assertEquals (
70
76
'loaded_data ' ,
71
- $ this ->LockGuardedCacheLoader ->lockedLoadData ($ lockName , $ dataLoader , $ dataCollector , $ dataSaver )
77
+ $ this ->lockGuardedCacheLoader ->lockedLoadData ($ lockName , $ dataLoader , $ dataCollector , $ dataSaver )
72
78
);
73
79
}
74
80
@@ -93,16 +99,19 @@ public function testDataCollectedAfterDeadlineReached(): void
93
99
return true ;
94
100
};
95
101
102
+ $ this ->deploymentConfigMock ->expects ($ this ->once ())
103
+ ->method ('get ' )
104
+ ->with ('cache/allow_parallel_generation ' )
105
+ ->willReturn (false );
96
106
$ this ->lockManagerInterfaceMock
97
107
->expects ($ this ->atLeastOnce ())->method ('lock ' )
98
108
->with ($ lockName , 0 )
99
109
->willReturn (false );
100
-
101
110
$ this ->lockManagerInterfaceMock ->expects ($ this ->never ())->method ('unlock ' );
102
111
103
112
$ this ->assertEquals (
104
113
'collected_data ' ,
105
- $ this ->LockGuardedCacheLoader ->lockedLoadData ($ lockName , $ dataLoader , $ dataCollector , $ dataSaver )
114
+ $ this ->lockGuardedCacheLoader ->lockedLoadData ($ lockName , $ dataLoader , $ dataCollector , $ dataSaver )
106
115
);
107
116
}
108
117
@@ -127,16 +136,19 @@ public function testDataWrite(): void
127
136
return true ;
128
137
};
129
138
139
+ $ this ->deploymentConfigMock ->expects ($ this ->once ())
140
+ ->method ('get ' )
141
+ ->with ('cache/allow_parallel_generation ' )
142
+ ->willReturn (false );
130
143
$ this ->lockManagerInterfaceMock
131
144
->expects ($ this ->once ())->method ('lock ' )
132
145
->with ($ lockName , 0 )
133
146
->willReturn (true );
134
-
135
147
$ this ->lockManagerInterfaceMock ->expects ($ this ->once ())->method ('unlock ' );
136
148
137
149
$ this ->assertEquals (
138
150
'collected_data ' ,
139
- $ this ->LockGuardedCacheLoader ->lockedLoadData ($ lockName , $ dataLoader , $ dataCollector , $ dataSaver )
151
+ $ this ->lockGuardedCacheLoader ->lockedLoadData ($ lockName , $ dataLoader , $ dataCollector , $ dataSaver )
140
152
);
141
153
}
142
154
@@ -161,21 +173,19 @@ public function testDataCollectedWithParallelGeneration(): void
161
173
return true ;
162
174
};
163
175
164
- $ closure = \Closure::bind (function ($ cacheLoader ) {
165
- return $ cacheLoader ->allowParallelGenerationConfigValue = true ;
166
- }, null , $ this ->LockGuardedCacheLoader );
167
- $ closure ($ this ->LockGuardedCacheLoader );
168
-
176
+ $ this ->deploymentConfigMock ->expects ($ this ->once ())
177
+ ->method ('get ' )
178
+ ->with ('cache/allow_parallel_generation ' )
179
+ ->willReturn (true );
169
180
$ this ->lockManagerInterfaceMock
170
181
->expects ($ this ->once ())->method ('lock ' )
171
182
->with ($ lockName , 0 )
172
183
->willReturn (false );
173
-
174
184
$ this ->lockManagerInterfaceMock ->expects ($ this ->never ())->method ('unlock ' );
175
185
176
186
$ this ->assertEquals (
177
187
'collected_data ' ,
178
- $ this ->LockGuardedCacheLoader ->lockedLoadData ($ lockName , $ dataLoader , $ dataCollector , $ dataSaver )
188
+ $ this ->lockGuardedCacheLoader ->lockedLoadData ($ lockName , $ dataLoader , $ dataCollector , $ dataSaver )
179
189
);
180
190
}
181
191
}
0 commit comments