Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
IntegrationConfigTest.php
Go to the documentation of this file.
1 <?php
7 
11 
15 class IntegrationConfigTest extends \PHPUnit\Framework\TestCase
16 {
20  private $integrationConfigModel;
21 
25  private $configCacheTypeMock;
26 
30  private $configReaderMock;
31 
35  private $serializer;
36 
37  protected function setUp()
38  {
39  $this->configCacheTypeMock = $this->getMockBuilder(\Magento\Integration\Model\Cache\TypeIntegration::class)
40  ->disableOriginalConstructor()
41  ->getMock();
42  $this->configReaderMock = $this->getMockBuilder(\Magento\Integration\Model\Config\Integration\Reader::class)
43  ->disableOriginalConstructor()
44  ->getMock();
45  $this->serializer = $this->getMockBuilder(SerializerInterface::class)
46  ->disableOriginalConstructor()
47  ->getMock();
48  $this->integrationConfigModel = new IntegrationConfig(
49  $this->configCacheTypeMock,
50  $this->configReaderMock,
51  $this->serializer
52  );
53  }
54 
56  {
57  $integrations = ['foo', 'bar', 'baz'];
58  $serializedIntegrations = '["foo","bar","baz"]';
59  $this->configCacheTypeMock->expects($this->once())
60  ->method('load')
62  ->will($this->returnValue($serializedIntegrations));
63  $this->serializer->expects($this->once())
64  ->method('unserialize')
65  ->with($serializedIntegrations)
66  ->willReturn($integrations);
67 
68  $this->assertEquals($integrations, $this->integrationConfigModel->getIntegrations());
69  }
70 
72  {
73  $integrations = ['foo', 'bar', 'baz'];
74  $serializedIntegrations = '["foo","bar","baz"]';
75  $this->configCacheTypeMock->expects($this->once())
76  ->method('load')
78  ->will($this->returnValue(null));
79  $this->configReaderMock->expects($this->once())
80  ->method('read')
81  ->will($this->returnValue($integrations));
82  $this->serializer->expects($this->once())
83  ->method('serialize')
84  ->with($integrations)
85  ->willReturn($serializedIntegrations);
86  $this->configCacheTypeMock->expects($this->once())
87  ->method('save')
88  ->with($serializedIntegrations, IntegrationConfig::CACHE_ID, [TypeIntegration::CACHE_TAG])
89  ->will($this->returnValue(null));
90 
91  $this->assertEquals($integrations, $this->integrationConfigModel->getIntegrations());
92  }
93 }