Skip to content

Commit a68cc70

Browse files
committed
Merge pull request #61 from magento-extensibility/MAGETWO-32870
[Github] extra tests for current interception behavior #965
2 parents 685df6f + 5ed5b22 commit a68cc70

File tree

6 files changed

+386
-70
lines changed

6 files changed

+386
-70
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\Interception;
7+
8+
/**
9+
* Class GeneralTest
10+
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
11+
*/
12+
abstract class AbstractPlugin extends \PHPUnit_Framework_TestCase
13+
{
14+
15+
/**
16+
* @var \PHPUnit_Framework_MockObject_MockObject
17+
*/
18+
protected $_configReader;
19+
20+
/**
21+
* @var \Magento\Framework\ObjectManagerInterface
22+
*/
23+
protected $_objectManager;
24+
25+
public function setUpInterceptionConfig($pluginConfig)
26+
{
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($pluginConfig)
37+
);
38+
39+
$areaList = $this->getMock('Magento\Framework\App\AreaList', [], [], '', false);
40+
$areaList->expects($this->any())->method('getCodes')->will($this->returnValue([]));
41+
$configScope = new \Magento\Framework\Config\Scope($areaList, 'global');
42+
$cache = $this->getMock('Magento\Framework\Config\CacheInterface');
43+
$cache->expects($this->any())->method('load')->will($this->returnValue(false));
44+
$definitions = new \Magento\Framework\ObjectManager\Definition\Runtime();
45+
$relations = new \Magento\Framework\ObjectManager\Relations\Runtime();
46+
$interceptionConfig = new Config\Config(
47+
$this->_configReader,
48+
$configScope,
49+
$cache,
50+
$relations,
51+
$config,
52+
$definitions
53+
);
54+
$interceptionDefinitions = new Definition\Runtime();
55+
$this->_objectManager = new \Magento\Framework\ObjectManager\ObjectManager(
56+
$factory,
57+
$config,
58+
[
59+
'Magento\Framework\Config\CacheInterface' => $cache,
60+
'Magento\Framework\Config\ScopeInterface' => $configScope,
61+
'Magento\Framework\Config\ReaderInterface' => $this->_configReader,
62+
'Magento\Framework\ObjectManager\RelationsInterface' => $relations,
63+
'Magento\Framework\ObjectManager\ConfigInterface' => $config,
64+
'Magento\Framework\Interception\ObjectManager\ConfigInterface' => $config,
65+
'Magento\Framework\ObjectManager\DefinitionInterface' => $definitions,
66+
'Magento\Framework\Interception\DefinitionInterface' => $interceptionDefinitions
67+
]
68+
);
69+
$factory->setObjectManager($this->_objectManager);
70+
$config->setInterceptionConfig($interceptionConfig);
71+
$config->extend(
72+
[
73+
'preferences' => [
74+
'Magento\Framework\Interception\PluginListInterface' =>
75+
'Magento\Framework\Interception\PluginList\PluginList',
76+
'Magento\Framework\Interception\ChainInterface' =>
77+
'Magento\Framework\Interception\Chain\Chain',
78+
],
79+
]
80+
);
81+
}
82+
}

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

+40
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,44 @@ public function K($param1)
7777
{
7878
return '<K>' . $param1 . '</K>';
7979
}
80+
81+
/**
82+
* @SuppressWarnings(PHPMD.ShortMethodName)
83+
*/
84+
public function V($param1)
85+
{
86+
return '<V>' . $param1 . '</V>';
87+
}
88+
89+
/**
90+
* @SuppressWarnings(PHPMD.ShortMethodName)
91+
*/
92+
public function W($param1)
93+
{
94+
return '<W>' . $param1 . '</W>';
95+
}
96+
97+
/**
98+
* @SuppressWarnings(PHPMD.ShortMethodName)
99+
*/
100+
public function X($param1)
101+
{
102+
return '<X>' . $param1 . '</X>';
103+
}
104+
105+
/**
106+
* @SuppressWarnings(PHPMD.ShortMethodName)
107+
*/
108+
public function Y($param1)
109+
{
110+
return '<Y>' . $param1 . '</Y>';
111+
}
112+
113+
/**
114+
* @SuppressWarnings(PHPMD.ShortMethodName)
115+
*/
116+
public function Z($param1)
117+
{
118+
return '<Z>' . $param1 . '</Z>';
119+
}
80120
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
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+
/**
18+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
19+
*/
20+
public function aroundC(Intercepted $subject, \Closure $next, $param1)
21+
{
22+
return '<F:C>' . $next($param1) . '</F:C>';
23+
}
24+
25+
/**
26+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
27+
*/
28+
public function aroundD(Intercepted $subject, \Closure $next, $param1)
29+
{
30+
$this->_counter++;
31+
return '<F:D>' . $this->_counter . ': ' . $next($param1) . '</F:D>';
32+
}
33+
34+
/**
35+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
36+
*/
37+
public function aroundK(Intercepted $subject, \Closure $next, $param1)
38+
{
39+
$result = $subject->C($param1);
40+
return '<F:K>' . $subject->F($result) . '</F:K>';
41+
}
42+
43+
/**
44+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
45+
*/
46+
public function beforeG(Intercepted $subject, $param1)
47+
{
48+
return ['<F:bG>' . $param1 . '</F:bG>'];
49+
}
50+
51+
/**
52+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
53+
*/
54+
public function aroundG(Intercepted $subject, \Closure $next, $param1)
55+
{
56+
return $next('<F:G>' . $param1 . '</F:G>');
57+
}
58+
59+
/**
60+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
61+
*/
62+
public function afterG(Intercepted $subject, $result)
63+
{
64+
return '<F:aG>' . $result . '</F:aG>';
65+
}
66+
67+
/**
68+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
69+
*/
70+
public function beforeV(Intercepted $subject, $param1)
71+
{
72+
return ['<F:bV/>'];
73+
}
74+
75+
/**
76+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
77+
*/
78+
public function aroundV(Intercepted $subject, \Closure $next, $param1)
79+
{
80+
return '<F:V>' . $param1 . '<F:V/>';
81+
}
82+
83+
/**
84+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
85+
*/
86+
public function beforeW(Intercepted $subject, $param1)
87+
{
88+
return ['<F:bW/>'];
89+
}
90+
91+
/**
92+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
93+
*/
94+
public function aroundW(Intercepted $subject, \Closure $next, $param1)
95+
{
96+
return '<F:W>' . $param1 . '<F:W/>';
97+
}
98+
99+
/**
100+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
101+
*/
102+
public function afterW(Intercepted $subject, $result)
103+
{
104+
return '<F:aW/>';
105+
}
106+
107+
/**
108+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
109+
*/
110+
public function beforeX(Intercepted $subject, $param1)
111+
{
112+
return ['<F:bX/>'];
113+
}
114+
115+
/**
116+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
117+
*/
118+
public function aroundY(Intercepted $subject, \Closure $next, $param1)
119+
{
120+
return '<F:Y>' . $param1 . '<F:Y/>';
121+
}
122+
123+
/**
124+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
125+
*/
126+
public function afterZ(Intercepted $subject, $result)
127+
{
128+
return '<F:aZ/>';
129+
}
130+
}

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

+64
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,68 @@ public function afterG(Intercepted $subject, $result)
6464
{
6565
return '<P:aG>' . $result . '</P:aG>';
6666
}
67+
68+
/**
69+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
70+
*/
71+
public function beforeV(Intercepted $subject, $param1)
72+
{
73+
return ['<P:bV/>'];
74+
}
75+
76+
/**
77+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
78+
*/
79+
public function aroundV(Intercepted $subject, \Closure $next, $param1)
80+
{
81+
return '<P:V>' . $param1 . '<P:V/>';
82+
}
83+
84+
/**
85+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
86+
*/
87+
public function beforeW(Intercepted $subject, $param1)
88+
{
89+
return ['<P:bW/>'];
90+
}
91+
92+
/**
93+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
94+
*/
95+
public function aroundW(Intercepted $subject, \Closure $next, $param1)
96+
{
97+
return '<P:W>' . $param1 . '<P:W/>';
98+
}
99+
100+
/**
101+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
102+
*/
103+
public function afterW(Intercepted $subject, $result)
104+
{
105+
return '<P:aW/>';
106+
}
107+
108+
/**
109+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
110+
*/
111+
public function beforeX(Intercepted $subject, $param1)
112+
{
113+
return ['<P:bX/>'];
114+
}
115+
116+
/**
117+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
118+
*/
119+
public function aroundY(Intercepted $subject, \Closure $next, $param1)
120+
{
121+
return '<P:Y>' . $param1 . '<P:Y/>';
122+
}
123+
124+
/**
125+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
126+
*/
127+
public function afterZ(Intercepted $subject, $result)
128+
{
129+
return '<P:aZ/>';
130+
}
67131
}

0 commit comments

Comments
 (0)