Skip to content

Commit

Permalink
Merge pull request #511 from magento-performance/ACPT-987-after-ACPT-…
Browse files Browse the repository at this point in the history
…1181

ACPT-987: Evaluate State check testing from PR
  • Loading branch information
andimov authored Apr 26, 2023
2 parents 1c0ed8a + 51efbb3 commit a74f840
Show file tree
Hide file tree
Showing 23 changed files with 1,051 additions and 81 deletions.
29 changes: 19 additions & 10 deletions app/code/Magento/Config/Model/Config/Loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@
* See COPYING.txt for license details.
*/

/**
* System configuration loader
*/
namespace Magento\Config\Model\Config;

use Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory;
use Magento\Framework\App\ObjectManager;

/**
* Class which can read config by paths
* System configuration loader - Class which can read config by paths
*
* @package Magento\Config\Model\Config
* @api
* @since 100.0.2
*/
Expand All @@ -22,15 +21,26 @@ class Loader
* Config data factory
*
* @var \Magento\Framework\App\Config\ValueFactory
* @deprecated
* @see $collectionFactory
*/
protected $_configValueFactory;

/**
* @var CollectionFactory
*/
private $collectionFactory;

/**
* @param \Magento\Framework\App\Config\ValueFactory $configValueFactory
* @param ?CollectionFactory $collectionFactory
*/
public function __construct(\Magento\Framework\App\Config\ValueFactory $configValueFactory)
{
public function __construct(
\Magento\Framework\App\Config\ValueFactory $configValueFactory,
CollectionFactory $collectionFactory = null
) {
$this->_configValueFactory = $configValueFactory;
$this->collectionFactory = $collectionFactory ?: ObjectManager::getInstance()->get(CollectionFactory::class);
}

/**
Expand All @@ -44,9 +54,8 @@ public function __construct(\Magento\Framework\App\Config\ValueFactory $configVa
*/
public function getConfigByPath($path, $scope, $scopeId, $full = true)
{
$configDataCollection = $this->_configValueFactory->create();
$configDataCollection = $configDataCollection->getCollection()->addScopeFilter($scope, $scopeId, $path);

$configDataCollection = $this->collectionFactory->create();
$configDataCollection->addScopeFilter($scope, $scopeId, $path);
$config = [];
$configDataCollection->load();
foreach ($configDataCollection->getItems() as $data) {
Expand Down
57 changes: 20 additions & 37 deletions app/code/Magento/Config/Test/Unit/Model/Config/LoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

use Magento\Config\Model\Config\Loader;
use Magento\Config\Model\ResourceModel\Config\Data\Collection;
use Magento\Framework\App\Config\Value;
use Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory;
use Magento\Framework\App\Config\ValueFactory;
use Magento\Framework\DataObject;
use PHPUnit\Framework\MockObject\MockObject;
Expand All @@ -23,57 +23,40 @@ class LoaderTest extends TestCase
protected $_model;

/**
* @var MockObject
* @var MockObject&ValueFactory
*/
protected $_configValueFactory;

/**
* @var MockObject
* @var MockObject&Collection
*/
protected $_configCollection;

/**
* @var MockObject&CollectionFactory
*/
protected $collectionFactory;

protected function setUp(): void
{
$this->_configValueFactory = $this->getMockBuilder(ValueFactory::class)
->addMethods(['getCollection'])
->onlyMethods(['create'])
->disableOriginalConstructor()
->getMock();
$this->_model = new Loader($this->_configValueFactory);
$this->collectionFactory = $this->getMockBuilder(CollectionFactory::class)
->addMethods(['getCollection'])
->onlyMethods(['create'])
->disableOriginalConstructor()
->getMock();
$this->_model = new Loader($this->_configValueFactory, $this->collectionFactory);
$this->_configCollection = $this->createMock(Collection::class);
$this->_configCollection->expects(
$this->once()
)->method(
'addScopeFilter'
)->with(
'scope',
'scopeId',
'section'
)->willReturnSelf();

$configDataMock = $this->createMock(Value::class);
$this->_configValueFactory->expects(
$this->once()
)->method(
'create'
)->willReturn(
$configDataMock
);
$configDataMock->expects(
$this->any()
)->method(
'getCollection'
)->willReturn(
$this->_configCollection
);

$this->_configCollection->expects(
$this->once()
)->method(
'getItems'
)->willReturn(
[new DataObject(['path' => 'section', 'value' => 10, 'config_id' => 20])]
);
$this->_configCollection->expects($this->once())->
method('addScopeFilter')->with('scope', 'scopeId', 'section')->willReturnSelf();
$this->_configValueFactory->expects($this->never())->method('create');
$this->collectionFactory->expects($this->any())->method('create')->willReturn($this->_configCollection);
$this->_configCollection->expects($this->once())->method('getItems')
->willReturn([new DataObject(['path' => 'section', 'value' => 10, 'config_id' => 20])]);
}

protected function tearDown(): void
Expand Down
27 changes: 21 additions & 6 deletions app/code/Magento/Eav/Model/ResourceModel/AttributePersistor.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,15 @@

namespace Magento\Eav\Model\ResourceModel;

use Magento\Catalog\Model\Product;
use Magento\Eav\Api\AttributeRepositoryInterface;
use Magento\Catalog\Api\ProductRepositoryInterface;
use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
use Magento\Framework\EntityManager\EntityMetadataInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Framework\Locale\FormatInterface;
use Magento\Framework\Model\Entity\ScopeInterface;
use Magento\Framework\EntityManager\MetadataPool;

/**
* Class AttributePersistor
* Class AttributePersistor persists attributes
*/
class AttributePersistor
{
Expand Down Expand Up @@ -67,6 +64,8 @@ public function __construct(
}

/**
* Registers delete
*
* @param string $entityType
* @param int $link
* @param string $attributeCode
Expand All @@ -78,6 +77,8 @@ public function registerDelete($entityType, $link, $attributeCode)
}

/**
* Registers update
*
* @param string $entityType
* @param int $link
* @param string $attributeCode
Expand All @@ -90,6 +91,8 @@ public function registerUpdate($entityType, $link, $attributeCode, $value)
}

/**
* Registers Insert
*
* @param string $entityType
* @param int $link
* @param string $attributeCode
Expand All @@ -102,6 +105,8 @@ public function registerInsert($entityType, $link, $attributeCode, $value)
}

/**
* Process deletes
*
* @param string $entityType
* @param \Magento\Framework\Model\Entity\ScopeInterface[] $context
* @return void
Expand Down Expand Up @@ -132,6 +137,8 @@ public function processDeletes($entityType, $context)
}

/**
* Process inserts
*
* @param string $entityType
* @param \Magento\Framework\Model\Entity\ScopeInterface[] $context
* @return void
Expand Down Expand Up @@ -194,6 +201,8 @@ private function prepareInsertDataForMultipleSave($entityType, $context)
}

/**
* Process updates
*
* @param string $entityType
* @param \Magento\Framework\Model\Entity\ScopeInterface[] $context
* @return void
Expand Down Expand Up @@ -329,10 +338,14 @@ public function flush($entityType, $context)
$this->processDeletes($entityType, $context);
$this->processInserts($entityType, $context);
$this->processUpdates($entityType, $context);
unset($this->delete, $this->insert, $this->update);
$this->delete = [];
$this->insert = [];
$this->update = [];
}

/**
* Prepares value
*
* @param string $entityType
* @param string $value
* @param AbstractAttribute $attribute
Expand All @@ -355,6 +368,8 @@ protected function prepareValue($entityType, $value, AbstractAttribute $attribut
}

/**
* Gets scope value
*
* @param ScopeInterface $scope
* @param AbstractAttribute $attribute
* @param bool $useDefault
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/GraphQl/etc/schema.graphqls
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ input FilterRangeTypeInput @doc(description: "Defines a filter that matches a ra
}

input FilterMatchTypeInput @doc(description: "Defines a filter that performs a fuzzy search.") {
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`.")
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`.")
}

input FilterStringTypeInput @doc(description: "Defines a filter for an input string.") {
Expand Down
16 changes: 13 additions & 3 deletions app/code/Magento/Theme/Test/Unit/Model/ThemeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use Magento\Framework\App\State;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Framework\TestFramework\Unit\Listener\ReplaceObjectManager\TestProvidesServiceInterface;
use Magento\Framework\View\Design\Theme\CustomizationFactory;
use Magento\Framework\View\Design\Theme\CustomizationInterface;
use Magento\Framework\View\Design\Theme\Domain\Factory;
Expand All @@ -29,7 +30,7 @@
/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class ThemeTest extends TestCase
class ThemeTest extends TestCase implements TestProvidesServiceInterface
{
/**
* @var Theme|MockObject
Expand Down Expand Up @@ -102,7 +103,6 @@ protected function setUp(): void
$this->themeModelFactory = $this->createPartialMock(ThemeFactory::class, ['create']);
$this->validator = $this->createMock(Validator::class);
$this->appState = $this->createMock(State::class);

$objectManagerHelper = new ObjectManager($this);
$arguments = $objectManagerHelper->getConstructArguments(
Theme::class,
Expand All @@ -118,10 +118,20 @@ protected function setUp(): void
'themeModelFactory' => $this->themeModelFactory
]
);

$this->_model = $objectManagerHelper->getObject(Theme::class, $arguments);
}

/**
* @inheritdoc
*/
public function getServiceForObjectManager(string $type) : ?object
{
if (Collection::class == $type) {
return $this->resourceCollection;
}
return null;
}

/**
* @inheritdoc
*/
Expand Down
18 changes: 15 additions & 3 deletions app/code/Magento/Variable/Test/Unit/Model/VariableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
use Magento\Framework\Escaper;
use Magento\Framework\Phrase;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Framework\TestFramework\Unit\Listener\ReplaceObjectManager\TestProvidesServiceInterface;
use Magento\Framework\Validation\ValidationException;
use Magento\Framework\Validator\HTML\WYSIWYGValidatorInterface;
use Magento\Variable\Model\ResourceModel\Variable;
use Magento\Variable\Model\ResourceModel\Variable\Collection;
use Magento\Framework\Validator\HTML\WYSIWYGValidatorInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;
use Magento\Framework\Validation\ValidationException;

class VariableTest extends TestCase
class VariableTest extends TestCase implements TestProvidesServiceInterface
{
/**
* @var \Magento\Variable\Model\Variable
Expand Down Expand Up @@ -79,6 +80,17 @@ protected function setUp(): void
$this->validationFailedPhrase = __('Validation has failed.');
}

/**
* @inheritdoc
*/
public function getServiceForObjectManager(string $type) : ?object
{
if (Collection::class == $type) {
return $this->resourceCollectionMock;
}
return null;
}

public function testGetValueHtml()
{
$type = \Magento\Variable\Model\Variable::TYPE_HTML;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function endTest(TestCase $test)
$values = $this->parse($test);
} catch (\Throwable $exception) {
ExceptionHandler::handle(
'Unable to parse fixtures',
'Unable to parse annotations',
get_class($test),
$test->getName(false),
$exception
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,13 @@ class Proxy extends \Magento\Framework\Code\GeneratorTest\SourceClassWithNamespa
*/
public function __clone()
{
$this->_subject = clone $this->_getSubject();
if ($this->_subject) {
$this->_subject = clone $this->_getSubject();
}
}

/**
* Clone proxied instance
* Debug proxied instance
*/
public function __debugInfo()
{
Expand Down
Loading

0 comments on commit a74f840

Please sign in to comment.