123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Integration\Test\Unit\Model;
- use Magento\Framework\Serialize\SerializerInterface;
- use Magento\Integration\Model\IntegrationConfig;
- use Magento\Integration\Model\Cache\TypeIntegration;
- /**
- * Unit test for \Magento\Integration\Model\IntegrationConfig
- */
- class IntegrationConfigTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var IntegrationConfig
- */
- private $integrationConfigModel;
- /**
- * @var TypeIntegration|\PHPUnit_Framework_MockObject_MockObject
- */
- private $configCacheTypeMock;
- /**
- * @var \Magento\Integration\Model\Config\Integration\Reader|\PHPUnit_Framework_MockObject_MockObject
- */
- private $configReaderMock;
- /**
- * @var SerializerInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- private $serializer;
- protected function setUp()
- {
- $this->configCacheTypeMock = $this->getMockBuilder(\Magento\Integration\Model\Cache\TypeIntegration::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->configReaderMock = $this->getMockBuilder(\Magento\Integration\Model\Config\Integration\Reader::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->serializer = $this->getMockBuilder(SerializerInterface::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->integrationConfigModel = new IntegrationConfig(
- $this->configCacheTypeMock,
- $this->configReaderMock,
- $this->serializer
- );
- }
- public function testGetIntegrationsFromConfigCacheType()
- {
- $integrations = ['foo', 'bar', 'baz'];
- $serializedIntegrations = '["foo","bar","baz"]';
- $this->configCacheTypeMock->expects($this->once())
- ->method('load')
- ->with(IntegrationConfig::CACHE_ID)
- ->will($this->returnValue($serializedIntegrations));
- $this->serializer->expects($this->once())
- ->method('unserialize')
- ->with($serializedIntegrations)
- ->willReturn($integrations);
- $this->assertEquals($integrations, $this->integrationConfigModel->getIntegrations());
- }
- public function testGetIntegrationsFromConfigReader()
- {
- $integrations = ['foo', 'bar', 'baz'];
- $serializedIntegrations = '["foo","bar","baz"]';
- $this->configCacheTypeMock->expects($this->once())
- ->method('load')
- ->with(IntegrationConfig::CACHE_ID)
- ->will($this->returnValue(null));
- $this->configReaderMock->expects($this->once())
- ->method('read')
- ->will($this->returnValue($integrations));
- $this->serializer->expects($this->once())
- ->method('serialize')
- ->with($integrations)
- ->willReturn($serializedIntegrations);
- $this->configCacheTypeMock->expects($this->once())
- ->method('save')
- ->with($serializedIntegrations, IntegrationConfig::CACHE_ID, [TypeIntegration::CACHE_TAG])
- ->will($this->returnValue(null));
- $this->assertEquals($integrations, $this->integrationConfigModel->getIntegrations());
- }
- }
|