Skip to content

Commit 6b11e6f

Browse files
ACPT-987
Fixes for unit tests
1 parent b32d5eb commit 6b11e6f

File tree

3 files changed

+48
-43
lines changed

3 files changed

+48
-43
lines changed

app/code/Magento/Config/Test/Unit/Model/Config/LoaderTest.php

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
use Magento\Config\Model\Config\Loader;
1111
use Magento\Config\Model\ResourceModel\Config\Data\Collection;
12-
use Magento\Framework\App\Config\Value;
12+
use Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory;
1313
use Magento\Framework\App\Config\ValueFactory;
1414
use Magento\Framework\DataObject;
1515
use PHPUnit\Framework\MockObject\MockObject;
@@ -23,57 +23,40 @@ class LoaderTest extends TestCase
2323
protected $_model;
2424

2525
/**
26-
* @var MockObject
26+
* @var MockObject&ValueFactory
2727
*/
2828
protected $_configValueFactory;
2929

3030
/**
31-
* @var MockObject
31+
* @var MockObject&Collection
3232
*/
3333
protected $_configCollection;
3434

35+
/**
36+
* @var MockObject&CollectionFactory
37+
*/
38+
protected $collectionFactory;
39+
3540
protected function setUp(): void
3641
{
3742
$this->_configValueFactory = $this->getMockBuilder(ValueFactory::class)
3843
->addMethods(['getCollection'])
3944
->onlyMethods(['create'])
4045
->disableOriginalConstructor()
4146
->getMock();
42-
$this->_model = new Loader($this->_configValueFactory);
47+
$this->collectionFactory = $this->getMockBuilder(CollectionFactory::class)
48+
->addMethods(['getCollection'])
49+
->onlyMethods(['create'])
50+
->disableOriginalConstructor()
51+
->getMock();
52+
$this->_model = new Loader($this->_configValueFactory, $this->collectionFactory);
4353
$this->_configCollection = $this->createMock(Collection::class);
44-
$this->_configCollection->expects(
45-
$this->once()
46-
)->method(
47-
'addScopeFilter'
48-
)->with(
49-
'scope',
50-
'scopeId',
51-
'section'
52-
)->willReturnSelf();
53-
54-
$configDataMock = $this->createMock(Value::class);
55-
$this->_configValueFactory->expects(
56-
$this->once()
57-
)->method(
58-
'create'
59-
)->willReturn(
60-
$configDataMock
61-
);
62-
$configDataMock->expects(
63-
$this->any()
64-
)->method(
65-
'getCollection'
66-
)->willReturn(
67-
$this->_configCollection
68-
);
69-
70-
$this->_configCollection->expects(
71-
$this->once()
72-
)->method(
73-
'getItems'
74-
)->willReturn(
75-
[new DataObject(['path' => 'section', 'value' => 10, 'config_id' => 20])]
76-
);
54+
$this->_configCollection->expects($this->once())->
55+
method('addScopeFilter')->with('scope', 'scopeId', 'section')->willReturnSelf();
56+
$this->_configValueFactory->expects($this->never())->method('create');
57+
$this->collectionFactory->expects($this->any())->method('create')->willReturn($this->_configCollection);
58+
$this->_configCollection->expects($this->once())->method('getItems')
59+
->willReturn([new DataObject(['path' => 'section', 'value' => 10, 'config_id' => 20])]);
7760
}
7861

7962
protected function tearDown(): void

app/code/Magento/Theme/Test/Unit/Model/ThemeTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
use Magento\Framework\App\State;
1414
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
15+
use Magento\Framework\TestFramework\Unit\Listener\ReplaceObjectManager\TestProvidesServiceInterface;
1516
use Magento\Framework\View\Design\Theme\CustomizationFactory;
1617
use Magento\Framework\View\Design\Theme\CustomizationInterface;
1718
use Magento\Framework\View\Design\Theme\Domain\Factory;
@@ -29,7 +30,7 @@
2930
/**
3031
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3132
*/
32-
class ThemeTest extends TestCase
33+
class ThemeTest extends TestCase implements TestProvidesServiceInterface
3334
{
3435
/**
3536
* @var Theme|MockObject
@@ -102,7 +103,6 @@ protected function setUp(): void
102103
$this->themeModelFactory = $this->createPartialMock(ThemeFactory::class, ['create']);
103104
$this->validator = $this->createMock(Validator::class);
104105
$this->appState = $this->createMock(State::class);
105-
106106
$objectManagerHelper = new ObjectManager($this);
107107
$arguments = $objectManagerHelper->getConstructArguments(
108108
Theme::class,
@@ -118,10 +118,20 @@ protected function setUp(): void
118118
'themeModelFactory' => $this->themeModelFactory
119119
]
120120
);
121-
122121
$this->_model = $objectManagerHelper->getObject(Theme::class, $arguments);
123122
}
124123

124+
/**
125+
* @inheritdoc
126+
*/
127+
public function getServiceForObjectManager(string $type) : ?object
128+
{
129+
if (Collection::class == $type) {
130+
return $this->resourceCollection;
131+
}
132+
return null;
133+
}
134+
125135
/**
126136
* @inheritdoc
127137
*/

app/code/Magento/Variable/Test/Unit/Model/VariableTest.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@
1010
use Magento\Framework\Escaper;
1111
use Magento\Framework\Phrase;
1212
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
13+
use Magento\Framework\TestFramework\Unit\Listener\ReplaceObjectManager\TestProvidesServiceInterface;
14+
use Magento\Framework\Validation\ValidationException;
15+
use Magento\Framework\Validator\HTML\WYSIWYGValidatorInterface;
1316
use Magento\Variable\Model\ResourceModel\Variable;
1417
use Magento\Variable\Model\ResourceModel\Variable\Collection;
15-
use Magento\Framework\Validator\HTML\WYSIWYGValidatorInterface;
1618
use PHPUnit\Framework\MockObject\MockObject;
1719
use PHPUnit\Framework\TestCase;
18-
use Magento\Framework\Validation\ValidationException;
1920

20-
class VariableTest extends TestCase
21+
class VariableTest extends TestCase implements TestProvidesServiceInterface
2122
{
2223
/**
2324
* @var \Magento\Variable\Model\Variable
@@ -79,6 +80,17 @@ protected function setUp(): void
7980
$this->validationFailedPhrase = __('Validation has failed.');
8081
}
8182

83+
/**
84+
* @inheritdoc
85+
*/
86+
public function getServiceForObjectManager(string $type) : ?object
87+
{
88+
if (Collection::class == $type) {
89+
return $this->resourceCollectionMock;
90+
}
91+
return null;
92+
}
93+
8294
public function testGetValueHtml()
8395
{
8496
$type = \Magento\Variable\Model\Variable::TYPE_HTML;

0 commit comments

Comments
 (0)