Skip to content

Commit bb63f4d

Browse files
author
vpaladiychuk
committed
MAGETWO-2204: "HEADERS ALREADY SENT" When Controller Action Outputs Directly
1 parent fe717c2 commit bb63f4d

File tree

1 file changed

+20
-21
lines changed
  • dev/tests/unit/testsuite/Magento/Customer/Controller/Adminhtml/Index

1 file changed

+20
-21
lines changed

dev/tests/unit/testsuite/Magento/Customer/Controller/Adminhtml/Index/ViewfileTest.php

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,11 @@ public function testExecuteParamFile()
120120
$this->storage->expects($this->once())->method('processStorageFile')->with($path)->willReturn(true);
121121

122122
$this->objectManager->expects($this->any())->method('get')
123-
->will($this->returnValueMap(
123+
->willReturnMap(
124124
[
125125
['Magento\Framework\Filesystem', $this->fileSystemMock],
126126
['Magento\Core\Helper\File\Storage', $this->storage]
127127
]
128-
)
129128
);
130129

131130
$this->urlDecoderMock->expects($this->once())->method('decode')->with($decodedFile)->willReturn($file);
@@ -158,9 +157,8 @@ public function testExecuteGetParamImage()
158157
$path = 'path';
159158
$stat = ['size' => 10, 'mtime' => 10];
160159

161-
$this->requestMock->expects($this->at(0))->method('getParam')->with('file')->willReturn(null);
162-
$this->requestMock->expects($this->at(1))->method('getParam')->with('image')->willReturn($decodedFile);
163-
$this->requestMock->expects($this->at(2))->method('getParam')->with('image')->willReturn($decodedFile);
160+
$this->requestMock->expects($this->any())->method('getParam')
161+
->willReturnMap([['file', null, null], ['image', null, $decodedFile]]);
164162

165163
$this->directoryMock->expects($this->once())->method('getAbsolutePath')->with($fileName)->willReturn($path);
166164
$this->directoryMock->expects($this->once())->method('stat')->with($path)->willReturn($stat);
@@ -171,26 +169,27 @@ public function testExecuteGetParamImage()
171169

172170
$this->storage->expects($this->once())->method('processStorageFile')->with($path)->willReturn(true);
173171

174-
$this->objectManager->expects($this->at(0))->method('get')->with('Magento\Framework\Filesystem')
175-
->willReturn($this->fileSystemMock);
176-
$this->objectManager->expects($this->at(1))->method('get')->with('Magento\Core\Helper\File\Storage')
177-
->willReturn($this->storage);
172+
$this->objectManager->expects($this->any())->method('get')
173+
->willReturnMap(
174+
[
175+
['Magento\Framework\Filesystem', $this->fileSystemMock],
176+
['Magento\Core\Helper\File\Storage', $this->storage]
177+
]
178+
);
179+
178180

179181
$this->urlDecoderMock->expects($this->once())->method('decode')->with($decodedFile)->willReturn($file);
180182

181183
$this->resultRawMock->expects($this->once())->method('setHttpResponseCode')->with(200)->willReturnSelf();
182-
$this->resultRawMock->expects($this->at(1))->method('setHeader')
183-
->with('Pragma', 'public', true)
184-
->willReturnSelf();
185-
$this->resultRawMock->expects($this->at(2))->method('setHeader')
186-
->with('Content-type', 'application/octet-stream', true)
187-
->willReturnSelf();
188-
$this->resultRawMock->expects($this->at(3))->method('setHeader')
189-
->with('Content-Length', $stat['size'])
190-
->willReturnSelf();
191-
$this->resultRawMock->expects($this->at(4))->method('setHeader')
192-
->with('Last-Modified', date('r', $stat['mtime']))
193-
->willReturnSelf();
184+
$this->resultRawMock->expects($this->any())->method('setHeader')
185+
->willReturnMap(
186+
[
187+
['Pragma', 'public', true, $this->resultRawMock],
188+
['Content-type', 'application/octet-stream', true, $this->resultRawMock],
189+
['Content-Length', $stat['size'], false, $this->resultRawMock],
190+
['Pragma', 'public', true, $this->resultRawMock],
191+
]
192+
);
194193

195194
$this->resultRawFactoryMock = $this->getMock(
196195
'Magento\Framework\Controller\Result\RawFactory',

0 commit comments

Comments
 (0)