11<?php
22/**
3- * Copyright © Magento, Inc. All rights reserved.
4- * See COPYING.txt for license details .
3+ * Copyright 2019 Adobe
4+ * All Rights Reserved .
55 */
66declare (strict_types=1 );
77
88namespace Magento \Framework \Cache \Test \Unit ;
99
10+ use Magento \Framework \App \DeploymentConfig ;
1011use Magento \Framework \Cache \LockGuardedCacheLoader ;
1112use Magento \Framework \Lock \LockManagerInterface ;
12- use Magento \Framework \TestFramework \Unit \Helper \ObjectManager as ObjectManagerHelper ;
1313use PHPUnit \Framework \MockObject \MockObject ;
1414use PHPUnit \Framework \TestCase ;
1515
@@ -20,25 +20,27 @@ class LockGuardedCacheLoaderTest extends TestCase
2020 */
2121 private $ lockManagerInterfaceMock ;
2222
23+ /**
24+ * @var DeploymentConfig|MockObject
25+ */
26+ private $ deploymentConfigMock ;
27+
2328 /**
2429 * @var LockGuardedCacheLoader
2530 */
26- private $ LockGuardedCacheLoader ;
31+ private $ lockGuardedCacheLoader ;
2732
2833 /**
2934 * @inheritDoc
3035 */
3136 protected function setUp (): void
3237 {
33- $ this ->lockManagerInterfaceMock = $ this ->getMockForAbstractClass (LockManagerInterface::class);
38+ $ this ->lockManagerInterfaceMock = $ this ->createMock (LockManagerInterface::class);
39+ $ this ->deploymentConfigMock = $ this ->createMock (DeploymentConfig::class);
3440
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
4244 );
4345 }
4446
@@ -63,12 +65,16 @@ public function testOptimisticDataRead(): void
6365 return true ;
6466 };
6567
68+ $ this ->deploymentConfigMock ->expects ($ this ->once ())
69+ ->method ('get ' )
70+ ->with ('cache/allow_parallel_generation ' )
71+ ->willReturn (false );
6672 $ this ->lockManagerInterfaceMock ->expects ($ this ->never ())->method ('lock ' );
6773 $ this ->lockManagerInterfaceMock ->expects ($ this ->never ())->method ('unlock ' );
6874
6975 $ this ->assertEquals (
7076 'loaded_data ' ,
71- $ this ->LockGuardedCacheLoader ->lockedLoadData ($ lockName , $ dataLoader , $ dataCollector , $ dataSaver )
77+ $ this ->lockGuardedCacheLoader ->lockedLoadData ($ lockName , $ dataLoader , $ dataCollector , $ dataSaver )
7278 );
7379 }
7480
@@ -93,16 +99,19 @@ public function testDataCollectedAfterDeadlineReached(): void
9399 return true ;
94100 };
95101
102+ $ this ->deploymentConfigMock ->expects ($ this ->once ())
103+ ->method ('get ' )
104+ ->with ('cache/allow_parallel_generation ' )
105+ ->willReturn (false );
96106 $ this ->lockManagerInterfaceMock
97107 ->expects ($ this ->atLeastOnce ())->method ('lock ' )
98108 ->with ($ lockName , 0 )
99109 ->willReturn (false );
100-
101110 $ this ->lockManagerInterfaceMock ->expects ($ this ->never ())->method ('unlock ' );
102111
103112 $ this ->assertEquals (
104113 'collected_data ' ,
105- $ this ->LockGuardedCacheLoader ->lockedLoadData ($ lockName , $ dataLoader , $ dataCollector , $ dataSaver )
114+ $ this ->lockGuardedCacheLoader ->lockedLoadData ($ lockName , $ dataLoader , $ dataCollector , $ dataSaver )
106115 );
107116 }
108117
@@ -127,16 +136,19 @@ public function testDataWrite(): void
127136 return true ;
128137 };
129138
139+ $ this ->deploymentConfigMock ->expects ($ this ->once ())
140+ ->method ('get ' )
141+ ->with ('cache/allow_parallel_generation ' )
142+ ->willReturn (false );
130143 $ this ->lockManagerInterfaceMock
131144 ->expects ($ this ->once ())->method ('lock ' )
132145 ->with ($ lockName , 0 )
133146 ->willReturn (true );
134-
135147 $ this ->lockManagerInterfaceMock ->expects ($ this ->once ())->method ('unlock ' );
136148
137149 $ this ->assertEquals (
138150 'collected_data ' ,
139- $ this ->LockGuardedCacheLoader ->lockedLoadData ($ lockName , $ dataLoader , $ dataCollector , $ dataSaver )
151+ $ this ->lockGuardedCacheLoader ->lockedLoadData ($ lockName , $ dataLoader , $ dataCollector , $ dataSaver )
140152 );
141153 }
142154
@@ -161,21 +173,19 @@ public function testDataCollectedWithParallelGeneration(): void
161173 return true ;
162174 };
163175
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 );
169180 $ this ->lockManagerInterfaceMock
170181 ->expects ($ this ->once ())->method ('lock ' )
171182 ->with ($ lockName , 0 )
172183 ->willReturn (false );
173-
174184 $ this ->lockManagerInterfaceMock ->expects ($ this ->never ())->method ('unlock ' );
175185
176186 $ this ->assertEquals (
177187 'collected_data ' ,
178- $ this ->LockGuardedCacheLoader ->lockedLoadData ($ lockName , $ dataLoader , $ dataCollector , $ dataSaver )
188+ $ this ->lockGuardedCacheLoader ->lockedLoadData ($ lockName , $ dataLoader , $ dataCollector , $ dataSaver )
179189 );
180190 }
181191}
0 commit comments