This commit is contained in:
2026-09-15 10:26:34 +08:00
commit ecf36afa56
10493 changed files with 1404888 additions and 0 deletions
@@ -0,0 +1,137 @@
<?php
/**
* Application configuration object. Used to access configuration when application is initialized and installed.
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\TestFramework\App;
use Magento\Framework\App\Config\ScopeCodeResolver;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\DataObject;
use Magento\TestFramework\ObjectManager;
/**
* @inheritdoc
*/
class Config extends \Magento\Framework\App\Config
{
/**
* @var DataObject[]
*/
private $data;
/**
* @var ScopeCodeResolver
*/
private $scopeCodeResolver;
/**
* Initialize data object with all settings data
*
* @param array $data
* @param string $configType
* @return void
*/
private function setData(array $data, $configType)
{
$this->data[$configType] = new DataObject($data);
}
/**
* Retrieve Scope Code Resolver
*
* @return ScopeCodeResolver
*/
private function getScopeCodeResolver()
{
if (!$this->scopeCodeResolver) {
$this->scopeCodeResolver = ObjectManager::getInstance()->get(ScopeCodeResolver::class);
}
return $this->scopeCodeResolver;
}
/**
* Set config value in the corresponding config scope
*
* @param string $path
* @param mixed $value
* @param string $scope
* @param null|string $scopeCode
* @return void
*/
public function setValue(
$path,
$value,
$scope = ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
$scopeCode = null
) {
$result = $this->get('system');
if ($scope === 'store') {
$scope = 'stores';
} elseif ($scope === 'website') {
$scope = 'websites';
}
if (empty($scopeCode)) {
$scopeCode = $this->getScopeCodeResolver()->resolve($scope, $scopeCode);
}
$keys = explode('/', $path);
if ($scope !== ScopeConfigInterface::SCOPE_TYPE_DEFAULT) {
$searchKeys = array_merge([$scope, $scopeCode], $keys);
} else {
$searchKeys = array_merge([$scope], $keys);
}
$this->updateResult($searchKeys, $result, $value);
$this->setData($result, 'system');
}
/**
* Recursively update results in global variable, which hold configs
*
* @param array $keys
* @param array $result
* @param mixed $value
* @return void
*/
private function updateResult(array $keys, & $result, $value)
{
$key = array_shift($keys);
if (empty($keys)) {
$result[$key] = $value;
} else {
$this->updateResult($keys, $result[$key], $value);
}
}
/**
* Flush all muted settings
*
* @return void
*/
public function clean()
{
$this->data = null;
$this->scopeCodeResolver = null;
parent::clean();
}
/**
* @inheritdoc
*/
public function get($configType, $path = null, $default = null)
{
$path = $path === null ? '' : $path;
if (!isset($this->data[$configType]) || $this->data[$configType]->getData($path) === null) {
return parent::get($configType, $path, $default);
}
return $this->data[$configType]->getData($path);
}
}
@@ -0,0 +1,17 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\TestFramework\App;
use Magento\TestFramework\App\ObjectManager\Environment\Developer;
class EnvironmentFactory extends \Magento\Framework\App\EnvironmentFactory
{
public function createEnvironment()
{
return new Developer($this);
}
}
@@ -0,0 +1,54 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\TestFramework\App;
class Filesystem extends \Magento\Framework\Filesystem
{
/**
* Overridden paths
*
* @var string[]
*/
private $paths = [];
/**
* {@inheritdoc}
*/
protected function getDirPath($code)
{
return $this->getOverriddenPath($code, parent::getDirPath($code));
}
/**
* Overrides a path to directory for testing purposes
*
* @param string $code
* @param string $value
* @return void
*/
public function overridePath($code, $value)
{
$this->paths[$code] = str_replace('\\', '/', $value);
unset($this->readInstances[$code]);
unset($this->writeInstances[$code]);
}
/**
* Looks up an overridden directory path
*
* @param string $code
* @param string $original
* @return string
*/
private function getOverriddenPath($code, $original)
{
if (array_key_exists($code, $this->paths)) {
return $this->paths[$code];
}
return $original;
}
}
@@ -0,0 +1,77 @@
<?php
/**
* Application configuration object. Used to access configuration when application is installed.
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\TestFramework\App;
use Magento\Framework\App\Config\MutableScopeConfigInterface;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\TestFramework\ObjectManager;
/**
* @inheritdoc
*/
class MutableScopeConfig implements MutableScopeConfigInterface
{
/**
* @var Config
*/
private $testAppConfig;
/**
* @inheritdoc
*/
public function isSetFlag($path, $scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeCode = null)
{
return $this->getTestAppConfig()->isSetFlag($path, $scopeType, $scopeCode);
}
/**
* @inheritdoc
*/
public function getValue($path, $scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT, $scopeCode = null)
{
return $this->getTestAppConfig()->getValue($path, $scopeType, $scopeCode);
}
/**
* @inheritdoc
*/
public function setValue(
$path,
$value,
$scopeType = \Magento\Framework\App\Config\ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
$scopeCode = null
) {
return $this->getTestAppConfig()->setValue($path, $value, $scopeType, $scopeCode);
}
/**
* Clean app config cache
*
* @param string|null $type
* @return void
*/
public function clean()
{
$this->getTestAppConfig()->clean();
}
/**
* Retrieve test app config instance
*
* @return \Magento\TestFramework\App\Config
*/
private function getTestAppConfig()
{
if (!$this->testAppConfig) {
$this->testAppConfig = ObjectManager::getInstance()->get(ScopeConfigInterface::class);
}
return $this->testAppConfig;
}
}
@@ -0,0 +1,21 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\TestFramework\App\ObjectManager\Environment;
class Developer extends \Magento\Framework\App\ObjectManager\Environment\Developer
{
public function getDiConfig()
{
if (!$this->config) {
$this->config = new \Magento\TestFramework\ObjectManager\Config(
$this->envFactory->getRelations(),
$this->envFactory->getDefinitions()
);
}
return $this->config;
}
}
@@ -0,0 +1,43 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\TestFramework\App;
use Magento\Framework\App\Config\ReinitableConfigInterface;
use Magento\TestFramework\ObjectManager;
/**
* @inheritdoc
*/
class ReinitableConfig extends MutableScopeConfig implements ReinitableConfigInterface
{
/**
* @var Config
*/
private $testAppConfig;
/**
* {@inheritdoc}
*/
public function reinit()
{
$this->getTestScopeConfig()->clean();
return $this;
}
/**
* Retrieve Test Scope Config
*
* @return Config
*/
public function getTestScopeConfig()
{
if (!$this->testAppConfig) {
$this->testAppConfig = ObjectManager::getInstance()->get(Config::class);
}
return $this->testAppConfig;
}
}
@@ -0,0 +1,38 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/**
* App State class for integration tests framework
*/
namespace Magento\TestFramework\App;
class State extends \Magento\Framework\App\State
{
/**
* {@inheritdoc}
*/
public function getAreaCode()
{
return $this->_areaCode;
}
/**
* {@inheritdoc}
*/
public function setAreaCode($code)
{
$this->_areaCode = $code;
$this->_configScope->setCurrentScope($code);
}
/**
* {@inheritdoc}
*/
public function setMode($mode)
{
$this->_appMode = $mode;
}
}