Skip to content

Commit 1188784

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

File tree

2 files changed

+32
-29
lines changed

2 files changed

+32
-29
lines changed

dev/tests/unit/testsuite/Magento/Backup/Controller/Adminhtml/Index/DownloadTest.php

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,24 @@ public function testExecuteBackupFound()
4949
$size = 10;
5050
$output = 'test';
5151

52-
$this->backup->expects($this->once())->method('getTime')->will($this->returnValue($time));
53-
$this->backup->expects($this->once())->method('exists')->will($this->returnValue(true));
54-
$this->backup->expects($this->once())->method('getSize')->will($this->returnValue($size));
55-
$this->backup->expects($this->once())->method('output')->will($this->returnValue($output));
52+
$this->backup->expects($this->once())->method('getTime')->willReturn($time);
53+
$this->backup->expects($this->once())->method('exists')->willReturn(true);
54+
$this->backup->expects($this->once())->method('getSize')->willReturn($size);
55+
$this->backup->expects($this->once())->method('output')->willReturn($output);
5656

57-
$this->request->expects($this->at(0))->method('getParam')->with('time')->will($this->returnValue($time));
58-
$this->request->expects($this->at(1))->method('getParam')->with('type')->will($this->returnValue($type));
57+
$this->request->expects($this->at(0))->method('getParam')->with('time')->willReturn($time);
58+
$this->request->expects($this->at(1))->method('getParam')->with('type')->willReturn($type);
5959

6060
$this->backupModelFactory->expects($this->once())->method('create')->with($time, $type)
61-
->will($this->returnValue($this->backup));
61+
->willReturn($this->backup);
6262

6363
$helper = $this->getMock('Magento\Backup\Helper\Data', [], [], '', false);
6464
$helper->expects($this->once())->method('generateBackupDownloadName')->with($this->backup)
65-
->will($this->returnValue($filename));
65+
->willReturn($filename);
6666

6767
$objectManager = $this->getMock('\Magento\Framework\ObjectManagerInterface', [], [], '', false);
6868
$objectManager->expects($this->once())->method('get')->with('Magento\Backup\Helper\Data')
69-
->will($this->returnValue($helper));
69+
->willReturn($helper);
7070

7171
$fileFactory = $this->getMock('\Magento\Framework\App\Response\Http\FileFactory', [], [], '', false);
7272
$fileFactory->expects($this->once())->method('create')->with(
@@ -75,7 +75,7 @@ public function testExecuteBackupFound()
7575
\Magento\Framework\App\Filesystem\DirectoryList::VAR_DIR,
7676
'application/octet-stream',
7777
$size
78-
)->will($this->returnValue($this->response));
78+
)->willReturn($this->response);
7979

8080
$resultRaw = $this->getMock('\Magento\Framework\Controller\Result\Raw', [], [], '', false);
8181
$resultRaw->expects($this->once())->method('setContents')->with($output);
@@ -87,12 +87,12 @@ public function testExecuteBackupFound()
8787
'',
8888
false
8989
);
90-
$resultRawFactory->expects($this->once())->method('create')->will($this->returnValue($resultRaw));
90+
$resultRawFactory->expects($this->once())->method('create')->willReturn($resultRaw);
9191

9292
$context = $this->getMock('\Magento\Backend\App\Action\Context', [], [], '', false);
93-
$context->expects($this->once())->method('getRequest')->will($this->returnValue($this->request));
94-
$context->expects($this->once())->method('getObjectManager')->will($this->returnValue($objectManager));
95-
$context->expects($this->once())->method('getResponse')->will($this->returnValue($this->response));
93+
$context->expects($this->once())->method('getRequest')->willReturn($this->request);
94+
$context->expects($this->once())->method('getObjectManager')->willReturn($objectManager);
95+
$context->expects($this->once())->method('getResponse')->willReturn($this->response);
9696

9797
/** @var Download|\PHPUnit_Framework_MockObject_MockObject $controller */
9898
$controller = (new \Magento\TestFramework\Helper\ObjectManager($this))->getObject(
@@ -111,25 +111,24 @@ public function testExecuteBackupFound()
111111
* @dataProvider executeBackupNotFoundDataProvider
112112
* @param string $time
113113
* @param bool $exists
114-
* @param \PHPUnit_Framework_MockObject_Matcher_InvokedCount $existsCount
114+
* @param int $existsCount
115115
*/
116116
public function testExecuteBackupNotFound($time, $exists, $existsCount)
117117
{
118118
$type = 'db';
119119

120-
$this->backup->expects($this->once())->method('getTime')->will($this->returnValue($time));
121-
$this->backup->expects($existsCount)->method('exists')->will($this->returnValue($exists));
120+
$this->backup->expects($this->once())->method('getTime')->willReturn($time);
121+
$this->backup->expects($this->exactly($existsCount))->method('exists')->willReturn($exists);
122122

123-
$this->request = $this->getMock('\Magento\Framework\App\RequestInterface', [], [], '', false);
124123
$this->request->expects($this->at(0))->method('getParam')->with('time')->will($this->returnValue($time));
125124
$this->request->expects($this->at(1))->method('getParam')->with('type')->will($this->returnValue($type));
126125

127126
$context = $this->getMock('\Magento\Backend\App\Action\Context', [], [], '', false);
128-
$context->expects($this->once())->method('getRequest')->will($this->returnValue($this->request));
129-
$context->expects($this->once())->method('getResponse')->will($this->returnValue($this->response));
127+
$context->expects($this->once())->method('getRequest')->willReturn($this->request);
128+
$context->expects($this->once())->method('getResponse')->willReturn($this->response);
130129

131130
$this->backupModelFactory->expects($this->once())->method('create')->with($time, $type)
132-
->will($this->returnValue($this->backup));
131+
->willReturn($this->backup);
133132

134133
$resultRedirect = $this->getMock('Magento\Backend\Model\View\Result\Redirect', [], [], '', false);
135134
$resultRedirect->expects($this->once())->method('setPath')->with('backup/*');
@@ -141,7 +140,7 @@ public function testExecuteBackupNotFound($time, $exists, $existsCount)
141140
'',
142141
false
143142
);
144-
$resultRedirectFactory->expects($this->once())->method('create')->will($this->returnValue($resultRedirect));
143+
$resultRedirectFactory->expects($this->once())->method('create')->willReturn($resultRedirect);
145144

146145
/** @var Download|\PHPUnit_Framework_MockObject_MockObject $controller */
147146
$controller = (new \Magento\TestFramework\Helper\ObjectManager($this))->getObject(
@@ -161,9 +160,9 @@ public function testExecuteBackupNotFound($time, $exists, $existsCount)
161160
public function executeBackupNotFoundDataProvider()
162161
{
163162
return [
164-
[1, false, $this->once()],
165-
[0, true, $this->never()],
166-
[0, false, $this->never()]
163+
[1, false, 1],
164+
[0, true, 0],
165+
[0, false, 0]
167166
];
168167
}
169168
}

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,14 @@ public function testExecuteParamFile()
119119

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

122-
$this->objectManager->expects($this->at(0))->method('get')->with('Magento\Framework\Filesystem')
123-
->willReturn($this->fileSystemMock);
124-
$this->objectManager->expects($this->at(1))->method('get')->with('Magento\Core\Helper\File\Storage')
125-
->willReturn($this->storage);
122+
$this->objectManager->expects($this->any())->method('get')
123+
->will($this->returnValueMap(
124+
[
125+
['Magento\Framework\Filesystem', $this->fileSystemMock],
126+
['Magento\Core\Helper\File\Storage', $this->storage]
127+
]
128+
)
129+
);
126130

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

0 commit comments

Comments
 (0)