77
88namespace Magento \Framework \App \Test \Unit \Http ;
99
10+ use Magento \Framework \App \DeploymentConfig ;
1011use Magento \Framework \App \Http \Context ;
12+ use Magento \Framework \Config \ConfigOptionsListConstants ;
13+ use Magento \Framework \ObjectManagerInterface ;
1114use Magento \Framework \Serialize \Serializer \Json ;
1215use Magento \Framework \TestFramework \Unit \Helper \ObjectManager ;
1316use PHPUnit \Framework \MockObject \MockObject ;
@@ -25,13 +28,29 @@ class ContextTest extends TestCase
2528 */
2629 protected $ object ;
2730
31+ /**
32+ * @var DeploymentConfig|MockObject
33+ */
34+ private $ deploymentConfig ;
35+
36+ /**
37+ * @var ObjectManagerInterface|MockObject
38+ */
39+ private $ objectManagerMock ;
40+
2841 /**
2942 * @var Json|MockObject
3043 */
3144 private $ serializerMock ;
3245
3346 protected function setUp (): void
3447 {
48+ $ this ->objectManagerMock = $ this ->getMockBuilder (ObjectManagerInterface::class)
49+ ->disableOriginalConstructor ()
50+ ->onlyMethods (['create ' ])
51+ ->getMockForAbstractClass ();
52+ \Magento \Framework \App \ObjectManager::setInstance ($ this ->objectManagerMock );
53+
3554 $ this ->objectManager = new ObjectManager ($ this );
3655 $ this ->serializerMock = $ this ->getMockBuilder (Json::class)
3756 ->setMethods (['serialize ' ])
@@ -50,6 +69,10 @@ function ($value) {
5069 'serializer ' => $ this ->serializerMock
5170 ]
5271 );
72+ $ this ->deploymentConfig = $ this ->createPartialMock (
73+ DeploymentConfig::class,
74+ ['get ' ]
75+ );
5376 }
5477
5578 public function testGetValue ()
@@ -81,14 +104,28 @@ public function testGetData()
81104
82105 public function testGetVaryString ()
83106 {
107+ $ this ->objectManagerMock ->expects ($ this ->any ())
108+ ->method ('get ' )
109+ ->with (DeploymentConfig::class)
110+ ->willReturn ($ this ->deploymentConfig );
111+
112+ $ this ->deploymentConfig ->expects ($ this ->any ())
113+ ->method ('get ' )
114+ ->with (ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY )
115+ ->willReturn ('448198e08af35844a42d3c93c1ef4e03 ' );
116+
84117 $ this ->object ->setValue ('key2 ' , 'value2 ' , 'default2 ' );
85118 $ this ->object ->setValue ('key1 ' , 'value1 ' , 'default1 ' );
86119 $ data = [
87120 'key2 ' => 'value2 ' ,
88121 'key1 ' => 'value1 '
89122 ];
90123 ksort ($ data );
91- $ this ->assertEquals (sha1 (json_encode ($ data )), $ this ->object ->getVaryString ());
124+
125+ $ salt = $ this ->deploymentConfig ->get (ConfigOptionsListConstants::CONFIG_PATH_CRYPT_KEY );
126+ $ cacheKey = hash ('sha256 ' , $ this ->serializerMock ->serialize ($ data ) . '| ' . $ salt );
127+
128+ $ this ->assertEquals ($ cacheKey , $ this ->object ->getVaryString ());
92129 }
93130
94131 public function testToArray ()
0 commit comments