Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ImporterPoolTest.php
Go to the documentation of this file.
1 <?php
8 
13 use PHPUnit_Framework_MockObject_MockObject as Mock;
14 
15 class ImporterPoolTest extends \PHPUnit\Framework\TestCase
16 {
20  private $configImporterPool;
21 
25  private $objectManagerMock;
26 
30  private $validatorFactoryMock;
31 
35  protected function setUp()
36  {
37  $this->objectManagerMock = $this->getMockBuilder(ObjectManagerInterface::class)
38  ->getMockForAbstractClass();
39  $this->validatorFactoryMock = $this->getMockBuilder(ValidatorFactory::class)
40  ->disableOriginalConstructor()
41  ->getMock();
42  $this->configImporterPool = new ImporterPool(
43  $this->objectManagerMock,
44  $this->validatorFactoryMock,
45  [
46  'firstSection' => ['importer_class' => 'Magento\Importer\SomeImporter', 'sort_order' => 20],
47  'secondSection' => [
48  'importer_class' => 'Magento\Importer\SomeImporter',
49  'validator_class' => 'Validator\SomeValidator\Class'
50  ],
51  'thirdSection' => ['importer_class' => 'Magento\Importer\SomeImporter', 'sort_order' => 10]
52  ]
53  );
54  }
55 
59  public function testGetImporters()
60  {
61  $expectedResult = [
62  'secondSection' => 'Magento\Importer\SomeImporter',
63  'thirdSection' => 'Magento\Importer\SomeImporter',
64  'firstSection' => 'Magento\Importer\SomeImporter',
65  ];
66  $this->assertSame($expectedResult, $this->configImporterPool->getImporters());
67  }
68 
75  {
76  $this->configImporterPool = new ImporterPool(
77  $this->objectManagerMock,
78  $this->validatorFactoryMock,
79  ['wrongSection' => ['class' => '']]
80  );
81 
82  $this->configImporterPool->getImporters();
83  }
84 
88  public function testGetSections()
89  {
90  $this->assertSame(
91  ['firstSection', 'secondSection', 'thirdSection'],
92  $this->configImporterPool->getSections()
93  );
94  }
95 
96  public function testGetValidator()
97  {
98  $validatorMock = $this->getMockBuilder(ValidatorInterface::class)
99  ->getMockForAbstractClass();
100  $this->validatorFactoryMock->expects($this->once())
101  ->method('create')
102  ->with('Validator\SomeValidator\Class')
103  ->willReturn($validatorMock);
104 
105  $this->assertNull($this->configImporterPool->getValidator('firstSection'));
106  $this->assertNull($this->configImporterPool->getValidator('thirdSection'));
107  $this->assertInstanceOf(
108  ValidatorInterface::class,
109  $this->configImporterPool->getValidator('secondSection')
110  );
111  }
112 }