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