Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ConfigCacheTest.php
Go to the documentation of this file.
1 <?php
7 
9 
10 class ConfigCacheTest extends \PHPUnit\Framework\TestCase
11 {
15  private $configCache;
16 
20  private $cacheFrontendMock;
21 
25  private $serializerMock;
26 
27  protected function setUp()
28  {
29  $objectManagerHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
30  $this->cacheFrontendMock = $this->createMock(\Magento\Framework\Cache\FrontendInterface::class);
31  $this->configCache = $objectManagerHelper->getObject(
32  \Magento\Framework\App\ObjectManager\ConfigCache::class,
33  ['cacheFrontend' => $this->cacheFrontendMock]
34  );
35 
36  $this->serializerMock = $this->createMock(SerializerInterface::class);
37  $objectManagerHelper->setBackwardCompatibleProperty(
38  $this->configCache,
39  'serializer',
40  $this->serializerMock
41  );
42  }
43 
44  protected function tearDown()
45  {
46  unset($this->configCache);
47  }
48 
55  public function testGet($data, $expectedResult, $unserializeCalledNum = 1)
56  {
57  $key = 'key';
58  $this->cacheFrontendMock->expects($this->once())
59  ->method('load')
60  ->with('diConfig' . $key)
61  ->willReturn($data);
62  $this->serializerMock->expects($this->exactly($unserializeCalledNum))
63  ->method('unserialize')
64  ->with($data)
65  ->willReturn($expectedResult);
66  $this->assertEquals($expectedResult, $this->configCache->get($key));
67  }
68 
72  public function getDataProvider()
73  {
74  return [
75  [false, false, 0],
76  ['serialized data', ['some data']],
77  ];
78  }
79 
80  public function testSave()
81  {
82  $key = 'key';
83  $config = ['config'];
84  $serializedData = 'serialized data';
85  $this->serializerMock->expects($this->once())
86  ->method('serialize')
87  ->willReturn($serializedData);
88  $this->cacheFrontendMock->expects($this->once())->method('save')->with($serializedData, 'diConfig' . $key);
89  $this->configCache->save($config, $key);
90  }
91 }
$config
Definition: fraud_order.php:17
testGet($data, $expectedResult, $unserializeCalledNum=1)