diff --git a/dev/tests/integration/testsuite/Magento/Framework/Interception/AbstractPlugin.php b/dev/tests/integration/testsuite/Magento/Framework/Interception/AbstractPlugin.php new file mode 100644 index 0000000000000..5201891a8c226 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Framework/Interception/AbstractPlugin.php @@ -0,0 +1,73 @@ +_configReader = $this->getMock('Magento\Framework\Config\ReaderInterface'); + $this->_configReader->expects( + $this->any() + )->method( + 'read' + )->will( + $this->returnValue($pluginConfig) + ); + + $areaList = $this->getMock('Magento\Framework\App\AreaList', [], [], '', false); + $areaList->expects($this->any())->method('getCodes')->will($this->returnValue([])); + $configScope = new \Magento\Framework\Config\Scope($areaList, 'global'); + $cache = $this->getMock('Magento\Framework\Config\CacheInterface'); + $cache->expects($this->any())->method('load')->will($this->returnValue(false)); + $definitions = new \Magento\Framework\ObjectManager\Definition\Runtime(); + $relations = new \Magento\Framework\ObjectManager\Relations\Runtime(); + $interceptionConfig = new Config\Config( + $this->_configReader, + $configScope, + $cache, + $relations, + $config, + $definitions + ); + $interceptionDefinitions = new Definition\Runtime(); + $this->_objectManager = new \Magento\Framework\ObjectManager\ObjectManager( + $factory, + $config, + [ + 'Magento\Framework\Config\CacheInterface' => $cache, + 'Magento\Framework\Config\ScopeInterface' => $configScope, + 'Magento\Framework\Config\ReaderInterface' => $this->_configReader, + 'Magento\Framework\ObjectManager\RelationsInterface' => $relations, + 'Magento\Framework\ObjectManager\ConfigInterface' => $config, + 'Magento\Framework\Interception\ObjectManager\ConfigInterface' => $config, + 'Magento\Framework\ObjectManager\DefinitionInterface' => $definitions, + 'Magento\Framework\Interception\DefinitionInterface' => $interceptionDefinitions + ] + ); + $factory->setObjectManager($this->_objectManager); + $config->setInterceptionConfig($interceptionConfig); + $config->extend( + [ + 'preferences' => [ + 'Magento\Framework\Interception\PluginListInterface' => + 'Magento\Framework\Interception\PluginList\PluginList', + 'Magento\Framework\Interception\ChainInterface' => + 'Magento\Framework\Interception\Chain\Chain', + ], + ] + ); + } +} diff --git a/dev/tests/integration/testsuite/Magento/Framework/Interception/Fixture/Intercepted.php b/dev/tests/integration/testsuite/Magento/Framework/Interception/Fixture/Intercepted.php index 84988bbba5b03..6b9a318344cb7 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Interception/Fixture/Intercepted.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Interception/Fixture/Intercepted.php @@ -49,4 +49,29 @@ public function K($param1) { return '' . $param1 . ''; } + + public function V($param1) + { + return '' . $param1 . ''; + } + + public function W($param1) + { + return '' . $param1 . ''; + } + + public function X($param1) + { + return '' . $param1 . ''; + } + + public function Y($param1) + { + return '' . $param1 . ''; + } + + public function Z($param1) + { + return '' . $param1 . ''; + } } diff --git a/dev/tests/integration/testsuite/Magento/Framework/Interception/Fixture/Intercepted/FirstPlugin.php b/dev/tests/integration/testsuite/Magento/Framework/Interception/Fixture/Intercepted/FirstPlugin.php new file mode 100644 index 0000000000000..a98e48ef926c9 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Framework/Interception/Fixture/Intercepted/FirstPlugin.php @@ -0,0 +1,88 @@ +' . $next($param1) . ''; + } + + public function aroundD(Intercepted $subject, \Closure $next, $param1) + { + $this->_counter++; + return '' . $this->_counter . ': ' . $next($param1) . ''; + } + + public function aroundK(Intercepted $subject, \Closure $next, $param1) + { + $result = $subject->C($param1); + return '' . $subject->F($result) . ''; + } + + public function beforeG(Intercepted $subject, $param1) + { + return ['' . $param1 . '']; + } + + public function aroundG(Intercepted $subject, \Closure $next, $param1) + { + return $next('' . $param1 . ''); + } + + public function afterG(Intercepted $subject, $result) + { + return '' . $result . ''; + } + + public function beforeV(Intercepted $subject, $param1) + { + return ['']; + } + + public function aroundV(Intercepted $subject, \Closure $next, $param1) + { + return '' . $param1 . ''; + } + + public function beforeW(Intercepted $subject, $param1) + { + return ['']; + } + + public function aroundW(Intercepted $subject, \Closure $next, $param1) + { + return '' . $param1 . ''; + } + + public function afterW(Intercepted $subject, $result) + { + return ''; + } + + public function beforeX(Intercepted $subject, $param1) + { + return ['']; + } + + public function aroundY(Intercepted $subject, \Closure $next, $param1) + { + return '' . $param1 . ''; + } + + public function afterZ(Intercepted $subject, $result) + { + return ''; + } +} diff --git a/dev/tests/integration/testsuite/Magento/Framework/Interception/Fixture/Intercepted/Plugin.php b/dev/tests/integration/testsuite/Magento/Framework/Interception/Fixture/Intercepted/Plugin.php index 06e04190ae49b..df0eb523b96d6 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Interception/Fixture/Intercepted/Plugin.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Interception/Fixture/Intercepted/Plugin.php @@ -45,4 +45,44 @@ public function afterG(Intercepted $subject, $result) { return '' . $result . ''; } + + public function beforeV(Intercepted $subject, $param1) + { + return ['']; + } + + public function aroundV(Intercepted $subject, \Closure $next, $param1) + { + return '' . $param1 . ''; + } + + public function beforeW(Intercepted $subject, $param1) + { + return ['']; + } + + public function aroundW(Intercepted $subject, \Closure $next, $param1) + { + return '' . $param1 . ''; + } + + public function afterW(Intercepted $subject, $result) + { + return ''; + } + + public function beforeX(Intercepted $subject, $param1) + { + return ['']; + } + + public function aroundY(Intercepted $subject, \Closure $next, $param1) + { + return '' . $param1 . ''; + } + + public function afterZ(Intercepted $subject, $result) + { + return ''; + } } diff --git a/dev/tests/integration/testsuite/Magento/Framework/Interception/GeneralTest.php b/dev/tests/integration/testsuite/Magento/Framework/Interception/GeneralTest.php index bd54fecae3c2f..bcd6c751e4af6 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Interception/GeneralTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Interception/GeneralTest.php @@ -11,7 +11,7 @@ * Class GeneralTest * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class GeneralTest extends \PHPUnit_Framework_TestCase +class GeneralTest extends AbstractPlugin { /** * @var \PHPUnit_Framework_MockObject_MockObject @@ -25,76 +25,26 @@ class GeneralTest extends \PHPUnit_Framework_TestCase public function setUp() { - $config = new \Magento\Framework\Interception\ObjectManager\Config\Developer(); - $factory = new \Magento\Framework\ObjectManager\Factory\Dynamic\Developer($config, null); - - $this->_configReader = $this->getMock('Magento\Framework\Config\ReaderInterface'); - $this->_configReader->expects( - $this->any() - )->method( - 'read' - )->will( - $this->returnValue( - [ - 'Magento\Framework\Interception\Fixture\InterceptedInterface' => [ + $this->setUpInterceptionConfig( + [ + 'Magento\Framework\Interception\Fixture\InterceptedInterface' => + [ 'plugins' => [ 'first' => [ - 'instance' => 'Magento\Framework\Interception\Fixture\Intercepted\InterfacePlugin', + 'instance' => 'Magento\Framework\Interception\Fixture\Intercepted\InterfacePlugin', 'sortOrder' => 10, ], ], ], - 'Magento\Framework\Interception\Fixture\Intercepted' => [ + 'Magento\Framework\Interception\Fixture\Intercepted' => + [ 'plugins' => [ 'second' => [ - 'instance' => 'Magento\Framework\Interception\Fixture\Intercepted\Plugin', + 'instance' => 'Magento\Framework\Interception\Fixture\Intercepted\Plugin', 'sortOrder' => 20, ], ], ], - ] - ) - ); - - $areaList = $this->getMock('Magento\Framework\App\AreaList', [], [], '', false); - $areaList->expects($this->any())->method('getCodes')->will($this->returnValue([])); - $configScope = new \Magento\Framework\Config\Scope($areaList, 'global'); - $cache = $this->getMock('Magento\Framework\Config\CacheInterface'); - $cache->expects($this->any())->method('load')->will($this->returnValue(false)); - $definitions = new \Magento\Framework\ObjectManager\Definition\Runtime(); - $relations = new \Magento\Framework\ObjectManager\Relations\Runtime(); - $interceptionConfig = new Config\Config( - $this->_configReader, - $configScope, - $cache, - $relations, - $config, - $definitions - ); - $interceptionDefinitions = new Definition\Runtime(); - $this->_objectManager = new \Magento\Framework\ObjectManager\ObjectManager( - $factory, - $config, - [ - 'Magento\Framework\Config\CacheInterface' => $cache, - 'Magento\Framework\Config\ScopeInterface' => $configScope, - 'Magento\Framework\Config\ReaderInterface' => $this->_configReader, - 'Magento\Framework\ObjectManager\RelationsInterface' => $relations, - 'Magento\Framework\ObjectManager\ConfigInterface' => $config, - 'Magento\Framework\Interception\ObjectManager\ConfigInterface' => $config, - 'Magento\Framework\ObjectManager\DefinitionInterface' => $definitions, - 'Magento\Framework\Interception\DefinitionInterface' => $interceptionDefinitions - ] - ); - $factory->setObjectManager($this->_objectManager); - $config->setInterceptionConfig($interceptionConfig); - $config->extend( - [ - 'preferences' => [ - 'Magento\Framework\Interception\PluginListInterface' => - 'Magento\Framework\Interception\PluginList\PluginList', - 'Magento\Framework\Interception\ChainInterface' => 'Magento\Framework\Interception\Chain\Chain', - ], ] ); } diff --git a/dev/tests/integration/testsuite/Magento/Framework/Interception/TwoPluginTest.php b/dev/tests/integration/testsuite/Magento/Framework/Interception/TwoPluginTest.php new file mode 100644 index 0000000000000..8a0c2e8c1e9ba --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Framework/Interception/TwoPluginTest.php @@ -0,0 +1,61 @@ +setUpInterceptionConfig( + [ + 'Magento\Framework\Interception\Fixture\Intercepted' => [ + 'plugins' => [ + 'first' => [ + 'instance' => 'Magento\Framework\Interception\Fixture\Intercepted\FirstPlugin', + 'sortOrder' => 10, + ], 'second' => [ + 'instance' => 'Magento\Framework\Interception\Fixture\Intercepted\Plugin', + 'sortOrder' => 20, + ] + ], + ] + ] + ); + } + + public function testPluginBeforeWins() + { + $subject = $this->_objectManager->create('Magento\Framework\Interception\Fixture\Intercepted'); + $this->assertEquals('', $subject->X('test')); + } + + public function testPluginAroundWins() + { + $subject = $this->_objectManager->create('Magento\Framework\Interception\Fixture\Intercepted'); + $this->assertEquals('test', $subject->Y('test')); + } + + public function testPluginAfterWins() + { + $subject = $this->_objectManager->create('Magento\Framework\Interception\Fixture\Intercepted'); + $this->assertEquals('', $subject->Z('test')); + } + + public function testPluginBeforeAroundWins() + { + $subject = $this->_objectManager->create('Magento\Framework\Interception\Fixture\Intercepted'); + $this->assertEquals('', $subject->V('test')); + } + + public function testPluginBeforeAroundAfterWins() + { + $subject = $this->_objectManager->create('Magento\Framework\Interception\Fixture\Intercepted'); + $this->assertEquals('', $subject->W('test')); + } +}