Skip to content

Commit 5ae9776

Browse files
author
Sergey Semenov
committed
MAGETWO-33074: Upgrade response class.
1 parent c0530db commit 5ae9776

File tree

4 files changed

+52
-16
lines changed

4 files changed

+52
-16
lines changed

dev/tests/unit/testsuite/Magento/Checkout/Controller/Onepage/SaveBillingTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,14 @@ public function testExecute()
168168
$this->request->expects($this->once())
169169
->method('isPost')
170170
->willReturn(false);
171-
$this->resultRaw->expects($this->exactly(2))
171+
$this->resultRaw->expects($this->once())
172+
->method('setStatusHeader')
173+
->with(403, '1.1', 'Session Expired')
174+
->willReturn($this->resultRaw);
175+
$this->resultRaw->expects($this->once())
172176
->method('setHeader')
173-
->willReturnMap([
174-
['HTTP/1.1', '403 Session Expired', false, $this->resultRaw],
175-
['Login-Required', 'true', false, $this->resultRaw]
176-
]);
177+
->with('Login-Required', 'true', false)
178+
->willReturn($this->resultRaw);
177179
$this->assertSame($this->resultRaw, $this->controller->execute());
178180
}
179181

dev/tests/unit/testsuite/Magento/Checkout/Controller/Onepage/SaveShippingTest.php

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,12 +169,14 @@ public function testExecute()
169169
$this->request->expects($this->once())
170170
->method('isPost')
171171
->willReturn(false);
172-
$this->resultRaw->expects($this->exactly(2))
172+
$this->resultRaw->expects($this->once())
173+
->method('setStatusHeader')
174+
->with(403, '1.1', 'Session Expired')
175+
->willReturn($this->resultRaw);
176+
$this->resultRaw->expects($this->once())
173177
->method('setHeader')
174-
->willReturnMap([
175-
['HTTP/1.1', '403 Session Expired', false, $this->resultRaw],
176-
['Login-Required', 'true', false, $this->resultRaw]
177-
]);
178+
->with('Login-Required', 'true', false)
179+
->willReturn($this->resultRaw);
178180
$this->assertSame($this->resultRaw, $this->controller->execute());
179181
}
180182

dev/tests/unit/testsuite/Magento/Cms/Controller/Noroute/IndexTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,8 @@ public function testExecuteResultPage()
9090
$this->resultPageMock->expects(
9191
$this->at(0)
9292
)->method(
93-
'setHeader'
94-
)->with(
95-
'HTTP/1.1',
96-
'404 Not Found'
97-
)->will(
93+
'setStatusHeader'
94+
)->with(404, '1.1', 'Not Found')->will(
9895
$this->returnSelf()
9996
);
10097
$this->resultPageMock->expects(

lib/internal/Magento/Framework/Controller/AbstractResult.php

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ abstract class AbstractResult implements ResultInterface
2020
*/
2121
protected $headers = [];
2222

23+
/**
24+
* @var string
25+
*/
26+
protected $statusHeaderCode;
27+
28+
/**
29+
* @var string
30+
*/
31+
protected $statusHeaderVersion;
32+
33+
/**
34+
* @var string
35+
*/
36+
protected $statusHeaderPhrase;
37+
2338
/**
2439
* Set response code to result
2540
*
@@ -53,6 +68,20 @@ public function setHeader($name, $value, $replace = false)
5368
return $this;
5469
}
5570

71+
/**
72+
* @param int|string $httpCode
73+
* @param null|int|string $version
74+
* @param null|string $phrase
75+
* @return $this
76+
*/
77+
public function setStatusHeader($httpCode, $version = null, $phrase = null)
78+
{
79+
$this->statusHeaderCode = $httpCode;
80+
$this->statusHeaderVersion = $version;
81+
$this->statusHeaderPhrase = $phrase;
82+
return $this;
83+
}
84+
5685
/**
5786
* @param ResponseInterface $response
5887
* @return $this
@@ -62,7 +91,13 @@ protected function applyHttpHeaders(ResponseInterface $response)
6291
if (!empty($this->httpResponseCode)) {
6392
$response->setHttpResponseCode($this->httpResponseCode);
6493
}
65-
94+
if ($this->statusHeaderCode) {
95+
$response->setStatusHeader(
96+
$this->statusHeaderCode,
97+
$this->statusHeaderVersion,
98+
$this->statusHeaderPhrase
99+
);
100+
}
66101
if (!empty($this->headers)) {
67102
foreach ($this->headers as $headerData) {
68103
$response->setHeader($headerData['name'], $headerData['value'], $headerData['replace']);

0 commit comments

Comments
 (0)