IntegrationConfigTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Integration\Test\Unit\Model;
  7. use Magento\Framework\Serialize\SerializerInterface;
  8. use Magento\Integration\Model\IntegrationConfig;
  9. use Magento\Integration\Model\Cache\TypeIntegration;
  10. /**
  11. * Unit test for \Magento\Integration\Model\IntegrationConfig
  12. */
  13. class IntegrationConfigTest extends \PHPUnit\Framework\TestCase
  14. {
  15. /**
  16. * @var IntegrationConfig
  17. */
  18. private $integrationConfigModel;
  19. /**
  20. * @var TypeIntegration|\PHPUnit_Framework_MockObject_MockObject
  21. */
  22. private $configCacheTypeMock;
  23. /**
  24. * @var \Magento\Integration\Model\Config\Integration\Reader|\PHPUnit_Framework_MockObject_MockObject
  25. */
  26. private $configReaderMock;
  27. /**
  28. * @var SerializerInterface|\PHPUnit_Framework_MockObject_MockObject
  29. */
  30. private $serializer;
  31. protected function setUp()
  32. {
  33. $this->configCacheTypeMock = $this->getMockBuilder(\Magento\Integration\Model\Cache\TypeIntegration::class)
  34. ->disableOriginalConstructor()
  35. ->getMock();
  36. $this->configReaderMock = $this->getMockBuilder(\Magento\Integration\Model\Config\Integration\Reader::class)
  37. ->disableOriginalConstructor()
  38. ->getMock();
  39. $this->serializer = $this->getMockBuilder(SerializerInterface::class)
  40. ->disableOriginalConstructor()
  41. ->getMock();
  42. $this->integrationConfigModel = new IntegrationConfig(
  43. $this->configCacheTypeMock,
  44. $this->configReaderMock,
  45. $this->serializer
  46. );
  47. }
  48. public function testGetIntegrationsFromConfigCacheType()
  49. {
  50. $integrations = ['foo', 'bar', 'baz'];
  51. $serializedIntegrations = '["foo","bar","baz"]';
  52. $this->configCacheTypeMock->expects($this->once())
  53. ->method('load')
  54. ->with(IntegrationConfig::CACHE_ID)
  55. ->will($this->returnValue($serializedIntegrations));
  56. $this->serializer->expects($this->once())
  57. ->method('unserialize')
  58. ->with($serializedIntegrations)
  59. ->willReturn($integrations);
  60. $this->assertEquals($integrations, $this->integrationConfigModel->getIntegrations());
  61. }
  62. public function testGetIntegrationsFromConfigReader()
  63. {
  64. $integrations = ['foo', 'bar', 'baz'];
  65. $serializedIntegrations = '["foo","bar","baz"]';
  66. $this->configCacheTypeMock->expects($this->once())
  67. ->method('load')
  68. ->with(IntegrationConfig::CACHE_ID)
  69. ->will($this->returnValue(null));
  70. $this->configReaderMock->expects($this->once())
  71. ->method('read')
  72. ->will($this->returnValue($integrations));
  73. $this->serializer->expects($this->once())
  74. ->method('serialize')
  75. ->with($integrations)
  76. ->willReturn($serializedIntegrations);
  77. $this->configCacheTypeMock->expects($this->once())
  78. ->method('save')
  79. ->with($serializedIntegrations, IntegrationConfig::CACHE_ID, [TypeIntegration::CACHE_TAG])
  80. ->will($this->returnValue(null));
  81. $this->assertEquals($integrations, $this->integrationConfigModel->getIntegrations());
  82. }
  83. }