-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
extra tests for current interception behavior #965
Merged
magento-team
merged 4 commits into
magento:develop
from
fooman:interception-sort-order-effect-unchained
Jan 30, 2015
Merged
Changes from 3 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
dev/tests/integration/testsuite/Magento/Framework/Interception/AbstractPlugin.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
/** | ||
* | ||
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) | ||
*/ | ||
namespace Magento\Framework\Interception; | ||
|
||
use Magento\Framework\ObjectManager\Config\Config as ObjectManagerConfig; | ||
|
||
/** | ||
* Class GeneralTest | ||
* @SuppressWarnings(PHPMD.CouplingBetweenObjects) | ||
*/ | ||
abstract class AbstractPlugin extends \PHPUnit_Framework_TestCase | ||
{ | ||
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', | ||
], | ||
] | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
.../integration/testsuite/Magento/Framework/Interception/Fixture/Intercepted/FirstPlugin.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
/** | ||
* | ||
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) | ||
*/ | ||
namespace Magento\Framework\Interception\Fixture\Intercepted; | ||
|
||
use Magento\Framework\Interception\Fixture\Intercepted; | ||
|
||
class FirstPlugin | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
protected $_counter = 0; | ||
|
||
public function aroundC(Intercepted $subject, \Closure $next, $param1) | ||
{ | ||
return '<F:C>' . $next($param1) . '</F:C>'; | ||
} | ||
|
||
public function aroundD(Intercepted $subject, \Closure $next, $param1) | ||
{ | ||
$this->_counter++; | ||
return '<F:D>' . $this->_counter . ': ' . $next($param1) . '</F:D>'; | ||
} | ||
|
||
public function aroundK(Intercepted $subject, \Closure $next, $param1) | ||
{ | ||
$result = $subject->C($param1); | ||
return '<F:K>' . $subject->F($result) . '</F:K>'; | ||
} | ||
|
||
public function beforeG(Intercepted $subject, $param1) | ||
{ | ||
return ['<F:bG>' . $param1 . '</F:bG>']; | ||
} | ||
|
||
public function aroundG(Intercepted $subject, \Closure $next, $param1) | ||
{ | ||
return $next('<F:G>' . $param1 . '</F:G>'); | ||
} | ||
|
||
public function afterG(Intercepted $subject, $result) | ||
{ | ||
return '<F:aG>' . $result . '</F:aG>'; | ||
} | ||
|
||
public function beforeV(Intercepted $subject, $param1) | ||
{ | ||
return ['<F:bV/>']; | ||
} | ||
|
||
public function aroundV(Intercepted $subject, \Closure $next, $param1) | ||
{ | ||
return '<F:V>' . $param1 . '<F:V/>'; | ||
} | ||
|
||
public function beforeW(Intercepted $subject, $param1) | ||
{ | ||
return ['<F:bV/>']; | ||
} | ||
|
||
public function aroundW(Intercepted $subject, \Closure $next, $param1) | ||
{ | ||
return '<F:V>' . $param1 . '<F:V/>'; | ||
} | ||
|
||
public function afterW(Intercepted $subject, $result) | ||
{ | ||
return '<F:aW/>'; | ||
} | ||
|
||
public function beforeX(Intercepted $subject, $param1) | ||
{ | ||
return ['<F:bX/>']; | ||
} | ||
|
||
public function aroundY(Intercepted $subject, \Closure $next, $param1) | ||
{ | ||
return '<F:Y>' . $param1 . '<F:Y/>'; | ||
} | ||
|
||
public function afterZ(Intercepted $subject, $result) | ||
{ | ||
return '<F:aZ/>'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,4 +45,44 @@ public function afterG(Intercepted $subject, $result) | |
{ | ||
return '<P:aG>' . $result . '</P:aG>'; | ||
} | ||
|
||
public function beforeV(Intercepted $subject, $param1) | ||
{ | ||
return ['<P:bV/>']; | ||
} | ||
|
||
public function aroundV(Intercepted $subject, \Closure $next, $param1) | ||
{ | ||
return '<P:V>' . $param1 . '<P:V/>'; | ||
} | ||
|
||
public function beforeW(Intercepted $subject, $param1) | ||
{ | ||
return ['<P:bV/>']; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as comment for V and bV to be W and bW There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for noticing this - will push an update shortly. |
||
} | ||
|
||
public function aroundW(Intercepted $subject, \Closure $next, $param1) | ||
{ | ||
return '<P:V>' . $param1 . '<P:V/>'; | ||
} | ||
|
||
public function afterW(Intercepted $subject, $result) | ||
{ | ||
return '<P:aW/>'; | ||
} | ||
|
||
public function beforeX(Intercepted $subject, $param1) | ||
{ | ||
return ['<P:bX/>']; | ||
} | ||
|
||
public function aroundY(Intercepted $subject, \Closure $next, $param1) | ||
{ | ||
return '<P:Y>' . $param1 . '<P:Y/>'; | ||
} | ||
|
||
public function afterZ(Intercepted $subject, $result) | ||
{ | ||
return '<P:aZ/>'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
dev/tests/integration/testsuite/Magento/Framework/Interception/TwoPluginTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
/** | ||
* | ||
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com) | ||
*/ | ||
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')); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be "bW" instead of bV? Same for the aroundW().