Skip to content

Commit ba91818

Browse files
extra tests for current interception behavior
1 parent e4b6347 commit ba91818

File tree

4 files changed

+278
-0
lines changed

4 files changed

+278
-0
lines changed

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

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,29 @@ public function K($param1)
4949
{
5050
return '<K>' . $param1 . '</K>';
5151
}
52+
53+
public function V($param1)
54+
{
55+
return '<V>' . $param1 . '</V>';
56+
}
57+
58+
public function W($param1)
59+
{
60+
return '<W>' . $param1 . '</W>';
61+
}
62+
63+
public function X($param1)
64+
{
65+
return '<X>' . $param1 . '</X>';
66+
}
67+
68+
public function Y($param1)
69+
{
70+
return '<Y>' . $param1 . '</Y>';
71+
}
72+
73+
public function Z($param1)
74+
{
75+
return '<Z>' . $param1 . '</Z>';
76+
}
5277
}
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:bV/>'];
62+
}
63+
64+
public function aroundW(Intercepted $subject, \Closure $next, $param1)
65+
{
66+
return '<F:V>' . $param1 . '<F:V/>';
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
@@ -45,4 +45,44 @@ public function afterG(Intercepted $subject, $result)
4545
{
4646
return '<P:aG>' . $result . '</P:aG>';
4747
}
48+
49+
public function beforeV(Intercepted $subject, $param1)
50+
{
51+
return ['<P:bV/>'];
52+
}
53+
54+
public function aroundV(Intercepted $subject, \Closure $next, $param1)
55+
{
56+
return '<P:V>' . $param1 . '<P:V/>';
57+
}
58+
59+
public function beforeW(Intercepted $subject, $param1)
60+
{
61+
return ['<P:bV/>'];
62+
}
63+
64+
public function aroundW(Intercepted $subject, \Closure $next, $param1)
65+
{
66+
return '<P:V>' . $param1 . '<P:V/>';
67+
}
68+
69+
public function afterW(Intercepted $subject, $result)
70+
{
71+
return '<P:aW/>';
72+
}
73+
74+
public function beforeX(Intercepted $subject, $param1)
75+
{
76+
return ['<P:bX/>'];
77+
}
78+
79+
public function aroundY(Intercepted $subject, \Closure $next, $param1)
80+
{
81+
return '<P:Y>' . $param1 . '<P:Y/>';
82+
}
83+
84+
public function afterZ(Intercepted $subject, $result)
85+
{
86+
return '<P:aZ/>';
87+
}
4888
}
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
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+
class TwoPluginTest extends \PHPUnit_Framework_TestCase
15+
{
16+
/**
17+
* @var \PHPUnit_Framework_MockObject_MockObject
18+
*/
19+
protected $_configReader;
20+
21+
/**
22+
* @var \Magento\Framework\ObjectManagerInterface
23+
*/
24+
protected $_objectManager;
25+
26+
public function setUp()
27+
{
28+
$config = new \Magento\Framework\Interception\ObjectManager\Config\Developer();
29+
$factory = new \Magento\Framework\ObjectManager\Factory\Dynamic\Developer($config, null);
30+
31+
$this->_configReader = $this->getMock('Magento\Framework\Config\ReaderInterface');
32+
$this->_configReader->expects(
33+
$this->any()
34+
)->method(
35+
'read'
36+
)->will(
37+
$this->returnValue(
38+
[
39+
'Magento\Framework\Interception\Fixture\Intercepted' => [
40+
'plugins' => [
41+
'first' => [
42+
'instance' => 'Magento\Framework\Interception\Fixture\Intercepted\FirstPlugin',
43+
'sortOrder' => 10,
44+
], 'second' => [
45+
'instance' => 'Magento\Framework\Interception\Fixture\Intercepted\Plugin',
46+
'sortOrder' => 20,
47+
]
48+
],
49+
]
50+
]
51+
)
52+
);
53+
54+
$areaList = $this->getMock('Magento\Framework\App\AreaList', [], [], '', false);
55+
$areaList->expects($this->any())->method('getCodes')->will($this->returnValue([]));
56+
$configScope = new \Magento\Framework\Config\Scope($areaList, 'global');
57+
$cache = $this->getMock('Magento\Framework\Config\CacheInterface');
58+
$cache->expects($this->any())->method('load')->will($this->returnValue(false));
59+
$definitions = new \Magento\Framework\ObjectManager\Definition\Runtime();
60+
$relations = new \Magento\Framework\ObjectManager\Relations\Runtime();
61+
$interceptionConfig = new Config\Config(
62+
$this->_configReader,
63+
$configScope,
64+
$cache,
65+
$relations,
66+
$config,
67+
$definitions
68+
);
69+
$interceptionDefinitions = new Definition\Runtime();
70+
$this->_objectManager = new \Magento\Framework\ObjectManager\ObjectManager(
71+
$factory,
72+
$config,
73+
[
74+
'Magento\Framework\Config\CacheInterface' => $cache,
75+
'Magento\Framework\Config\ScopeInterface' => $configScope,
76+
'Magento\Framework\Config\ReaderInterface' => $this->_configReader,
77+
'Magento\Framework\ObjectManager\RelationsInterface' => $relations,
78+
'Magento\Framework\ObjectManager\ConfigInterface' => $config,
79+
'Magento\Framework\Interception\ObjectManager\ConfigInterface' => $config,
80+
'Magento\Framework\ObjectManager\DefinitionInterface' => $definitions,
81+
'Magento\Framework\Interception\DefinitionInterface' => $interceptionDefinitions
82+
]
83+
);
84+
$factory->setObjectManager($this->_objectManager);
85+
$config->setInterceptionConfig($interceptionConfig);
86+
$config->extend(
87+
[
88+
'preferences' => [
89+
'Magento\Framework\Interception\PluginListInterface' =>
90+
'Magento\Framework\Interception\PluginList\PluginList',
91+
'Magento\Framework\Interception\ChainInterface' => 'Magento\Framework\Interception\Chain\Chain',
92+
],
93+
]
94+
);
95+
}
96+
97+
public function testPluginBeforeWins()
98+
{
99+
$subject = $this->_objectManager->create('Magento\Framework\Interception\Fixture\Intercepted');
100+
$this->assertEquals('<X><P:bX/></X>', $subject->X('test'));
101+
}
102+
103+
public function testPluginAroundWins()
104+
{
105+
$subject = $this->_objectManager->create('Magento\Framework\Interception\Fixture\Intercepted');
106+
$this->assertEquals('<F:Y>test<F:Y/>', $subject->Y('test'));
107+
}
108+
109+
public function testPluginAfterWins()
110+
{
111+
$subject = $this->_objectManager->create('Magento\Framework\Interception\Fixture\Intercepted');
112+
$this->assertEquals('<P:aZ/>', $subject->Z('test'));
113+
}
114+
115+
public function testPluginBeforeAroundWins()
116+
{
117+
$subject = $this->_objectManager->create('Magento\Framework\Interception\Fixture\Intercepted');
118+
$this->assertEquals('<F:V><F:bV/><F:V/>', $subject->V('test'));
119+
}
120+
public function testPluginBeforeAroundAfterWins()
121+
{
122+
$subject = $this->_objectManager->create('Magento\Framework\Interception\Fixture\Intercepted');
123+
$this->assertEquals('<F:aW/>', $subject->W('test'));
124+
}
125+
}

0 commit comments

Comments
 (0)