ConfigBasedIntegrationManagerTest.php 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Integration\Model;
  8. /**
  9. * Test class for \Magento\Integration\Model\ConfigBasedIntegrationManager.php.
  10. */
  11. class ConfigBasedIntegrationManagerTest extends \PHPUnit\Framework\TestCase
  12. {
  13. /**
  14. * @var \PHPUnit_Framework_MockObject_MockObject
  15. */
  16. protected $consolidatedMock;
  17. /**
  18. * @var \Magento\Integration\Model\ConfigBasedIntegrationManager
  19. */
  20. protected $integrationManager;
  21. /**
  22. * @var \Magento\Integration\Api\IntegrationServiceInterface
  23. */
  24. protected $integrationService;
  25. /**
  26. * @var \Magento\TestFramework\ObjectManager
  27. */
  28. protected $objectManager;
  29. /**
  30. * @inheritdoc
  31. */
  32. protected function setUp()
  33. {
  34. parent::setUp();
  35. $this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
  36. $this->consolidatedMock = $this->createMock(\Magento\Integration\Model\ConsolidatedConfig::class);
  37. $this->objectManager->addSharedInstance(
  38. $this->consolidatedMock,
  39. \Magento\Integration\Model\ConsolidatedConfig::class
  40. );
  41. $this->integrationManager = $this->objectManager->create(
  42. \Magento\Integration\Model\ConfigBasedIntegrationManager::class,
  43. []
  44. );
  45. $this->integrationService = $this->objectManager->create(
  46. \Magento\Integration\Api\IntegrationServiceInterface::class,
  47. []
  48. );
  49. }
  50. /**
  51. * @inheritdoc
  52. */
  53. protected function tearDown()
  54. {
  55. $this->objectManager->removeSharedInstance(\Magento\Integration\Model\ConsolidatedConfig::class);
  56. parent::tearDown();
  57. }
  58. /**
  59. * @magentoDbIsolation enabled
  60. */
  61. public function testProcessConfigBasedIntegrations()
  62. {
  63. $newIntegrations = require __DIR__ . '/Config/Consolidated/_files/integration.php';
  64. $this->consolidatedMock
  65. ->expects($this->any())
  66. ->method('getIntegrations')
  67. ->willReturn($newIntegrations);
  68. // Check that the integrations do not exist already
  69. foreach ($newIntegrations as $integrationName => $integrationData) {
  70. $integration = $this->integrationService->findByName($integrationName);
  71. $this->assertEquals(null, $integration->getId(), 'Integration already exists');
  72. }
  73. // Create new integrations
  74. $this->assertEquals(
  75. $newIntegrations,
  76. $this->integrationManager->processConfigBasedIntegrations($newIntegrations),
  77. 'Error processing config based integrations.'
  78. );
  79. $createdIntegrations = [];
  80. // Check that the integrations are new with "inactive" status
  81. foreach ($newIntegrations as $integrationName => $integrationData) {
  82. $integration = $this->integrationService->findByName($integrationName);
  83. $this->assertNotEmpty($integration->getId(), 'Integration was not created');
  84. $this->assertEquals(
  85. $integration::STATUS_INACTIVE,
  86. $integration->getStatus(),
  87. 'Integration is not created with "inactive" status'
  88. );
  89. $createdIntegrations[$integrationName] = $integration;
  90. }
  91. // Rerun integration creation with the same data (data has not changed)
  92. $this->assertEquals(
  93. $newIntegrations,
  94. $this->integrationManager->processConfigBasedIntegrations($newIntegrations),
  95. 'Error processing config based integrations.'
  96. );
  97. // Check that the integrations are not recreated when data has not actually changed
  98. foreach ($newIntegrations as $integrationName => $integrationData) {
  99. $integration = $this->integrationService->findByName($integrationName);
  100. $this->assertEquals(
  101. $createdIntegrations[$integrationName]->getId(),
  102. $integration->getId(),
  103. 'Integration ID has changed'
  104. );
  105. $this->assertEquals(
  106. $createdIntegrations[$integrationName]->getStatus(),
  107. $integration->getStatus(),
  108. 'Integration status has changed'
  109. );
  110. }
  111. }
  112. }