Skip to content

Commit 205a6e0

Browse files
committed
Merge branch 'interception-sort-order-effect-unchained' of https://github.com/fooman/magento2 into MAGETWO-32870
2 parents 1bba5fe + 6e9947f commit 205a6e0

File tree

6 files changed

+296
-59
lines changed

6 files changed

+296
-59
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
/**
3+
*
4+
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
5+
*/
6+
namespace Magento\Framework\Interception;
7+
8+
use Magento\Framework\ObjectManager\Config\Config as ObjectManagerConfig;
9+
10+
/**
11+
* Class GeneralTest
12+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
13+
*/
14+
abstract class AbstractPlugin extends \PHPUnit_Framework_TestCase
15+
{
16+
public function setUpInterceptionConfig($pluginConfig)
17+
{
18+
$config = new \Magento\Framework\Interception\ObjectManager\Config\Developer();
19+
$factory = new \Magento\Framework\ObjectManager\Factory\Dynamic\Developer($config, null);
20+
21+
$this->_configReader = $this->getMock('Magento\Framework\Config\ReaderInterface');
22+
$this->_configReader->expects(
23+
$this->any()
24+
)->method(
25+
'read'
26+
)->will(
27+
$this->returnValue($pluginConfig)
28+
);
29+
30+
$areaList = $this->getMock('Magento\Framework\App\AreaList', [], [], '', false);
31+
$areaList->expects($this->any())->method('getCodes')->will($this->returnValue([]));
32+
$configScope = new \Magento\Framework\Config\Scope($areaList, 'global');
33+
$cache = $this->getMock('Magento\Framework\Config\CacheInterface');
34+
$cache->expects($this->any())->method('load')->will($this->returnValue(false));
35+
$definitions = new \Magento\Framework\ObjectManager\Definition\Runtime();
36+
$relations = new \Magento\Framework\ObjectManager\Relations\Runtime();
37+
$interceptionConfig = new Config\Config(
38+
$this->_configReader,
39+
$configScope,
40+
$cache,
41+
$relations,
42+
$config,
43+
$definitions
44+
);
45+
$interceptionDefinitions = new Definition\Runtime();
46+
$this->_objectManager = new \Magento\Framework\ObjectManager\ObjectManager(
47+
$factory,
48+
$config,
49+
[
50+
'Magento\Framework\Config\CacheInterface' => $cache,
51+
'Magento\Framework\Config\ScopeInterface' => $configScope,
52+
'Magento\Framework\Config\ReaderInterface' => $this->_configReader,
53+
'Magento\Framework\ObjectManager\RelationsInterface' => $relations,
54+
'Magento\Framework\ObjectManager\ConfigInterface' => $config,
55+
'Magento\Framework\Interception\ObjectManager\ConfigInterface' => $config,
56+
'Magento\Framework\ObjectManager\DefinitionInterface' => $definitions,
57+
'Magento\Framework\Interception\DefinitionInterface' => $interceptionDefinitions
58+
]
59+
);
60+
$factory->setObjectManager($this->_objectManager);
61+
$config->setInterceptionConfig($interceptionConfig);
62+
$config->extend(
63+
[
64+
'preferences' => [
65+
'Magento\Framework\Interception\PluginListInterface' =>
66+
'Magento\Framework\Interception\PluginList\PluginList',
67+
'Magento\Framework\Interception\ChainInterface' =>
68+
'Magento\Framework\Interception\Chain\Chain',
69+
],
70+
]
71+
);
72+
}
73+
}

dev/tests/integration/testsuite/Magento/Framework/Interception/Fixture/Intercepted.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,29 @@ public function K($param1)
5050
{
5151
return '<K>' . $param1 . '</K>';
5252
}
53+
54+
public function V($param1)
55+
{
56+
return '<V>' . $param1 . '</V>';
57+
}
58+
59+
public function W($param1)
60+
{
61+
return '<W>' . $param1 . '</W>';
62+
}
63+
64+
public function X($param1)
65+
{
66+
return '<X>' . $param1 . '</X>';
67+
}
68+
69+
public function Y($param1)
70+
{
71+
return '<Y>' . $param1 . '</Y>';
72+
}
73+
74+
public function Z($param1)
75+
{
76+
return '<Z>' . $param1 . '</Z>';
77+
}
5378
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
<?php
2+
/**
3+
*
4+
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
5+
*/
6+
namespace Magento\Framework\Interception\Fixture\Intercepted;
7+
8+
use Magento\Framework\Interception\Fixture\Intercepted;
9+
10+
class FirstPlugin
11+
{
12+
/**
13+
* @var int
14+
*/
15+
protected $_counter = 0;
16+
17+
public function aroundC(Intercepted $subject, \Closure $next, $param1)
18+
{
19+
return '<F:C>' . $next($param1) . '</F:C>';
20+
}
21+
22+
public function aroundD(Intercepted $subject, \Closure $next, $param1)
23+
{
24+
$this->_counter++;
25+
return '<F:D>' . $this->_counter . ': ' . $next($param1) . '</F:D>';
26+
}
27+
28+
public function aroundK(Intercepted $subject, \Closure $next, $param1)
29+
{
30+
$result = $subject->C($param1);
31+
return '<F:K>' . $subject->F($result) . '</F:K>';
32+
}
33+
34+
public function beforeG(Intercepted $subject, $param1)
35+
{
36+
return ['<F:bG>' . $param1 . '</F:bG>'];
37+
}
38+
39+
public function aroundG(Intercepted $subject, \Closure $next, $param1)
40+
{
41+
return $next('<F:G>' . $param1 . '</F:G>');
42+
}
43+
44+
public function afterG(Intercepted $subject, $result)
45+
{
46+
return '<F:aG>' . $result . '</F:aG>';
47+
}
48+
49+
public function beforeV(Intercepted $subject, $param1)
50+
{
51+
return ['<F:bV/>'];
52+
}
53+
54+
public function aroundV(Intercepted $subject, \Closure $next, $param1)
55+
{
56+
return '<F:V>' . $param1 . '<F:V/>';
57+
}
58+
59+
public function beforeW(Intercepted $subject, $param1)
60+
{
61+
return ['<F:bW/>'];
62+
}
63+
64+
public function aroundW(Intercepted $subject, \Closure $next, $param1)
65+
{
66+
return '<F:W>' . $param1 . '<F:W/>';
67+
}
68+
69+
public function afterW(Intercepted $subject, $result)
70+
{
71+
return '<F:aW/>';
72+
}
73+
74+
public function beforeX(Intercepted $subject, $param1)
75+
{
76+
return ['<F:bX/>'];
77+
}
78+
79+
public function aroundY(Intercepted $subject, \Closure $next, $param1)
80+
{
81+
return '<F:Y>' . $param1 . '<F:Y/>';
82+
}
83+
84+
public function afterZ(Intercepted $subject, $result)
85+
{
86+
return '<F:aZ/>';
87+
}
88+
}

dev/tests/integration/testsuite/Magento/Framework/Interception/Fixture/Intercepted/Plugin.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,44 @@ public function afterG(Intercepted $subject, $result)
4646
{
4747
return '<P:aG>' . $result . '</P:aG>';
4848
}
49+
50+
public function beforeV(Intercepted $subject, $param1)
51+
{
52+
return ['<P:bV/>'];
53+
}
54+
55+
public function aroundV(Intercepted $subject, \Closure $next, $param1)
56+
{
57+
return '<P:V>' . $param1 . '<P:V/>';
58+
}
59+
60+
public function beforeW(Intercepted $subject, $param1)
61+
{
62+
return ['<P:bW/>'];
63+
}
64+
65+
public function aroundW(Intercepted $subject, \Closure $next, $param1)
66+
{
67+
return '<P:W>' . $param1 . '<P:W/>';
68+
}
69+
70+
public function afterW(Intercepted $subject, $result)
71+
{
72+
return '<P:aW/>';
73+
}
74+
75+
public function beforeX(Intercepted $subject, $param1)
76+
{
77+
return ['<P:bX/>'];
78+
}
79+
80+
public function aroundY(Intercepted $subject, \Closure $next, $param1)
81+
{
82+
return '<P:Y>' . $param1 . '<P:Y/>';
83+
}
84+
85+
public function afterZ(Intercepted $subject, $result)
86+
{
87+
return '<P:aZ/>';
88+
}
4989
}

dev/tests/integration/testsuite/Magento/Framework/Interception/GeneralTest.php

Lines changed: 9 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* Class GeneralTest
1111
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
1212
*/
13-
class GeneralTest extends \PHPUnit_Framework_TestCase
13+
class GeneralTest extends AbstractPlugin
1414
{
1515
/**
1616
* @var \PHPUnit_Framework_MockObject_MockObject
@@ -24,76 +24,26 @@ class GeneralTest extends \PHPUnit_Framework_TestCase
2424

2525
public function setUp()
2626
{
27-
$config = new \Magento\Framework\Interception\ObjectManager\Config\Developer();
28-
$factory = new \Magento\Framework\ObjectManager\Factory\Dynamic\Developer($config, null);
29-
30-
$this->_configReader = $this->getMock('Magento\Framework\Config\ReaderInterface');
31-
$this->_configReader->expects(
32-
$this->any()
33-
)->method(
34-
'read'
35-
)->will(
36-
$this->returnValue(
37-
[
38-
'Magento\Framework\Interception\Fixture\InterceptedInterface' => [
27+
$this->setUpInterceptionConfig(
28+
[
29+
'Magento\Framework\Interception\Fixture\InterceptedInterface' =>
30+
[
3931
'plugins' => [
4032
'first' => [
41-
'instance' => 'Magento\Framework\Interception\Fixture\Intercepted\InterfacePlugin',
33+
'instance' => 'Magento\Framework\Interception\Fixture\Intercepted\InterfacePlugin',
4234
'sortOrder' => 10,
4335
],
4436
],
4537
],
46-
'Magento\Framework\Interception\Fixture\Intercepted' => [
38+
'Magento\Framework\Interception\Fixture\Intercepted' =>
39+
[
4740
'plugins' => [
4841
'second' => [
49-
'instance' => 'Magento\Framework\Interception\Fixture\Intercepted\Plugin',
42+
'instance' => 'Magento\Framework\Interception\Fixture\Intercepted\Plugin',
5043
'sortOrder' => 20,
5144
],
5245
],
5346
],
54-
]
55-
)
56-
);
57-
58-
$areaList = $this->getMock('Magento\Framework\App\AreaList', [], [], '', false);
59-
$areaList->expects($this->any())->method('getCodes')->will($this->returnValue([]));
60-
$configScope = new \Magento\Framework\Config\Scope($areaList, 'global');
61-
$cache = $this->getMock('Magento\Framework\Config\CacheInterface');
62-
$cache->expects($this->any())->method('load')->will($this->returnValue(false));
63-
$definitions = new \Magento\Framework\ObjectManager\Definition\Runtime();
64-
$relations = new \Magento\Framework\ObjectManager\Relations\Runtime();
65-
$interceptionConfig = new Config\Config(
66-
$this->_configReader,
67-
$configScope,
68-
$cache,
69-
$relations,
70-
$config,
71-
$definitions
72-
);
73-
$interceptionDefinitions = new Definition\Runtime();
74-
$this->_objectManager = new \Magento\Framework\ObjectManager\ObjectManager(
75-
$factory,
76-
$config,
77-
[
78-
'Magento\Framework\Config\CacheInterface' => $cache,
79-
'Magento\Framework\Config\ScopeInterface' => $configScope,
80-
'Magento\Framework\Config\ReaderInterface' => $this->_configReader,
81-
'Magento\Framework\ObjectManager\RelationsInterface' => $relations,
82-
'Magento\Framework\ObjectManager\ConfigInterface' => $config,
83-
'Magento\Framework\Interception\ObjectManager\ConfigInterface' => $config,
84-
'Magento\Framework\ObjectManager\DefinitionInterface' => $definitions,
85-
'Magento\Framework\Interception\DefinitionInterface' => $interceptionDefinitions
86-
]
87-
);
88-
$factory->setObjectManager($this->_objectManager);
89-
$config->setInterceptionConfig($interceptionConfig);
90-
$config->extend(
91-
[
92-
'preferences' => [
93-
'Magento\Framework\Interception\PluginListInterface' =>
94-
'Magento\Framework\Interception\PluginList\PluginList',
95-
'Magento\Framework\Interception\ChainInterface' => 'Magento\Framework\Interception\Chain\Chain',
96-
],
9747
]
9848
);
9949
}
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/**
3+
*
4+
* @copyright Copyright (c) 2014 X.commerce, Inc. (http://www.magentocommerce.com)
5+
*/
6+
namespace Magento\Framework\Interception;
7+
8+
/**
9+
* Class TwoPluginTest
10+
*/
11+
class TwoPluginTest extends AbstractPlugin
12+
{
13+
public function setUp()
14+
{
15+
$this->setUpInterceptionConfig(
16+
[
17+
'Magento\Framework\Interception\Fixture\Intercepted' => [
18+
'plugins' => [
19+
'first' => [
20+
'instance' => 'Magento\Framework\Interception\Fixture\Intercepted\FirstPlugin',
21+
'sortOrder' => 10,
22+
], 'second' => [
23+
'instance' => 'Magento\Framework\Interception\Fixture\Intercepted\Plugin',
24+
'sortOrder' => 20,
25+
]
26+
],
27+
]
28+
]
29+
);
30+
}
31+
32+
public function testPluginBeforeWins()
33+
{
34+
$subject = $this->_objectManager->create('Magento\Framework\Interception\Fixture\Intercepted');
35+
$this->assertEquals('<X><P:bX/></X>', $subject->X('test'));
36+
}
37+
38+
public function testPluginAroundWins()
39+
{
40+
$subject = $this->_objectManager->create('Magento\Framework\Interception\Fixture\Intercepted');
41+
$this->assertEquals('<F:Y>test<F:Y/>', $subject->Y('test'));
42+
}
43+
44+
public function testPluginAfterWins()
45+
{
46+
$subject = $this->_objectManager->create('Magento\Framework\Interception\Fixture\Intercepted');
47+
$this->assertEquals('<P:aZ/>', $subject->Z('test'));
48+
}
49+
50+
public function testPluginBeforeAroundWins()
51+
{
52+
$subject = $this->_objectManager->create('Magento\Framework\Interception\Fixture\Intercepted');
53+
$this->assertEquals('<F:V><F:bV/><F:V/>', $subject->V('test'));
54+
}
55+
56+
public function testPluginBeforeAroundAfterWins()
57+
{
58+
$subject = $this->_objectManager->create('Magento\Framework\Interception\Fixture\Intercepted');
59+
$this->assertEquals('<F:aW/>', $subject->W('test'));
60+
}
61+
}

0 commit comments

Comments
 (0)