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 0000000000000000000000000000000000000000..1539ad87f28dfcaaedca40f1418f4cc26c8198f5 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Framework/Interception/AbstractPlugin.php @@ -0,0 +1,82 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\Interception; + +/** + * Class GeneralTest + * @SuppressWarnings(PHPMD.CouplingBetweenObjects) + */ +abstract class AbstractPlugin extends \PHPUnit_Framework_TestCase +{ + + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + protected $_configReader; + + /** + * @var \Magento\Framework\ObjectManagerInterface + */ + protected $_objectManager; + + 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->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 8625ff972836b0c3cb949bb4c17e5696e34afbbf..6213b569b94e5052c57210621ed0b51b13c289f8 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Interception/Fixture/Intercepted.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Interception/Fixture/Intercepted.php @@ -77,4 +77,44 @@ class Intercepted extends InterceptedParent implements InterceptedInterface { 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>'; + } } 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 0000000000000000000000000000000000000000..3babf53be8f8e54cbc5ebe9de229e80b01becdd4 --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Framework/Interception/Fixture/Intercepted/FirstPlugin.php @@ -0,0 +1,130 @@ +<?php +/** + * Copyright © 2015 Magento. 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/>'; + } +} 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 f8ce0abe8d8b9d0c285df20abfaed1c35e176690..fab9c11c709fee250d00d3bd1fe5ff9c1a3ad4f1 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 @@ -64,4 +64,68 @@ class Plugin { 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/>'; + } } diff --git a/dev/tests/integration/testsuite/Magento/Framework/Interception/GeneralTest.php b/dev/tests/integration/testsuite/Magento/Framework/Interception/GeneralTest.php index 8b2db1eafdbce5361b356a231411cd158fe0b033..dfeb14900296ee264a47089b051c53cb0a82ee63 100644 --- a/dev/tests/integration/testsuite/Magento/Framework/Interception/GeneralTest.php +++ b/dev/tests/integration/testsuite/Magento/Framework/Interception/GeneralTest.php @@ -1,6 +1,5 @@ <?php /** - * * Copyright © 2015 Magento. All rights reserved. * See COPYING.txt for license details. */ @@ -10,90 +9,30 @@ namespace Magento\Framework\Interception; * Class GeneralTest * @SuppressWarnings(PHPMD.CouplingBetweenObjects) */ -class GeneralTest extends \PHPUnit_Framework_TestCase +class GeneralTest extends AbstractPlugin { - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - protected $_configReader; - - /** - * @var \Magento\Framework\ObjectManagerInterface - */ - protected $_objectManager; - 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 0000000000000000000000000000000000000000..a4cbcd18f1103952d43884c3c34c11f0278e9e4d --- /dev/null +++ b/dev/tests/integration/testsuite/Magento/Framework/Interception/TwoPluginTest.php @@ -0,0 +1,61 @@ +<?php +/** + * Copyright © 2015 Magento. All rights reserved. + * See COPYING.txt for license details. + */ +namespace Magento\Framework\Interception; + +/** + * Class TwoPluginTest + */ +class TwoPluginTest extends AbstractPlugin +{ + public function setUp() + { + $this->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('<X><P:bX/></X>', $subject->X('test')); + } + + public function testPluginAroundWins() + { + $subject = $this->_objectManager->create('Magento\Framework\Interception\Fixture\Intercepted'); + $this->assertEquals('<F:Y>test<F:Y/>', $subject->Y('test')); + } + + public function testPluginAfterWins() + { + $subject = $this->_objectManager->create('Magento\Framework\Interception\Fixture\Intercepted'); + $this->assertEquals('<P:aZ/>', $subject->Z('test')); + } + + public function testPluginBeforeAroundWins() + { + $subject = $this->_objectManager->create('Magento\Framework\Interception\Fixture\Intercepted'); + $this->assertEquals('<F:V><F:bV/><F:V/>', $subject->V('test')); + } + + public function testPluginBeforeAroundAfterWins() + { + $subject = $this->_objectManager->create('Magento\Framework\Interception\Fixture\Intercepted'); + $this->assertEquals('<F:aW/>', $subject->W('test')); + } +}