ImporterPoolTest.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Deploy\Test\Unit\Model\DeploymentConfig;
  7. use Magento\Deploy\Model\DeploymentConfig\ImporterPool;
  8. use Magento\Deploy\Model\DeploymentConfig\ValidatorFactory;
  9. use Magento\Framework\App\DeploymentConfig\ValidatorInterface;
  10. use Magento\Framework\ObjectManagerInterface;
  11. use PHPUnit_Framework_MockObject_MockObject as Mock;
  12. class ImporterPoolTest extends \PHPUnit\Framework\TestCase
  13. {
  14. /**
  15. * @var ImporterPool
  16. */
  17. private $configImporterPool;
  18. /**
  19. * @var ObjectManagerInterface|Mock
  20. */
  21. private $objectManagerMock;
  22. /**
  23. * @var ValidatorFactory|Mock
  24. */
  25. private $validatorFactoryMock;
  26. /**
  27. * @return void
  28. */
  29. protected function setUp()
  30. {
  31. $this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)
  32. ->getMockForAbstractClass();
  33. $this->validatorFactoryMock = $this->getMockBuilder(ValidatorFactory::class)
  34. ->disableOriginalConstructor()
  35. ->getMock();
  36. $this->configImporterPool = new ImporterPool(
  37. $this->objectManagerMock,
  38. $this->validatorFactoryMock,
  39. [
  40. 'firstSection' => ['importer_class' => 'Magento\Importer\SomeImporter', 'sort_order' => 20],
  41. 'secondSection' => [
  42. 'importer_class' => 'Magento\Importer\SomeImporter',
  43. 'validator_class' => 'Validator\SomeValidator\Class'
  44. ],
  45. 'thirdSection' => ['importer_class' => 'Magento\Importer\SomeImporter', 'sort_order' => 10]
  46. ]
  47. );
  48. }
  49. /**
  50. * @return void
  51. */
  52. public function testGetImporters()
  53. {
  54. $expectedResult = [
  55. 'secondSection' => 'Magento\Importer\SomeImporter',
  56. 'thirdSection' => 'Magento\Importer\SomeImporter',
  57. 'firstSection' => 'Magento\Importer\SomeImporter',
  58. ];
  59. $this->assertSame($expectedResult, $this->configImporterPool->getImporters());
  60. }
  61. /**
  62. * @return void
  63. * @expectedException \Magento\Framework\Exception\ConfigurationMismatchException
  64. * @expectedExceptionMessage The parameter "importer_class" is missing. Set the "importer_class" and try again.
  65. */
  66. public function testGetImportersEmptyParameterClass()
  67. {
  68. $this->configImporterPool = new ImporterPool(
  69. $this->objectManagerMock,
  70. $this->validatorFactoryMock,
  71. ['wrongSection' => ['class' => '']]
  72. );
  73. $this->configImporterPool->getImporters();
  74. }
  75. /**
  76. * @return void
  77. */
  78. public function testGetSections()
  79. {
  80. $this->assertSame(
  81. ['firstSection', 'secondSection', 'thirdSection'],
  82. $this->configImporterPool->getSections()
  83. );
  84. }
  85. public function testGetValidator()
  86. {
  87. $validatorMock = $this->getMockBuilder(ValidatorInterface::class)
  88. ->getMockForAbstractClass();
  89. $this->validatorFactoryMock->expects($this->once())
  90. ->method('create')
  91. ->with('Validator\SomeValidator\Class')
  92. ->willReturn($validatorMock);
  93. $this->assertNull($this->configImporterPool->getValidator('firstSection'));
  94. $this->assertNull($this->configImporterPool->getValidator('thirdSection'));
  95. $this->assertInstanceOf(
  96. ValidatorInterface::class,
  97. $this->configImporterPool->getValidator('secondSection')
  98. );
  99. }
  100. }