ltsecurityinc安防产品在线商城代码
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\Interception;
|
||||
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
|
||||
/**
|
||||
* Class GeneralTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
abstract class AbstractPlugin extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* Config reader
|
||||
*
|
||||
* @var \PHPUnit\Framework\MockObject\MockObject
|
||||
*/
|
||||
protected $_configReader;
|
||||
|
||||
/**
|
||||
* Object Manager
|
||||
*
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
protected $_objectManager;
|
||||
|
||||
/**
|
||||
* Applicartion Object Manager
|
||||
*
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
private $applicationObjectManager;
|
||||
|
||||
/**
|
||||
* Set up
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
if (!$this->_objectManager) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->applicationObjectManager = \Magento\Framework\App\ObjectManager::getInstance();
|
||||
\Magento\Framework\App\ObjectManager::setInstance($this->_objectManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tear down
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
\Magento\Framework\App\ObjectManager::setInstance($this->applicationObjectManager);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up Interception Config
|
||||
*
|
||||
* @param array $pluginConfig
|
||||
*/
|
||||
public function setUpInterceptionConfig($pluginConfig)
|
||||
{
|
||||
$config = new \Magento\Framework\Interception\ObjectManager\Config\Developer();
|
||||
$factory = new \Magento\Framework\ObjectManager\Factory\Dynamic\Developer($config, null);
|
||||
|
||||
$this->_configReader = $this->createMock(\Magento\Framework\Config\ReaderInterface::class);
|
||||
$this->_configReader->expects(
|
||||
$this->any()
|
||||
)->method(
|
||||
'read'
|
||||
)->willReturn(
|
||||
$pluginConfig
|
||||
);
|
||||
|
||||
$areaList = $this->createMock(\Magento\Framework\App\AreaList::class);
|
||||
$areaList->expects($this->any())->method('getCodes')->willReturn([]);
|
||||
$configScope = new \Magento\Framework\Config\Scope($areaList, 'global');
|
||||
$cache = $this->createMock(\Magento\Framework\Config\CacheInterface::class);
|
||||
$cacheManager = $this->createMock(\Magento\Framework\Interception\Config\CacheManager::class);
|
||||
$cacheManager->method('load')->willReturn(null);
|
||||
$definitions = new \Magento\Framework\ObjectManager\Definition\Runtime();
|
||||
$relations = new \Magento\Framework\ObjectManager\Relations\Runtime();
|
||||
$configLoader = $this->createMock(ConfigLoaderInterface::class);
|
||||
$logger = $this->createMock(\Psr\Log\LoggerInterface::class);
|
||||
$directoryList = $this->createMock(DirectoryList::class);
|
||||
$configWriter = $this->createMock(PluginListGenerator::class);
|
||||
$interceptionConfig = new Config\Config(
|
||||
$this->_configReader,
|
||||
$configScope,
|
||||
$cache,
|
||||
$relations,
|
||||
$config,
|
||||
$definitions,
|
||||
'interception',
|
||||
null,
|
||||
$cacheManager
|
||||
);
|
||||
$interceptionDefinitions = new Definition\Runtime();
|
||||
$json = new \Magento\Framework\Serialize\Serializer\Json();
|
||||
$sharedInstances = [
|
||||
\Magento\Framework\Config\CacheInterface::class => $cache,
|
||||
\Magento\Framework\Config\ScopeInterface::class => $configScope,
|
||||
\Magento\Framework\Config\ReaderInterface::class => $this->_configReader,
|
||||
\Magento\Framework\ObjectManager\RelationsInterface::class => $relations,
|
||||
\Magento\Framework\ObjectManager\ConfigInterface::class => $config,
|
||||
\Magento\Framework\Interception\ObjectManager\ConfigInterface::class => $config,
|
||||
\Magento\Framework\ObjectManager\DefinitionInterface::class => $definitions,
|
||||
\Magento\Framework\Interception\DefinitionInterface::class => $interceptionDefinitions,
|
||||
\Magento\Framework\Serialize\SerializerInterface::class => $json,
|
||||
\Magento\Framework\Interception\ConfigLoaderInterface::class => $configLoader,
|
||||
\Psr\Log\LoggerInterface::class => $logger,
|
||||
\Magento\Framework\App\Filesystem\DirectoryList::class => $directoryList,
|
||||
\Magento\Framework\App\ObjectManager\ConfigWriterInterface::class => $configWriter
|
||||
];
|
||||
$this->_objectManager = new \Magento\Framework\ObjectManager\ObjectManager(
|
||||
$factory,
|
||||
$config,
|
||||
$sharedInstances
|
||||
);
|
||||
$factory->setObjectManager($this->_objectManager);
|
||||
|
||||
$config->setInterceptionConfig($interceptionConfig);
|
||||
$config->extend(
|
||||
[
|
||||
'preferences' => [
|
||||
\Magento\Framework\Interception\PluginListInterface::class =>
|
||||
\Magento\Framework\Interception\PluginList\PluginList::class,
|
||||
\Magento\Framework\Interception\ConfigWriterInterface::class =>
|
||||
\Magento\Framework\Interception\PluginListGenerator::class
|
||||
],
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
+135
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Framework\Interception\Config;
|
||||
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
|
||||
class CacheManagerTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
const CACHE_ID = 'interceptiontest';
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\ObjectManagerInterface
|
||||
*/
|
||||
private $objectManager;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Serialize\SerializerInterface
|
||||
*/
|
||||
private $serializer;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\Cache\FrontendInterface
|
||||
*/
|
||||
private $cache;
|
||||
|
||||
/**
|
||||
* @var \Magento\Framework\App\ObjectManager\ConfigWriterInterface
|
||||
*/
|
||||
private $configWriter;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
||||
|
||||
$this->serializer = $this->objectManager->get(\Magento\Framework\Serialize\SerializerInterface::class);
|
||||
$this->cache = $this->objectManager->get(\Magento\Framework\App\CacheInterface::class);
|
||||
$this->configWriter =
|
||||
$this->objectManager->get(\Magento\Framework\App\ObjectManager\ConfigWriter\Filesystem::class);
|
||||
|
||||
$this->initializeMetadataDirectory();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete compiled file if it was created and clear cache data
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
$compiledPath = \Magento\Framework\App\ObjectManager\ConfigLoader\Compiled::getFilePath(self::CACHE_ID);
|
||||
if (file_exists($compiledPath)) {
|
||||
unlink($compiledPath);
|
||||
}
|
||||
|
||||
$this->cache->remove(self::CACHE_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test load interception cache from generated/metadata
|
||||
* @dataProvider interceptionCompiledConfigDataProvider
|
||||
* @param array $testConfig
|
||||
*/
|
||||
public function testInstantiateFromCompiled(array $testConfig)
|
||||
{
|
||||
$this->configWriter->write(self::CACHE_ID, $testConfig);
|
||||
$config = $this->getConfig();
|
||||
|
||||
$this->assertEquals($testConfig, $config->load(self::CACHE_ID));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test load interception cache from backend cache
|
||||
* @dataProvider interceptionCacheConfigDataProvider
|
||||
* @param array $testConfig
|
||||
*/
|
||||
public function testInstantiateFromCache(array $testConfig)
|
||||
{
|
||||
$this->cache->save($this->serializer->serialize($testConfig), self::CACHE_ID);
|
||||
$config = $this->getConfig();
|
||||
|
||||
$this->assertEquals($testConfig, $config->load(self::CACHE_ID));
|
||||
}
|
||||
|
||||
public function interceptionCompiledConfigDataProvider()
|
||||
{
|
||||
return [
|
||||
[['classA' => true, 'classB' => false]],
|
||||
[['classA' => false, 'classB' => true]],
|
||||
];
|
||||
}
|
||||
|
||||
public function interceptionCacheConfigDataProvider()
|
||||
{
|
||||
return [
|
||||
[['classC' => true, 'classD' => false]],
|
||||
[['classC' => false, 'classD' => true]],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensure generated/metadata exists
|
||||
*/
|
||||
private function initializeMetadataDirectory()
|
||||
{
|
||||
$diPath = DirectoryList::getDefaultConfig()[DirectoryList::GENERATED_METADATA][DirectoryList::PATH];
|
||||
$fullPath = BP . DIRECTORY_SEPARATOR . $diPath;
|
||||
if (!file_exists($fullPath)) {
|
||||
mkdir($fullPath);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create instance of Config class with specific cacheId. This is done to prevent our test
|
||||
* from altering the interception config that may have been generated during application
|
||||
* installation. Inject a new instance of the compileLoaded to bypass it's caching.
|
||||
*
|
||||
* @return \Magento\Framework\Interception\Config\CacheManager
|
||||
*/
|
||||
private function getConfig()
|
||||
{
|
||||
return $this->objectManager->create(
|
||||
\Magento\Framework\Interception\Config\CacheManager::class,
|
||||
[
|
||||
'cacheId' => self::CACHE_ID,
|
||||
'compiledLoader' => $this->objectManager->create(
|
||||
\Magento\Framework\App\ObjectManager\ConfigLoader\Compiled::class
|
||||
),
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Framework\Interception\Fixture;
|
||||
|
||||
/**
|
||||
* phpcs:ignoreFile
|
||||
*/
|
||||
class Intercepted extends InterceptedParent implements InterceptedInterface
|
||||
{
|
||||
protected $_key;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*/
|
||||
public function A($param1)
|
||||
{
|
||||
$this->_key = $param1;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*/
|
||||
public function B($param1, $param2)
|
||||
{
|
||||
return '<B>' . $param1 . $param2 . $this->C($param1) . '</B>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*/
|
||||
public function C($param1)
|
||||
{
|
||||
return '<C>' . $param1 . '</C>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*/
|
||||
public function D($param1)
|
||||
{
|
||||
return '<D>' . $this->_key . $param1 . '</D>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*/
|
||||
final public function E($param1)
|
||||
{
|
||||
return '<E>' . $this->_key . $param1 . '</E>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*/
|
||||
public function F($param1)
|
||||
{
|
||||
return '<F>' . $param1 . '</F>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*/
|
||||
public function G($param1)
|
||||
{
|
||||
return '<G>' . $param1 . "</G>";
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*/
|
||||
public function K($param1)
|
||||
{
|
||||
return '<K>' . $param1 . '</K>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*/
|
||||
public function V($param1)
|
||||
{
|
||||
return '<V>' . $param1 . '</V>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*/
|
||||
public function W($param1)
|
||||
{
|
||||
return '<W>' . $param1 . '</W>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*/
|
||||
public function X($param1)
|
||||
{
|
||||
return '<X>' . $param1 . '</X>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*/
|
||||
public function Y($param1)
|
||||
{
|
||||
return '<Y>' . $param1 . '</Y>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*/
|
||||
public function Z($param1)
|
||||
{
|
||||
return '<Z>' . $param1 . '</Z>';
|
||||
}
|
||||
}
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\Interception\Fixture\Intercepted;
|
||||
|
||||
use Magento\Framework\Interception\Fixture\Intercepted;
|
||||
|
||||
class FirstPlugin
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $_counter = 0;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function aroundC(Intercepted $subject, \Closure $next, $param1)
|
||||
{
|
||||
return '<F:C>' . $next($param1) . '</F:C>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function aroundD(Intercepted $subject, \Closure $next, $param1)
|
||||
{
|
||||
$this->_counter++;
|
||||
return '<F:D>' . $this->_counter . ': ' . $next($param1) . '</F:D>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function aroundK(Intercepted $subject, \Closure $next, $param1)
|
||||
{
|
||||
$result = $subject->C($param1);
|
||||
return '<F:K>' . $subject->F($result) . '</F:K>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function beforeG(Intercepted $subject, $param1)
|
||||
{
|
||||
return ['<F:bG>' . $param1 . '</F:bG>'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function aroundG(Intercepted $subject, \Closure $next, $param1)
|
||||
{
|
||||
return $next('<F:G>' . $param1 . '</F:G>');
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function afterG(Intercepted $subject, $result)
|
||||
{
|
||||
return '<F:aG>' . $result . '</F:aG>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function beforeV(Intercepted $subject, $param1)
|
||||
{
|
||||
return ['<F:bV/>'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function aroundV(Intercepted $subject, \Closure $next, $param1)
|
||||
{
|
||||
return '<F:V>' . $param1 . '<F:V/>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function beforeW(Intercepted $subject, $param1)
|
||||
{
|
||||
return ['<F:bW/>'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function aroundW(Intercepted $subject, \Closure $next, $param1)
|
||||
{
|
||||
return '<F:W>' . $param1 . '<F:W/>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function afterW(Intercepted $subject, $result)
|
||||
{
|
||||
return '<F:aW/>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function beforeX(Intercepted $subject, $param1)
|
||||
{
|
||||
return ['<F:bX/>'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function aroundY(Intercepted $subject, \Closure $next, $param1)
|
||||
{
|
||||
return '<F:Y>' . $param1 . '<F:Y/>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function afterZ(Intercepted $subject, $result)
|
||||
{
|
||||
return '<F:aZ/>';
|
||||
}
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\Interception\Fixture\Intercepted;
|
||||
|
||||
use Magento\Framework\Interception\Fixture\InterceptedInterface;
|
||||
|
||||
class InterfacePlugin
|
||||
{
|
||||
/**
|
||||
* @param InterceptedInterface $subject
|
||||
* @param \Closure $next
|
||||
* @param string $param1
|
||||
* @return string
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function aroundC(InterceptedInterface $subject, \Closure $next, $param1)
|
||||
{
|
||||
return '<IP:C>' . $next($param1) . '</IP:C>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param InterceptedInterface $subject
|
||||
* @param \Closure $next
|
||||
* @param $param1
|
||||
* @return string
|
||||
*/
|
||||
public function aroundF(InterceptedInterface $subject, \Closure $next, $param1)
|
||||
{
|
||||
return '<IP:F>' . $subject->D($next($subject->C($param1))) . '</IP:F>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function beforeG(InterceptedInterface $subject, $param1)
|
||||
{
|
||||
return ['<IP:bG>' . $param1 . '</IP:bG>'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function aroundG(InterceptedInterface $subject, \Closure $next, $param1)
|
||||
{
|
||||
return $next('<IP:G>' . $param1 . '</IP:G>');
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function afterG(InterceptedInterface $subject, $result)
|
||||
{
|
||||
return '<IP:aG>' . $result . '</IP:aG>';
|
||||
}
|
||||
}
|
||||
+131
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\Interception\Fixture\Intercepted;
|
||||
|
||||
use Magento\Framework\Interception\Fixture\Intercepted;
|
||||
|
||||
class Plugin
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected $_counter = 0;
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function aroundC(Intercepted $subject, \Closure $next, $param1)
|
||||
{
|
||||
return '<P:C>' . $next($param1) . '</P:C>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function aroundD(Intercepted $subject, \Closure $next, $param1)
|
||||
{
|
||||
$this->_counter++;
|
||||
return '<P:D>' . $this->_counter . ': ' . $next($param1) . '</P:D>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function aroundK(Intercepted $subject, \Closure $next, $param1)
|
||||
{
|
||||
$result = $subject->C($param1);
|
||||
return '<P:K>' . $subject->F($result) . '</P:K>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function beforeG(Intercepted $subject, $param1)
|
||||
{
|
||||
return ['<P:bG>' . $param1 . '</P:bG>'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function aroundG(Intercepted $subject, \Closure $next, $param1)
|
||||
{
|
||||
return $next('<P:G>' . $param1 . '</P:G>');
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function afterG(Intercepted $subject, $result)
|
||||
{
|
||||
return '<P:aG>' . $result . '</P:aG>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function beforeV(Intercepted $subject, $param1)
|
||||
{
|
||||
return ['<P:bV/>'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function aroundV(Intercepted $subject, \Closure $next, $param1)
|
||||
{
|
||||
return '<P:V>' . $param1 . '<P:V/>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function beforeW(Intercepted $subject, $param1)
|
||||
{
|
||||
return ['<P:bW/>'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function aroundW(Intercepted $subject, \Closure $next, $param1)
|
||||
{
|
||||
return '<P:W>' . $param1 . '<P:W/>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function afterW(Intercepted $subject, $result)
|
||||
{
|
||||
return '<P:aW/>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function beforeX(Intercepted $subject, $param1)
|
||||
{
|
||||
return ['<P:bX/>'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function aroundY(Intercepted $subject, \Closure $next, $param1)
|
||||
{
|
||||
return '<P:Y>' . $param1 . '<P:Y/>';
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function afterZ(Intercepted $subject, $result)
|
||||
{
|
||||
return '<P:aZ/>';
|
||||
}
|
||||
}
|
||||
+24
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Framework\Interception\Fixture;
|
||||
|
||||
/**
|
||||
* @codingStandardsIgnoreStart
|
||||
*/
|
||||
interface InterceptedInterface
|
||||
{
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*/
|
||||
public function C($param1);
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*/
|
||||
public function F($param1);
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Framework\Interception\Fixture;
|
||||
|
||||
/**
|
||||
* @codingStandardsIgnoreStart
|
||||
*/
|
||||
class InterceptedParent implements InterceptedParentInterface
|
||||
{
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*/
|
||||
public function A($param1)
|
||||
{
|
||||
return 'A' . $param1 . 'A';
|
||||
}
|
||||
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
*/
|
||||
public function B($param1, $param2)
|
||||
{
|
||||
return $param1 . $param2 . $this->A($param1);
|
||||
}
|
||||
}
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
*
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
|
||||
namespace Magento\Framework\Interception\Fixture;
|
||||
|
||||
interface InterceptedParentInterface
|
||||
{
|
||||
/**
|
||||
* @SuppressWarnings(PHPMD.ShortMethodName)
|
||||
* @codingStandardsIgnoreStart
|
||||
*/
|
||||
public function A($param1);
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\Interception;
|
||||
|
||||
/**
|
||||
* Class GeneralTest
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class GeneralTest extends AbstractPlugin
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->setUpInterceptionConfig(
|
||||
[\Magento\Framework\Interception\Fixture\InterceptedInterface::class =>
|
||||
[
|
||||
'plugins' => [
|
||||
'first' => [
|
||||
'instance' =>
|
||||
\Magento\Framework\Interception\Fixture\Intercepted\InterfacePlugin::class,
|
||||
'sortOrder' => 10,
|
||||
],
|
||||
],
|
||||
], \Magento\Framework\Interception\Fixture\Intercepted::class =>
|
||||
[
|
||||
'plugins' => [
|
||||
'second' => [
|
||||
'instance' => \Magento\Framework\Interception\Fixture\Intercepted\Plugin::class,
|
||||
'sortOrder' => 20,
|
||||
],
|
||||
],
|
||||
],
|
||||
]
|
||||
);
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testMethodCanBePluginized()
|
||||
{
|
||||
$subject = $this->_objectManager->create(\Magento\Framework\Interception\Fixture\Intercepted::class);
|
||||
$this->assertEquals('<P:D>1: <D>test</D></P:D>', $subject->D('test'));
|
||||
}
|
||||
|
||||
public function testPluginCanCallOnlyNextMethodOnNext()
|
||||
{
|
||||
$subject = $this->_objectManager->create(\Magento\Framework\Interception\Fixture\Intercepted::class);
|
||||
$this->assertEquals(
|
||||
'<IP:aG><P:aG><G><P:G><P:bG><IP:G><IP:bG>test</IP:bG></IP:G></P:bG></P:G></G></P:aG></IP:aG>',
|
||||
$subject->G('test')
|
||||
);
|
||||
}
|
||||
|
||||
public function testBeforeAndAfterPluginsAreExecuted()
|
||||
{
|
||||
$subject = $this->_objectManager->create(\Magento\Framework\Interception\Fixture\Intercepted::class);
|
||||
$this->assertEquals(
|
||||
'<IP:F><P:D>1: <D>prefix_<F><IP:C><P:C><C>test</C></P:C>' . '</IP:C></F></D></P:D></IP:F>',
|
||||
$subject->A('prefix_')->F('test')
|
||||
);
|
||||
}
|
||||
|
||||
public function testPluginCallsOtherMethodsOnSubject()
|
||||
{
|
||||
$subject = $this->_objectManager->create(\Magento\Framework\Interception\Fixture\Intercepted::class);
|
||||
$this->assertEquals(
|
||||
'<P:K><IP:F><P:D>1: <D>prefix_<F><IP:C><P:C><C><IP:C><P:C><C>test' .
|
||||
'</C></P:C></IP:C></C></P:C></IP:C></F></D></P:D></IP:F></P:K>',
|
||||
$subject->A('prefix_')->K('test')
|
||||
);
|
||||
}
|
||||
|
||||
public function testInterfacePluginsAreInherited()
|
||||
{
|
||||
$subject = $this->_objectManager->create(\Magento\Framework\Interception\Fixture\Intercepted::class);
|
||||
$this->assertEquals('<IP:C><P:C><C>test</C></P:C></IP:C>', $subject->C('test'));
|
||||
}
|
||||
|
||||
public function testInternalMethodCallsAreIntercepted()
|
||||
{
|
||||
$subject = $this->_objectManager->create(\Magento\Framework\Interception\Fixture\Intercepted::class);
|
||||
$this->assertEquals('<B>12<IP:C><P:C><C>1</C></P:C></IP:C></B>', $subject->B('1', '2'));
|
||||
}
|
||||
|
||||
public function testChainedMethodsAreIntercepted()
|
||||
{
|
||||
$subject = $this->_objectManager->create(\Magento\Framework\Interception\Fixture\Intercepted::class);
|
||||
$this->assertEquals('<P:D>1: <D>prefix_test</D></P:D>', $subject->A('prefix_')->D('test'));
|
||||
}
|
||||
|
||||
public function testFinalMethodWorks()
|
||||
{
|
||||
$subject = $this->_objectManager->create(\Magento\Framework\Interception\Fixture\Intercepted::class);
|
||||
$this->assertEquals('<P:D>1: <D>prefix_test</D></P:D>', $subject->A('prefix_')->D('test'));
|
||||
$this->assertEquals('<E>prefix_final</E>', $subject->E('final'));
|
||||
$this->assertEquals('<P:D>2: <D>prefix_test</D></P:D>', $subject->D('test'));
|
||||
}
|
||||
|
||||
public function testObjectKeepsStateBetweenInvocations()
|
||||
{
|
||||
$subject = $this->_objectManager->create(\Magento\Framework\Interception\Fixture\Intercepted::class);
|
||||
$this->assertEquals('<P:D>1: <D>test</D></P:D>', $subject->D('test'));
|
||||
$this->assertEquals('<P:D>2: <D>test</D></P:D>', $subject->D('test'));
|
||||
}
|
||||
}
|
||||
+176
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Magento\Framework\Interception;
|
||||
|
||||
use Magento\Framework\App\Filesystem\DirectoryList;
|
||||
use Magento\Framework\Filesystem\DriverInterface;
|
||||
use Magento\TestFramework\Application;
|
||||
use Magento\TestFramework\Helper\Bootstrap;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Provide tests for PluginListGeneratorTest
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
|
||||
*/
|
||||
class PluginListGeneratorTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* Generated plugin list config for frontend scope
|
||||
*/
|
||||
const CACHE_ID_FRONTEND = 'primary|global|frontend|plugin-list';
|
||||
|
||||
/**
|
||||
* Generated plugin list config for dummy scope
|
||||
*/
|
||||
const CACHE_ID_DUMMY = 'primary|global|dummy|plugin-list';
|
||||
|
||||
private $cacheIds = [self::CACHE_ID_FRONTEND, self::CACHE_ID_DUMMY];
|
||||
|
||||
/**
|
||||
* @var PluginListGenerator
|
||||
*/
|
||||
private $model;
|
||||
|
||||
/**
|
||||
* @var DirectoryList
|
||||
*/
|
||||
private $directoryList;
|
||||
|
||||
/**
|
||||
* @var DriverInterface
|
||||
*/
|
||||
private $file;
|
||||
|
||||
/**
|
||||
* @var Application
|
||||
*/
|
||||
private $application;
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->application = Bootstrap::getInstance()->getBootstrap()->getApplication();
|
||||
$this->directoryList = new DirectoryList(BP, $this->getCustomDirs());
|
||||
$this->file = Bootstrap::getObjectManager()->create(DriverInterface::class);
|
||||
$reader = Bootstrap::getObjectManager()->create(
|
||||
// phpstan:ignore "Class Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy not found."
|
||||
\Magento\Framework\ObjectManager\Config\Reader\Dom\Proxy::class
|
||||
);
|
||||
$scopeConfig = Bootstrap::getObjectManager()->create(\Magento\Framework\Config\Scope::class);
|
||||
$omConfig = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\Interception\ObjectManager\Config\Developer::class
|
||||
);
|
||||
$relations = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\ObjectManager\Relations\Runtime::class
|
||||
);
|
||||
$definitions = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\Interception\Definition\Runtime::class
|
||||
);
|
||||
$classDefinitions = Bootstrap::getObjectManager()->create(
|
||||
\Magento\Framework\ObjectManager\Definition\Runtime::class
|
||||
);
|
||||
// phpstan:ignore "Class Psr\Log\LoggerInterface\Proxy not found."
|
||||
$logger = Bootstrap::getObjectManager()->create(\Psr\Log\LoggerInterface\Proxy::class);
|
||||
$this->model = new PluginListGenerator(
|
||||
$reader,
|
||||
$scopeConfig,
|
||||
$omConfig,
|
||||
$relations,
|
||||
$definitions,
|
||||
$classDefinitions,
|
||||
$logger,
|
||||
$this->directoryList,
|
||||
['primary', 'global']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test plugin list configuration generation and load.
|
||||
*/
|
||||
public function testPluginListConfigGeneration()
|
||||
{
|
||||
$scopes = ['global', 'frontend', 'dummy'];
|
||||
$globalPlugin = 'genericHeaderPlugin';
|
||||
$frontendPlugin = 'response-http-page-cache';
|
||||
$this->model->write($scopes);
|
||||
$configDataFrontend = $this->model->load(self::CACHE_ID_FRONTEND);
|
||||
$this->assertNotEmpty($configDataFrontend[0]);
|
||||
$this->assertNotEmpty($configDataFrontend[1]);
|
||||
$this->assertNotEmpty($configDataFrontend[2]);
|
||||
$expectedFrontend = [
|
||||
1 => [
|
||||
0 => $globalPlugin,
|
||||
1 => $frontendPlugin
|
||||
]
|
||||
];
|
||||
// Here in test is assumed that this class below has 3 plugins. But the amount of plugins and class itself
|
||||
// may vary. If it is changed, please update these assertions.
|
||||
$this->assertArrayHasKey(
|
||||
'Magento\\Framework\\App\\Response\\Http_sendResponse___self',
|
||||
$configDataFrontend[2],
|
||||
'Processed plugin does not exist in the processed plugins array.'
|
||||
);
|
||||
|
||||
$this->assertSame(
|
||||
$expectedFrontend,
|
||||
$configDataFrontend[2]['Magento\\Framework\\App\\Response\\Http_sendResponse___self'],
|
||||
'Plugin configurations are not equal'
|
||||
);
|
||||
|
||||
$configDataDummy = $this->model->load(self::CACHE_ID_DUMMY);
|
||||
/**
|
||||
* Make sure "dummy" scope with no plugins in system should not contain plugins from "frontend" scope
|
||||
*/
|
||||
$this->assertNotContains(
|
||||
$frontendPlugin,
|
||||
$configDataDummy[2]['Magento\\Framework\\App\\Response\\Http_sendResponse___self'][1],
|
||||
'Plugin configurations are not equal. "dummy" scope should not contain plugins from "frontend" scope'
|
||||
);
|
||||
/**
|
||||
* Make sure "dummy" scope with no plugins in system should contain plugins from "global" scope
|
||||
*/
|
||||
$this->assertContains(
|
||||
$globalPlugin,
|
||||
$configDataDummy[2]['Magento\\Framework\\App\\Response\\Http_sendResponse___self'][1],
|
||||
'Plugin configurations are not equal. "dummy" scope should contain plugins from "global" scope'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets customized directory paths
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function getCustomDirs(): array
|
||||
{
|
||||
$path = DirectoryList::PATH;
|
||||
$generated = "{$this->application->getTempDir()}/generated";
|
||||
|
||||
return [
|
||||
DirectoryList::GENERATED_METADATA => [$path => "{$generated}/metadata"],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
protected function tearDown(): void
|
||||
{
|
||||
foreach ($this->cacheIds as $cacheId) {
|
||||
$filePath = $this->directoryList->getPath(DirectoryList::GENERATED_METADATA)
|
||||
. '/' . $cacheId . '.' . 'php';
|
||||
|
||||
if (file_exists($filePath)) {
|
||||
$this->file->deleteFile($filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
<?php
|
||||
/**
|
||||
* Copyright © Magento, Inc. All rights reserved.
|
||||
* See COPYING.txt for license details.
|
||||
*/
|
||||
namespace Magento\Framework\Interception;
|
||||
|
||||
/**
|
||||
* Class TwoPluginTest
|
||||
*/
|
||||
class TwoPluginTest extends AbstractPlugin
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->setUpInterceptionConfig(
|
||||
[\Magento\Framework\Interception\Fixture\Intercepted::class => [
|
||||
'plugins' => [
|
||||
'first' => [
|
||||
'instance' => \Magento\Framework\Interception\Fixture\Intercepted\FirstPlugin::class,
|
||||
'sortOrder' => 10,
|
||||
], 'second' => [
|
||||
'instance' => \Magento\Framework\Interception\Fixture\Intercepted\Plugin::class,
|
||||
'sortOrder' => 20,
|
||||
]
|
||||
],
|
||||
]
|
||||
]
|
||||
);
|
||||
|
||||
parent::setUp();
|
||||
}
|
||||
|
||||
public function testPluginBeforeWins()
|
||||
{
|
||||
$subject = $this->_objectManager->create(\Magento\Framework\Interception\Fixture\Intercepted::class);
|
||||
$this->assertEquals('<X><P:bX/></X>', $subject->X('test'));
|
||||
}
|
||||
|
||||
public function testPluginAroundWins()
|
||||
{
|
||||
$subject = $this->_objectManager->create(\Magento\Framework\Interception\Fixture\Intercepted::class);
|
||||
$this->assertEquals('<F:Y>test<F:Y/>', $subject->Y('test'));
|
||||
}
|
||||
|
||||
public function testPluginAfterWins()
|
||||
{
|
||||
$subject = $this->_objectManager->create(\Magento\Framework\Interception\Fixture\Intercepted::class);
|
||||
$this->assertEquals('<P:aZ/>', $subject->Z('test'));
|
||||
}
|
||||
|
||||
public function testPluginBeforeAroundWins()
|
||||
{
|
||||
$subject = $this->_objectManager->create(\Magento\Framework\Interception\Fixture\Intercepted::class);
|
||||
$this->assertEquals('<F:V><F:bV/><F:V/>', $subject->V('test'));
|
||||
}
|
||||
|
||||
public function testPluginBeforeAroundAfterWins()
|
||||
{
|
||||
$subject = $this->_objectManager->create(\Magento\Framework\Interception\Fixture\Intercepted::class);
|
||||
$this->assertEquals('<F:aW/>', $subject->W('test'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user