ltsecurityinc安防产品在线商城代码

This commit is contained in:
2026-09-14 17:47:10 +08:00
parent 57d8444c15
commit 6a3c9c5bd8
14539 changed files with 1775310 additions and 0 deletions
@@ -0,0 +1,125 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture\Api;
use Magento\Framework\Api\AttributeInterface;
use Magento\Framework\Api\CustomAttributesDataInterface;
use Magento\Framework\Api\ExtensibleDataInterface;
/**
* Data merger for api payload
*/
class DataMerger
{
/**
* Merge default api data with custom data
*
* @param array $defaultData
* @param array $data
* @param bool $isExtensible
* @return array
*/
public function merge(array $defaultData, array $data, bool $isExtensible = true): array
{
if ($isExtensible) {
if (isset($data[CustomAttributesDataInterface::CUSTOM_ATTRIBUTES])) {
$data[CustomAttributesDataInterface::CUSTOM_ATTRIBUTES] = $this->convertCustomAttributesToMap(
$data[CustomAttributesDataInterface::CUSTOM_ATTRIBUTES]
);
}
foreach ($data as $key => $value) {
if (!array_key_exists($key, $defaultData)) {
if (array_key_exists($key, $defaultData[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY])) {
$data[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY][$key] = $value;
} else {
$data[CustomAttributesDataInterface::CUSTOM_ATTRIBUTES][$key] = $value;
}
unset($data[$key]);
}
}
}
$result = $this->mergeRecursive($defaultData, $data);
if ($isExtensible && isset($result[CustomAttributesDataInterface::CUSTOM_ATTRIBUTES])) {
$result[CustomAttributesDataInterface::CUSTOM_ATTRIBUTES] = $this->convertCustomAttributesToCollection(
$result[CustomAttributesDataInterface::CUSTOM_ATTRIBUTES]
);
}
return $result;
}
/**
* Recursively merge entity data
*
* @param array $arrays
* @return array
*/
public function mergeRecursive(array ...$arrays): array
{
$result = [];
while ($arrays) {
$array = array_shift($arrays);
// is array an associative array
if (array_values($array) !== $array) {
foreach ($array as $key => $value) {
if (is_array($value) && array_key_exists($key, $result) && is_array($result[$key])) {
$result[$key] = $this->mergeRecursive($result[$key], $value);
} else {
$result[$key] = $value;
}
}
} elseif (array_values($result) === $result) {
$result = $array;
}
}
return $result;
}
/**
* Return an associative array with attribute codes as key
*
* @param array $data
* @return mixed
*/
private function convertCustomAttributesToMap(array $data): array
{
$result = [];
// check if data is not an associative array
if (array_values($data) === $data) {
foreach ($data as $item) {
$result[$item[AttributeInterface::ATTRIBUTE_CODE]] = $item[AttributeInterface::VALUE];
}
} else {
$result = $data;
}
return $result;
}
/**
* Return a multi-dimension array with attribute codes and values
*
* @param array $data
* @return mixed
*/
private function convertCustomAttributesToCollection(array $data): array
{
$result = [];
foreach ($data as $key => $value) {
$result[] = [
AttributeInterface::ATTRIBUTE_CODE => $key,
AttributeInterface::VALUE => $value,
];
}
return $result;
}
}
@@ -0,0 +1,73 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture\Api;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\Webapi\ServiceInputProcessor;
/**
* Api service
*/
class Service
{
/**
* @var ObjectManagerInterface
*/
private $objectManager;
/**
* @var ServiceInputProcessor
*/
private $serviceInputProcessor;
/**
* @var string
*/
private $className;
/**
* @var string
*/
private $methodName;
/**
* @param ObjectManagerInterface $objectManager
* @param ServiceInputProcessor $serviceInputProcessor
* @param string $className
* @param string $methodName
*/
public function __construct(
ObjectManagerInterface $objectManager,
ServiceInputProcessor $serviceInputProcessor,
string $className,
string $methodName
) {
$this->objectManager = $objectManager;
$this->serviceInputProcessor = $serviceInputProcessor;
$this->className = $className;
$this->methodName = $methodName;
}
/**
* Execute the Api service with provided the data
*
* @param array $data
* @return mixed
*/
public function execute(array $data)
{
$params = $this->serviceInputProcessor->process(
$this->className,
$this->methodName,
$data
);
$service = $this->objectManager->get($this->className);
return call_user_func_array([$service, $this->methodName], $params);
}
}
@@ -0,0 +1,48 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture\Api;
use Magento\Framework\ObjectManagerInterface;
/**
* Api service factor
*/
class ServiceFactory
{
/**
* @var ObjectManagerInterface
*/
private $objectManager;
/**
* @param ObjectManagerInterface $objectManager
*/
public function __construct(
ObjectManagerInterface $objectManager
) {
$this->objectManager = $objectManager;
}
/**
* Create Api service
*
* @param string $className
* @param string $methodName
* @return Service
*/
public function create(string $className, string $methodName): Service
{
return $this->objectManager->create(
Service::class,
[
'className' => $className,
'methodName' => $methodName
]
);
}
}
@@ -0,0 +1,23 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture;
use Attribute;
use Magento\Framework\App\Config\ScopeConfigInterface;
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_CLASS)]
class AppArea
{
/**
* @param string $area
*/
public function __construct(
public string $area
) {
}
}
@@ -0,0 +1,23 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture;
use Attribute;
use Magento\Framework\App\Config\ScopeConfigInterface;
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_CLASS)]
class AppIsolation
{
/**
* @param bool $state
*/
public function __construct(
public bool $state = true
) {
}
}
@@ -0,0 +1,24 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture;
use Attribute;
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
class Cache
{
/**
* @param string $type
* @param bool $status
*/
public function __construct(
public string $type,
public bool $status,
) {
}
}
@@ -0,0 +1,57 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture;
use Magento\Framework\DataObject;
/**
* Callable data fixture type
*/
class CallableDataFixture implements RevertibleDataFixtureInterface
{
/**
* @var callable
*/
private $callback;
/**
* @param callable $callback
*/
public function __construct(
callable $callback
) {
$this->callback = $callback;
}
/**
* @inheritdoc
*/
public function apply(array $data = []): ?DataObject
{
call_user_func($this->callback);
return null;
}
/**
* @inheritdoc
*/
public function revert(DataObject $data): void
{
$rollbackCallback = null;
if (is_array($this->callback)) {
$rollbackCallback = $this->callback;
$rollbackCallback[1] .= 'Rollback';
} elseif (is_string($this->callback)) {
$rollbackCallback = $this->callback;
$rollbackCallback .= 'Rollback';
}
if ($rollbackCallback && is_callable($rollbackCallback)) {
call_user_func($rollbackCallback);
}
}
}
@@ -0,0 +1,23 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture;
use Attribute;
use Magento\Framework\App\Config\ScopeConfigInterface;
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
class ComponentsDir
{
/**
* @param string $path
*/
public function __construct(
public string $path
) {
}
}
@@ -0,0 +1,29 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture;
use Attribute;
use Magento\Framework\App\Config\ScopeConfigInterface;
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
class Config
{
/**
* @param string $path
* @param mixed $value
* @param string $scopeType
* @param string|null $scopeValue
*/
public function __construct(
public string $path,
public mixed $value,
public string $scopeType = ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
public ?string $scopeValue = null
) {
}
}
@@ -0,0 +1,61 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture\Data;
use Magento\Framework\ObjectManagerInterface;
use Magento\TestFramework\Fixture\DataFixtureInterface;
/**
* Invokes all registered processors for data fixture
*/
class CompositeProcessor implements ProcessorInterface
{
/**
* @var \Magento\Framework\ObjectManagerInterface
*/
private $objectManager;
/**
* Stored Processors
*
* @var array
*/
protected $processors = [];
/**
* @param ObjectManagerInterface $objectManager
*/
public function __construct(
ObjectManagerInterface $objectManager
) {
$this->objectManager = $objectManager;
}
/**
* @inheritdoc
*/
public function process(DataFixtureInterface $fixture, array $data): array
{
foreach ($this->getProcessors() as $processor) {
$data = $this->objectManager->get($processor)->process($fixture, $data);
}
return $data;
}
/**
* Get registered processors
*
* @return array
*/
private function getProcessors(): array
{
return [
UniqueIdProcessor::class
];
}
}
@@ -0,0 +1,25 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture\Data;
use Magento\TestFramework\Fixture\DataFixtureInterface;
/**
* Interface for data fixtures processors
*/
interface ProcessorInterface
{
/**
* Processes provided data
*
* @param DataFixtureInterface $fixture
* @param array $data
* @return array
*/
public function process(DataFixtureInterface $fixture, array $data): array;
}
@@ -0,0 +1,46 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture\Data;
use Magento\TestFramework\Fixture\DataFixtureInterface;
/**
* Replaces uniqid placeholder in the provided data with unique ID
*/
class UniqueIdProcessor implements ProcessorInterface
{
private const PLACEHOLDER = '%uniqid%';
/**
* @var int
*/
private const INCREMENT = 1;
/**
* @var array
*/
private static $storage = [];
/**
* @inheritdoc
*/
public function process(DataFixtureInterface $fixture, array $data): array
{
$class = get_class($fixture);
if (!isset(self::$storage[$class])) {
self::$storage[$class] = ['prefix' => uniqid(), 'increment' => self::INCREMENT];
}
$hash = self::$storage[$class]['prefix'] . self::$storage[$class]['increment']++;
array_walk_recursive($data, function (&$value) use ($hash) {
if (is_string($value)) {
$value = str_replace(self::PLACEHOLDER, $hash, $value);
}
});
return $data;
}
}
@@ -0,0 +1,30 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture;
use Attribute;
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
class DataFixture
{
/**
* @param string $type Fixture class name
* @param array $data Data passed on to the fixture.
* @param string|null $as Fixture identifier used to retrieve the data returned by the fixture
* @param string|null $scope Name of scope data fixture in which the data fixture should be executed
* @param int $count Number of instances to generate
*/
public function __construct(
public string $type,
public array $data = [],
public ?string $as = null,
public ?string $scope = null,
public int $count = 1
) {
}
}
@@ -0,0 +1,15 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture;
use Attribute;
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)]
class DataFixtureBeforeTransaction extends DataFixture
{
}
@@ -0,0 +1,59 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture;
use Magento\Framework\ObjectManagerInterface;
/**
* Factory for data fixture
*/
class DataFixtureFactory
{
/**
* @var ObjectManagerInterface
*/
private $objectManager;
/**
* @param ObjectManagerInterface $objectManager
*/
public function __construct(
ObjectManagerInterface $objectManager
) {
$this->objectManager = $objectManager;
}
/**
* Create new instance of data fixture
*
* @param string $fixture
* @return DataFixtureInterface
*/
public function create(string $fixture): DataFixtureInterface
{
if (is_callable($fixture)) {
$result = $this->objectManager->create(
CallableDataFixture::class,
[
'callback' => $fixture
]
);
} elseif (class_exists($fixture)) {
$result = $this->objectManager->create($fixture);
} else {
$result = $this->objectManager->create(
LegacyDataFixture::class,
[
'filePath' => $fixture,
]
);
}
return $result;
}
}
@@ -0,0 +1,24 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture;
use Magento\Framework\DataObject;
/**
* Interface for data fixtures
*/
interface DataFixtureInterface
{
/**
* Apply fixture data
*
* @param array $data
* @return DataObject|null
*/
public function apply(array $data = []): ?DataObject;
}
@@ -0,0 +1,51 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture;
use Magento\Framework\DataObject;
/**
* Data fixture storage model
*/
class DataFixtureStorage
{
/**
* @var array
*/
private $fixtures = [];
/**
* Get fixture result by its identifier
*
* @param string $name
* @return DataObject|null
*/
public function get(string $name): ?DataObject
{
return $this->fixtures[$name] ?? null;
}
/**
* Persist fixture result to the storage
*
* @param string $name
* @param DataObject|null $data
*/
public function persist(string $name, ?DataObject $data): void
{
$this->fixtures[$name] = $data;
}
/**
* Flush the storage
*/
public function flush(): void
{
$this->fixtures = [];
}
}
@@ -0,0 +1,46 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture;
use Magento\Framework\Exception\LocalizedException;
/**
* Data fixture storage service manager
*/
class DataFixtureStorageManager
{
/**
* @var DataFixtureStorage
*/
private static $storage;
/**
* Get the unique instance of the storage
*
* @return DataFixtureStorage
* @throws LocalizedException
*/
public static function getStorage(): DataFixtureStorage
{
if (self::$storage === null) {
throw new LocalizedException(__('Data fixture result storage is not initialized.'));
}
return self::$storage;
}
/**
* Set the unique instance of the storage
*
* @param DataFixtureStorage $storage
*/
public static function setStorage(DataFixtureStorage $storage): void
{
self::$storage = $storage;
}
}
@@ -0,0 +1,23 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture;
use Attribute;
use Magento\Framework\App\Config\ScopeConfigInterface;
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_CLASS)]
class DbIsolation
{
/**
* @param bool $state
*/
public function __construct(
public bool $state = true
) {
}
}
@@ -0,0 +1,24 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture;
use Attribute;
#[Attribute(Attribute::TARGET_METHOD | Attribute::TARGET_CLASS)]
class IndexerDimensionMode
{
/**
* @param string $indexer
* @param string $dimension
*/
public function __construct(
public string $indexer,
public string $dimension
) {
}
}
@@ -0,0 +1,57 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture;
use Magento\Framework\DataObject;
/**
* File based data fixture
*/
class LegacyDataFixture implements RevertibleDataFixtureInterface
{
/**
* @var string
*/
private string $filePath;
/**
* @param LegacyDataFixturePathResolver $fixturePathResolver
* @param string $filePath
*/
public function __construct(
LegacyDataFixturePathResolver $fixturePathResolver,
string $filePath
) {
$this->filePath = $fixturePathResolver->resolve($filePath);
}
/**
* @inheritdoc
*/
public function apply(array $data = []): ?DataObject
{
require $this->filePath;
return null;
}
/**
* @inheritdoc
*/
public function revert(DataObject $data): void
{
$fileInfo = pathinfo($this->filePath);
$extension = '';
if (isset($fileInfo['extension'])) {
$extension = '.' . $fileInfo['extension'];
}
$rollbackScript = $fileInfo['dirname'] . DIRECTORY_SEPARATOR . $fileInfo['filename'] . '_rollback' . $extension;
if (file_exists($rollbackScript)) {
require $rollbackScript;
}
}
}
@@ -0,0 +1,81 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture;
use Magento\Framework\Component\ComponentRegistrar;
use Magento\Framework\Component\ComponentRegistrarInterface;
use Magento\Framework\Exception\LocalizedException;
/**
* Fixture path resolver for file based data fixture
*/
class LegacyDataFixturePathResolver
{
/**
* @var ComponentRegistrarInterface
*/
private $componentRegistrar;
/**
* @param ComponentRegistrarInterface $componentRegistrar
*/
public function __construct(
ComponentRegistrarInterface $componentRegistrar
) {
$this->componentRegistrar = $componentRegistrar;
}
/**
* Get the full path to the fixture
*
* @param string $fixture
* @return string
* @throws LocalizedException
*/
public function resolve(string $fixture): string
{
if ($this->isModuleAnnotation($fixture)) {
$filePath = $this->getModulePath($fixture);
} else {
$filePath = INTEGRATION_TESTS_DIR . '/testsuite/' . $fixture;
}
return $filePath;
}
/**
* Check if the fixture file is located in the module path
*
* @param string $fixture
* @return bool
*/
private function isModuleAnnotation(string $fixture): bool
{
return strpos($fixture, '::') !== false;
}
/**
* Get the full path to the fixture in the module
*
* @param string $fixture
* @return string
* @throws LocalizedException
*/
private function getModulePath(string $fixture): string
{
[$moduleName, $fixtureFile] = explode('::', $fixture, 2);
$modulePath = $this->componentRegistrar->getPath(ComponentRegistrar::MODULE, $moduleName);
if ($modulePath === null) {
throw new LocalizedException(__('Can\'t find registered Module with name %1 .', $moduleName));
}
return $modulePath . '/' . ltrim($fixtureFile, '/');
}
}
@@ -0,0 +1,62 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture\Parser;
use Magento\Framework\Exception\LocalizedException;
use Magento\TestFramework\Fixture\ParserInterface;
use PHPUnit\Framework\TestCase;
/**
* AppArea attribute parser
*/
class AppArea implements ParserInterface
{
/**
* @var string
*/
private string $attributeClass;
/**
* @param string $attributeClass
*/
public function __construct(
string $attributeClass = \Magento\TestFramework\Fixture\AppArea::class
) {
$this->attributeClass = $attributeClass;
}
/**
* @inheritdoc
*/
public function parse(TestCase $test, string $scope): array
{
$fixtures = [];
try {
$reflection = $scope === ParserInterface::SCOPE_CLASS
? new \ReflectionClass($test)
: new \ReflectionMethod($test, $test->getName(false));
} catch (\ReflectionException $e) {
throw new LocalizedException(
__(
'Unable to parse attributes for %1',
get_class($test) . ($scope === ParserInterface::SCOPE_CLASS ? '' : '::' . $test->getName(false))
),
$e
);
}
$attributes = $reflection->getAttributes($this->attributeClass);
foreach ($attributes as $attribute) {
$args = $attribute->getArguments();
$fixtures[] = [
'area' => $args[0],
];
}
return $fixtures;
}
}
@@ -0,0 +1,63 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture\Parser;
use Magento\Framework\Exception\LocalizedException;
use Magento\TestFramework\Fixture\ParserInterface;
use PHPUnit\Framework\TestCase;
/**
* AppIsolation attribute parser
*/
class AppIsolation implements ParserInterface
{
/**
* @var string
*/
private string $attributeClass;
/**
* @param string $attributeClass
*/
public function __construct(
string $attributeClass = \Magento\TestFramework\Fixture\AppIsolation::class
) {
$this->attributeClass = $attributeClass;
}
/**
* @inheritdoc
*/
public function parse(TestCase $test, string $scope): array
{
$fixtures = [];
try {
$reflection = $scope === ParserInterface::SCOPE_CLASS
? new \ReflectionClass($test)
: new \ReflectionMethod($test, $test->getName(false));
} catch (\ReflectionException $e) {
throw new LocalizedException(
__(
'Unable to parse attributes for %1',
get_class($test) . ($scope === ParserInterface::SCOPE_CLASS ? '' : '::' . $test->getName(false))
),
$e
);
}
$attributes = $reflection->getAttributes($this->attributeClass);
foreach ($attributes as $attribute) {
$args = $attribute->getArguments();
$fixtures[] = [
'enabled' => $args[0],
];
}
return $fixtures;
}
}
@@ -0,0 +1,63 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture\Parser;
use Magento\Framework\Exception\LocalizedException;
use Magento\TestFramework\Fixture\ParserInterface;
use PHPUnit\Framework\TestCase;
/**
* Cache attribute parser
*/
class Cache implements ParserInterface
{
/**
* @var string
*/
private string $attributeClass;
/**
* @param string $attributeClass
*/
public function __construct(
string $attributeClass = \Magento\TestFramework\Fixture\Cache::class
) {
$this->attributeClass = $attributeClass;
}
/**
* @inheritdoc
*/
public function parse(TestCase $test, string $scope): array
{
$fixtures = [];
try {
$reflection = $scope === ParserInterface::SCOPE_CLASS
? new \ReflectionClass($test)
: new \ReflectionMethod($test, $test->getName(false));
} catch (\ReflectionException $e) {
throw new LocalizedException(
__(
'Unable to parse attributes for %1',
get_class($test) . ($scope === ParserInterface::SCOPE_CLASS ? '' : '::' . $test->getName(false))
),
$e
);
}
$attributes = $reflection->getAttributes($this->attributeClass);
foreach ($attributes as $attribute) {
$args = $attribute->getArguments();
$fixtures[] = [
'type' => $args[0],
'status' => $args[1]
];
}
return $fixtures;
}
}
@@ -0,0 +1,62 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture\Parser;
use Magento\Framework\Exception\LocalizedException;
use Magento\TestFramework\Fixture\ParserInterface;
use PHPUnit\Framework\TestCase;
/**
* ComponentsDir attribute parser
*/
class ComponentsDir implements ParserInterface
{
/**
* @var string
*/
private string $attributeClass;
/**
* @param string $attributeClass
*/
public function __construct(
string $attributeClass = \Magento\TestFramework\Fixture\ComponentsDir::class
) {
$this->attributeClass = $attributeClass;
}
/**
* @inheritdoc
*/
public function parse(TestCase $test, string $scope): array
{
$fixtures = [];
try {
$reflection = $scope === ParserInterface::SCOPE_CLASS
? new \ReflectionClass($test)
: new \ReflectionMethod($test, $test->getName(false));
} catch (\ReflectionException $e) {
throw new LocalizedException(
__(
'Unable to parse attributes for %1',
get_class($test) . ($scope === ParserInterface::SCOPE_CLASS ? '' : '::' . $test->getName(false))
),
$e
);
}
$attributes = $reflection->getAttributes($this->attributeClass);
foreach ($attributes as $attribute) {
$args = $attribute->getArguments();
$fixtures[] = [
'path' => $args[0],
];
}
return $fixtures;
}
}
@@ -0,0 +1,83 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture\Parser;
use Magento\Framework\App\Config\ScopeConfigInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Store\Model\ScopeInterface;
use Magento\TestFramework\Fixture\ParserInterface;
use PHPUnit\Framework\TestCase;
/**
* Config attribute parser
*/
class Config implements ParserInterface
{
/**
* @var string
*/
private string $attributeClass;
/**
* @param string $attributeClass
*/
public function __construct(
string $attributeClass = \Magento\TestFramework\Fixture\Config::class
) {
$this->attributeClass = $attributeClass;
}
/**
* @inheritdoc
*/
public function parse(TestCase $test, string $scope): array
{
$fixtures = [];
try {
$reflection = $scope === ParserInterface::SCOPE_CLASS
? new \ReflectionClass($test)
: new \ReflectionMethod($test, $test->getName(false));
} catch (\ReflectionException $e) {
throw new LocalizedException(
__(
'Unable to parse attributes for %1',
get_class($test) . ($scope === ParserInterface::SCOPE_CLASS ? '' : '::' . $test->getName(false))
),
$e
);
}
$attributes = $reflection->getAttributes($this->attributeClass);
$scopeTypes = [
ScopeConfigInterface::SCOPE_TYPE_DEFAULT,
ScopeInterface::SCOPE_STORE,
ScopeInterface::SCOPE_WEBSITE
];
foreach ($attributes as $attribute) {
$args = $attribute->getArguments();
$scopeType = $args['scopeType'] ?? $args[2] ?? ScopeConfigInterface::SCOPE_TYPE_DEFAULT;
if (!in_array($scopeType, $scopeTypes)) {
throw new LocalizedException(
__(
'Invalid scope type "%1" was supplied to %2 at %3',
$scopeType,
get_class($this),
get_class($test) . ($scope === 'class' ? '' : '::' . $test->getName(false))
),
);
}
$fixtures[] = [
'path' => $args[0],
'value' => $args[1],
'scopeType' => $scopeType,
'scopeValue' => $args[3] ?? null,
];
}
return $fixtures;
}
}
@@ -0,0 +1,71 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture\Parser;
use Magento\Framework\Exception\LocalizedException;
use Magento\TestFramework\Fixture\ParserInterface;
use PHPUnit\Framework\TestCase;
/**
* DataFixture attribute parser
*/
class DataFixture implements ParserInterface
{
/**
* @var string
*/
private string $attributeClass;
/**
* @param string $attributeClass
*/
public function __construct(
string $attributeClass = \Magento\TestFramework\Fixture\DataFixture::class
) {
$this->attributeClass = $attributeClass;
}
/**
* @inheritdoc
*/
public function parse(TestCase $test, string $scope): array
{
try {
$reflection = $scope === ParserInterface::SCOPE_CLASS
? new \ReflectionClass($test)
: new \ReflectionMethod($test, $test->getName(false));
} catch (\ReflectionException $e) {
throw new LocalizedException(
__(
'Unable to parse attributes for %1',
get_class($test) . ($scope === ParserInterface::SCOPE_CLASS ? '' : '::' . $test->getName(false))
),
$e
);
}
$fixtures = [];
$attributes = $reflection->getAttributes($this->attributeClass);
foreach ($attributes as $attribute) {
$args = $attribute->getArguments();
$alias = $args['as'] ?? $args[2] ?? null;
$count = $args['count'] ?? $args[4] ?? 1;
$id = $count > 1 ? 1 : '';
do {
$fixtures[] = [
'name' => $alias !== null ? ($alias.($id++)) : null,
'factory' => $args[0],
'data' => $args[1] ?? [],
'scope' => $args['scope'] ?? $args[3] ?? null,
];
} while (--$count > 0);
}
return $fixtures;
}
}
@@ -0,0 +1,63 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture\Parser;
use Magento\Framework\Exception\LocalizedException;
use Magento\TestFramework\Fixture\ParserInterface;
use PHPUnit\Framework\TestCase;
/**
* DbIsolation attribute parser
*/
class DbIsolation implements ParserInterface
{
/**
* @var string
*/
private string $attributeClass;
/**
* @param string $attributeClass
*/
public function __construct(
string $attributeClass = \Magento\TestFramework\Fixture\DbIsolation::class
) {
$this->attributeClass = $attributeClass;
}
/**
* @inheritdoc
*/
public function parse(TestCase $test, string $scope): array
{
$fixtures = [];
try {
$reflection = $scope === ParserInterface::SCOPE_CLASS
? new \ReflectionClass($test)
: new \ReflectionMethod($test, $test->getName(false));
} catch (\ReflectionException $e) {
throw new LocalizedException(
__(
'Unable to parse attributes for %1',
get_class($test) . ($scope === ParserInterface::SCOPE_CLASS ? '' : '::' . $test->getName(false))
),
$e
);
}
$attributes = $reflection->getAttributes($this->attributeClass);
foreach ($attributes as $attribute) {
$args = $attribute->getArguments();
$fixtures[] = [
'enabled' => $args[0],
];
}
return $fixtures;
}
}
@@ -0,0 +1,63 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture\Parser;
use Magento\Framework\Exception\LocalizedException;
use Magento\TestFramework\Fixture\ParserInterface;
use PHPUnit\Framework\TestCase;
/**
* IndexerDimensionMode attribute parser
*/
class IndexerDimensionMode implements ParserInterface
{
/**
* @var string
*/
private string $attributeClass;
/**
* @param string $attributeClass
*/
public function __construct(
string $attributeClass = \Magento\TestFramework\Fixture\IndexerDimensionMode::class
) {
$this->attributeClass = $attributeClass;
}
/**
* @inheritdoc
*/
public function parse(TestCase $test, string $scope): array
{
$fixtures = [];
try {
$reflection = $scope === ParserInterface::SCOPE_CLASS
? new \ReflectionClass($test)
: new \ReflectionMethod($test, $test->getName(false));
} catch (\ReflectionException $e) {
throw new LocalizedException(
__(
'Unable to parse attributes for %1',
get_class($test) . ($scope === ParserInterface::SCOPE_CLASS ? '' : '::' . $test->getName(false))
),
$e
);
}
$attributes = $reflection->getAttributes($this->attributeClass);
foreach ($attributes as $attribute) {
$args = $attribute->getArguments();
$fixtures[] = [
'indexer' => $args[0],
'dimension' => $args[1]
];
}
return $fixtures;
}
}
@@ -0,0 +1,31 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture;
use Magento\Framework\Exception\LocalizedException;
use PHPUnit\Framework\TestCase;
/**
* Fixtures parser interface
*/
interface ParserInterface
{
public const SCOPE_CLASS = 'class';
public const SCOPE_METHOD = 'method';
/**
* Returns fixtures configuration defined in the given scope
*
* @param TestCase $testCase
* @param string $scope
* @return mixed
* @throws LocalizedException
*/
public function parse(TestCase $testCase, string $scope);
}
@@ -0,0 +1,23 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\TestFramework\Fixture;
use Magento\Framework\DataObject;
/**
* Interface for revertible data fixtures
*/
interface RevertibleDataFixtureInterface extends DataFixtureInterface
{
/**
* Revert fixture data
*
* @param DataObject $data
*/
public function revert(DataObject $data): void;
}