Skip to content

Commit a74f840

Browse files
authored
Merge pull request #511 from magento-performance/ACPT-987-after-ACPT-1181
ACPT-987: Evaluate State check testing from PR
2 parents 1c0ed8a + 51efbb3 commit a74f840

File tree

23 files changed

+1051
-81
lines changed

23 files changed

+1051
-81
lines changed

app/code/Magento/Config/Model/Config/Loader.php

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,14 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
/**
8-
* System configuration loader
9-
*/
107
namespace Magento\Config\Model\Config;
118

9+
use Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory;
10+
use Magento\Framework\App\ObjectManager;
11+
1212
/**
13-
* Class which can read config by paths
13+
* System configuration loader - Class which can read config by paths
1414
*
15-
* @package Magento\Config\Model\Config
1615
* @api
1716
* @since 100.0.2
1817
*/
@@ -22,15 +21,26 @@ class Loader
2221
* Config data factory
2322
*
2423
* @var \Magento\Framework\App\Config\ValueFactory
24+
* @deprecated
25+
* @see $collectionFactory
2526
*/
2627
protected $_configValueFactory;
2728

29+
/**
30+
* @var CollectionFactory
31+
*/
32+
private $collectionFactory;
33+
2834
/**
2935
* @param \Magento\Framework\App\Config\ValueFactory $configValueFactory
36+
* @param ?CollectionFactory $collectionFactory
3037
*/
31-
public function __construct(\Magento\Framework\App\Config\ValueFactory $configValueFactory)
32-
{
38+
public function __construct(
39+
\Magento\Framework\App\Config\ValueFactory $configValueFactory,
40+
CollectionFactory $collectionFactory = null
41+
) {
3342
$this->_configValueFactory = $configValueFactory;
43+
$this->collectionFactory = $collectionFactory ?: ObjectManager::getInstance()->get(CollectionFactory::class);
3444
}
3545

3646
/**
@@ -44,9 +54,8 @@ public function __construct(\Magento\Framework\App\Config\ValueFactory $configVa
4454
*/
4555
public function getConfigByPath($path, $scope, $scopeId, $full = true)
4656
{
47-
$configDataCollection = $this->_configValueFactory->create();
48-
$configDataCollection = $configDataCollection->getCollection()->addScopeFilter($scope, $scopeId, $path);
49-
57+
$configDataCollection = $this->collectionFactory->create();
58+
$configDataCollection->addScopeFilter($scope, $scopeId, $path);
5059
$config = [];
5160
$configDataCollection->load();
5261
foreach ($configDataCollection->getItems() as $data) {

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/Eav/Model/ResourceModel/AttributePersistor.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,15 @@
66

77
namespace Magento\Eav\Model\ResourceModel;
88

9-
use Magento\Catalog\Model\Product;
109
use Magento\Eav\Api\AttributeRepositoryInterface;
11-
use Magento\Catalog\Api\ProductRepositoryInterface;
1210
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
1311
use Magento\Framework\EntityManager\EntityMetadataInterface;
14-
use Magento\Store\Model\StoreManagerInterface;
12+
use Magento\Framework\EntityManager\MetadataPool;
1513
use Magento\Framework\Locale\FormatInterface;
1614
use Magento\Framework\Model\Entity\ScopeInterface;
17-
use Magento\Framework\EntityManager\MetadataPool;
1815

1916
/**
20-
* Class AttributePersistor
17+
* Class AttributePersistor persists attributes
2118
*/
2219
class AttributePersistor
2320
{
@@ -67,6 +64,8 @@ public function __construct(
6764
}
6865

6966
/**
67+
* Registers delete
68+
*
7069
* @param string $entityType
7170
* @param int $link
7271
* @param string $attributeCode
@@ -78,6 +77,8 @@ public function registerDelete($entityType, $link, $attributeCode)
7877
}
7978

8079
/**
80+
* Registers update
81+
*
8182
* @param string $entityType
8283
* @param int $link
8384
* @param string $attributeCode
@@ -90,6 +91,8 @@ public function registerUpdate($entityType, $link, $attributeCode, $value)
9091
}
9192

9293
/**
94+
* Registers Insert
95+
*
9396
* @param string $entityType
9497
* @param int $link
9598
* @param string $attributeCode
@@ -102,6 +105,8 @@ public function registerInsert($entityType, $link, $attributeCode, $value)
102105
}
103106

104107
/**
108+
* Process deletes
109+
*
105110
* @param string $entityType
106111
* @param \Magento\Framework\Model\Entity\ScopeInterface[] $context
107112
* @return void
@@ -132,6 +137,8 @@ public function processDeletes($entityType, $context)
132137
}
133138

134139
/**
140+
* Process inserts
141+
*
135142
* @param string $entityType
136143
* @param \Magento\Framework\Model\Entity\ScopeInterface[] $context
137144
* @return void
@@ -194,6 +201,8 @@ private function prepareInsertDataForMultipleSave($entityType, $context)
194201
}
195202

196203
/**
204+
* Process updates
205+
*
197206
* @param string $entityType
198207
* @param \Magento\Framework\Model\Entity\ScopeInterface[] $context
199208
* @return void
@@ -329,10 +338,14 @@ public function flush($entityType, $context)
329338
$this->processDeletes($entityType, $context);
330339
$this->processInserts($entityType, $context);
331340
$this->processUpdates($entityType, $context);
332-
unset($this->delete, $this->insert, $this->update);
341+
$this->delete = [];
342+
$this->insert = [];
343+
$this->update = [];
333344
}
334345

335346
/**
347+
* Prepares value
348+
*
336349
* @param string $entityType
337350
* @param string $value
338351
* @param AbstractAttribute $attribute
@@ -355,6 +368,8 @@ protected function prepareValue($entityType, $value, AbstractAttribute $attribut
355368
}
356369

357370
/**
371+
* Gets scope value
372+
*
358373
* @param ScopeInterface $scope
359374
* @param AbstractAttribute $attribute
360375
* @param bool $useDefault

app/code/Magento/GraphQl/etc/schema.graphqls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ input FilterRangeTypeInput @doc(description: "Defines a filter that matches a ra
7676
}
7777

7878
input FilterMatchTypeInput @doc(description: "Defines a filter that performs a fuzzy search.") {
79-
match: String @doc(description: "Use this attribute to exactly match the specified string. For example, to filter on a specific SKU, specify a value such as `24-MB01`.")
79+
match: String @doc(description: "Use this attribute to fuzzy match the specified string. For example, to filter on a specific SKU, specify a value such as `24-MB01`.")
8080
}
8181

8282
input FilterStringTypeInput @doc(description: "Defines a filter for an input string.") {

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;

dev/tests/integration/framework/Magento/TestFramework/Annotation/AppIsolation.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function endTest(TestCase $test)
9090
$values = $this->parse($test);
9191
} catch (\Throwable $exception) {
9292
ExceptionHandler::handle(
93-
'Unable to parse fixtures',
93+
'Unable to parse annotations',
9494
get_class($test),
9595
$test->getName(false),
9696
$exception

dev/tests/integration/testsuite/Magento/Framework/Code/_expected/SourceClassWithNamespaceProxy.php.sample

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,13 @@ class Proxy extends \Magento\Framework\Code\GeneratorTest\SourceClassWithNamespa
7272
*/
7373
public function __clone()
7474
{
75-
$this->_subject = clone $this->_getSubject();
75+
if ($this->_subject) {
76+
$this->_subject = clone $this->_getSubject();
77+
}
7678
}
7779

7880
/**
79-
* Clone proxied instance
81+
* Debug proxied instance
8082
*/
8183
public function __debugInfo()
8284
{

0 commit comments

Comments
 (0)