Skip to content

Commit 77e4220

Browse files
committed
MAGETWO-32340: [GITHUB] Add getParams and setParams to App\RequestInterface #865 #1053
- Remove RequestInterface::getParam from obsolete_methods since it still exists - Move getCookie to PhpEnvironment\Request
1 parent 969d2ff commit 77e4220

File tree

12 files changed

+134
-200
lines changed

12 files changed

+134
-200
lines changed

app/code/Magento/Webapi/Controller/Request.php

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ class Request extends HttpRequest implements RequestInterface
1818
/** @var int */
1919
protected $_consumerId = 0;
2020

21-
/**
22-
* @var CookieReaderInterface
23-
*/
24-
protected $_cookieReader;
25-
2621
/**
2722
* Modify pathInfo: strip down the front name and query parameters.
2823
*
@@ -32,13 +27,12 @@ class Request extends HttpRequest implements RequestInterface
3227
* @param null|string|\Zend_Uri $uri
3328
*/
3429
public function __construct(
30+
CookieReaderInterface $cookieReader,
3531
AreaList $areaList,
3632
ScopeInterface $configScope,
37-
CookieReaderInterface $cookieReader,
3833
$uri = null
3934
) {
40-
parent::__construct($uri);
41-
$this->_cookieReader = $cookieReader;
35+
parent::__construct($cookieReader, $uri);
4236

4337
$pathInfo = $this->getRequestUri();
4438
/** Remove base url and area from path */
@@ -48,16 +42,4 @@ public function __construct(
4842
$pathInfo = preg_replace('#\?.*#', '', $pathInfo);
4943
$this->setPathInfo($pathInfo);
5044
}
51-
52-
/**
53-
* Retrieve a value from a cookie.
54-
*
55-
* @param string|null $name
56-
* @param string|null $default The default value to return if no value could be found for the given $name.
57-
* @return string|null
58-
*/
59-
public function getCookie($name = null, $default = null)
60-
{
61-
return $this->_cookieReader->getCookie($name, $default);
62-
}
6345
}

app/code/Magento/Webapi/Controller/Rest/Request.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,20 @@ class Request extends \Magento\Webapi\Controller\Request
3838
/**
3939
* Initialize dependencies
4040
*
41+
* @param \Magento\Framework\Stdlib\Cookie\CookieReaderInterface $cookieReader
4142
* @param \Magento\Framework\App\AreaList $areaList
4243
* @param \Magento\Framework\Config\ScopeInterface $configScope
43-
* @param \Magento\Framework\Stdlib\Cookie\CookieReaderInterface $cookieReader
4444
* @param \Magento\Webapi\Controller\Rest\Request\Deserializer\Factory $deserializerFactory
4545
* @param null|string $uri
4646
*/
4747
public function __construct(
48+
\Magento\Framework\Stdlib\Cookie\CookieReaderInterface $cookieReader,
4849
\Magento\Framework\App\AreaList $areaList,
4950
\Magento\Framework\Config\ScopeInterface $configScope,
50-
\Magento\Framework\Stdlib\Cookie\CookieReaderInterface $cookieReader,
5151
\Magento\Webapi\Controller\Rest\Request\Deserializer\Factory $deserializerFactory,
5252
$uri = null
5353
) {
54-
parent::__construct($areaList, $configScope, $cookieReader, $uri);
54+
parent::__construct($cookieReader, $areaList, $configScope, $uri);
5555
$this->_deserializerFactory = $deserializerFactory;
5656
}
5757

dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/RequestTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ class RequestTest extends \PHPUnit_Framework_TestCase
1717
protected function setUp()
1818
{
1919
$this->_model = new \Magento\TestFramework\Request(
20-
$this->getMock('Magento\Framework\App\Route\ConfigInterface\Proxy', [], [], '', false),
21-
$this->getMock('Magento\Framework\App\Request\PathInfoProcessorInterface', [], [], '', false),
2220
$this->getMock('Magento\Framework\Stdlib\Cookie\CookieReaderInterface'),
21+
$this->getMock('Magento\Framework\App\Route\ConfigInterface\Proxy', [], [], '', false),
22+
$this->getMock('Magento\Framework\App\Request\PathInfoProcessorInterface'),
2323
$this->getMock('Magento\Framework\ObjectManagerInterface')
2424
);
2525
}

dev/tests/integration/framework/tests/unit/testsuite/Magento/Test/TestCase/ControllerAbstractTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ protected function setUp()
1919
{
2020
$this->messageManager = $this->getMock('\Magento\Framework\Message\Manager', [], [], '', false);
2121
$request = new \Magento\TestFramework\Request(
22-
$this->getMock('Magento\Framework\App\Route\ConfigInterface\Proxy', [], [], '', false),
23-
$this->getMock('Magento\Framework\App\Request\PathInfoProcessorInterface', [], [], '', false),
2422
$this->getMock('Magento\Framework\Stdlib\Cookie\CookieReaderInterface'),
23+
$this->getMock('Magento\Framework\App\Route\ConfigInterface\Proxy', [], [], '', false),
24+
$this->getMock('Magento\Framework\App\Request\PathInfoProcessorInterface'),
2525
$this->getMock('Magento\Framework\ObjectManagerInterface')
2626
);
2727
$response = new \Magento\TestFramework\Response(

dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2084,5 +2084,4 @@
20842084
['getFiles', 'Magento\Framework\App\Request\Http'],
20852085
['getAlias', 'Magento\Framework\App\Request\Http', 'Magento\Framework\HTTP\PhpEnvironment\Request'],
20862086
['setAlias', 'Magento\Framework\App\Request\Http', 'Magento\Framework\HTTP\PhpEnvironment\Request'],
2087-
['getParam', 'Magento\Framework\App\RequestInterface'],
20882087
];

dev/tests/unit/testsuite/Magento/DesignEditor/Controller/Varien/Router/StandardTest.php

Lines changed: 18 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,6 @@ public function testMatch(
6666
) {
6767
$this->_model = $this->_prepareMocksForTestMatch($request, $isVde, $isLoggedIn, $routers);
6868
$this->assertEquals($matchedValue, $this->_model->match($request));
69-
if ($isVde && $isLoggedIn) {
70-
$this->assertEquals(self::TEST_PATH, $request->getPathInfo());
71-
}
7269
}
7370

7471
/**
@@ -79,30 +76,26 @@ public function testMatch(
7976
*/
8077
public function matchDataProvider()
8178
{
82-
$objectManagerMock = $this->getMock('Magento\Framework\ObjectManagerInterface');
8379
$this->_cookieReaderMock = $this->getMock('Magento\Framework\Stdlib\Cookie\CookieReaderInterface');
84-
$uri = self::TEST_HOST . '/' . self::VDE_FRONT_NAME . self::TEST_PATH;
85-
$notVdeUrl = self::TEST_HOST . self::TEST_PATH;
80+
$vdePath = '/' . self::VDE_FRONT_NAME . self::TEST_PATH;
81+
$notVdePath = self::TEST_PATH;
8682

8783
$excludedRouters = ['admin' => 'admin router', 'vde' => 'vde router'];
8884

89-
$routerListMock = $this->getMock(
90-
'\Magento\Framework\App\Route\ConfigInterface\Proxy',
91-
[],
92-
[],
93-
'',
94-
false
95-
);
96-
9785
$infoProcessorMock = $this->getMock('Magento\Framework\App\Request\PathInfoProcessorInterface');
9886
$infoProcessorMock->expects($this->any())->method('process')->will($this->returnArgument(1));
9987

10088
// test data to verify routers match logic
101-
$matchedRequest = $this->getMock(
102-
'Magento\Framework\App\Request\Http',
103-
['_isFrontArea'],
104-
[$routerListMock, $infoProcessorMock, $this->_cookieReaderMock, $objectManagerMock, $uri]
105-
);
89+
$notVdeRequest = $this->getMockBuilder('Magento\Framework\App\Request\Http')
90+
->disableOriginalConstructor()->getMock();
91+
$notVdeRequest->expects($this->any())
92+
->method('getPathInfo')
93+
->willReturn($vdePath);
94+
$vdeRequest = $this->getMockBuilder('Magento\Framework\App\Request\Http')
95+
->disableOriginalConstructor()->getMock();
96+
$vdeRequest->expects($this->any())
97+
->method('getPathInfo')
98+
->willReturn($notVdePath);
10699

107100
$matchedController = $this->getMockForAbstractClass(
108101
'Magento\Framework\App\Action\AbstractAction',
@@ -118,13 +111,13 @@ public function matchDataProvider()
118111
)->method(
119112
'match'
120113
)->with(
121-
$matchedRequest
114+
$notVdeRequest
122115
)->will(
123116
$this->returnValue($matchedController)
124117
);
125118
$matchedRouter->expects($this->once())
126119
->method('match')
127-
->with($matchedRequest)
120+
->with($notVdeRequest)
128121
->will($this->returnValue($matchedController));
129122

130123
// method "match" will not be invoked for this router because controller will be found by first router
@@ -138,39 +131,23 @@ public function matchDataProvider()
138131

139132
$routers = [
140133
'not vde request' => [
141-
'$request' => $this->getMock(
142-
'Magento\Framework\App\Request\Http', ['_isFrontArea'], [
143-
$routerListMock,
144-
$infoProcessorMock,
145-
$this->_cookieReaderMock,
146-
$objectManagerMock,
147-
$notVdeUrl
148-
]
149-
),
134+
'$request' => $vdeRequest,
150135
'$isVde' => false,
151136
'$isLoggedIn' => true,
152137
],
153138
'not logged as admin' => [
154-
'$request' => $this->getMock(
155-
'Magento\Framework\App\Request\Http',
156-
['_isFrontArea'],
157-
[$routerListMock, $infoProcessorMock, $this->_cookieReaderMock, $objectManagerMock, $uri]
158-
),
139+
'$request' => $notVdeRequest,
159140
'$isVde' => true,
160141
'$isLoggedIn' => false,
161142
],
162143
'no matched routers' => [
163-
'$request' => $this->getMock(
164-
'Magento\Framework\App\Request\Http',
165-
['_isFrontArea'],
166-
[$routerListMock, $infoProcessorMock, $this->_cookieReaderMock, $objectManagerMock, $uri]
167-
),
144+
'$request' => $notVdeRequest,
168145
'$isVde' => true,
169146
'$isLoggedIn' => true,
170147
'$routers' => $excludedRouters
171148
],
172149
'matched routers' => [
173-
'$request' => $matchedRequest,
150+
'$request' => $notVdeRequest,
174151
'$isVde' => true,
175152
'$isLoggedIn' => true,
176153
'$routers' => $matchedRouters,

dev/tests/unit/testsuite/Magento/Framework/App/Request/HttpTest.php

Lines changed: 12 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,6 @@ class HttpTest extends \PHPUnit_Framework_TestCase
2828
*/
2929
protected $_infoProcessorMock;
3030

31-
/**
32-
* @var \Magento\Framework\Stdlib\Cookie\CookieReaderInterface | \PHPUnit_Framework_MockObject_MockObject
33-
*/
34-
protected $cookieReaderMock;
35-
3631
/**
3732
* @var \Magento\TestFramework\Helper\ObjectManager | \PHPUnit_Framework_MockObject_MockObject
3833
*/
@@ -55,7 +50,6 @@ protected function setUp()
5550
);
5651
$this->_infoProcessorMock = $this->getMock('Magento\Framework\App\Request\PathInfoProcessorInterface');
5752
$this->_infoProcessorMock->expects($this->any())->method('process')->will($this->returnArgument(1));
58-
$this->cookieReaderMock = $this->getMock('Magento\Framework\Stdlib\Cookie\CookieReaderInterface');
5953
$this->objectManager = $this->getMock('Magento\Framework\ObjectManagerInterface');
6054

6155
// Stash the $_SERVER array to protect it from modification in test
@@ -67,14 +61,20 @@ public function tearDown()
6761
$_SERVER = $this->serverArray;
6862
}
6963

64+
/**
65+
* @return \Magento\Framework\App\Request\Http
66+
*/
7067
private function getModel($uri = null)
7168
{
72-
return new \Magento\Framework\App\Request\Http(
73-
$this->_routerListMock,
74-
$this->_infoProcessorMock,
75-
$this->cookieReaderMock,
76-
$this->objectManager,
77-
$uri
69+
$testFrameworkObjectManager = new \Magento\TestFramework\Helper\ObjectManager($this);
70+
return $testFrameworkObjectManager->getObject(
71+
'Magento\Framework\App\Request\Http',
72+
[
73+
'routeConfig' => $this->_routerListMock,
74+
'pathInfoProcessor' => $this->_infoProcessorMock,
75+
'objectManager' => $this->objectManager,
76+
'uri' => $uri,
77+
]
7878
);
7979
}
8080

@@ -255,48 +255,6 @@ public function getDistroBaseUrlPathDataProvider()
255255
];
256256
}
257257

258-
public function testGetCookieDefault()
259-
{
260-
$key = "cookieName";
261-
$default = "defaultValue";
262-
263-
$this->cookieReaderMock
264-
->expects($this->once())
265-
->method('getCookie')
266-
->with($key, $default)
267-
->will($this->returnValue($default));
268-
269-
$this->assertEquals($default, $this->getModel()->getCookie($key, $default));
270-
}
271-
272-
public function testGetCookieNameExists()
273-
{
274-
$key = "cookieName";
275-
$default = "defaultValue";
276-
$value = "cookieValue";
277-
278-
$this->cookieReaderMock
279-
->expects($this->once())
280-
->method('getCookie')
281-
->with($key, $default)
282-
->will($this->returnValue($value));
283-
284-
$this->assertEquals($value, $this->getModel()->getCookie($key, $default));
285-
}
286-
287-
public function testGetCookieNullName()
288-
{
289-
$nullKey = null;
290-
$default = "defaultValue";
291-
292-
$this->cookieReaderMock
293-
->expects($this->once())
294-
->method('getCookie')
295-
->with($nullKey, $default)
296-
->will($this->returnValue($default));
297-
298-
$this->assertEquals($default, $this->getModel()->getCookie($nullKey, $default));
299-
}
300258

301259
public function serverVariablesProvider()
302260
{

0 commit comments

Comments
 (0)