Skip to content

Commit 6320e46

Browse files
committed
Merge branch 'MC-42942' of https://github.com/magento-l3/magento2ce into L3-PR-20210830
2 parents 6460f55 + 1c7d252 commit 6320e46

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

app/code/Magento/ImportExport/Model/Export.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public function export()
194194
if (isset($this->_data[self::FILTER_ELEMENT_GROUP])) {
195195
$this->addLogComment(__('Begin export of %1', $this->getEntity()));
196196
$result = $this->_getEntityAdapter()->setWriter($this->_getWriter())->export();
197-
$countRows = substr_count(trim($result), "\n");
197+
$countRows = substr_count($result, "\n");
198198
if (!$countRows) {
199199
throw new \Magento\Framework\Exception\LocalizedException(__('There is no data for the export.'));
200200
}

app/code/Magento/ImportExport/Test/Unit/Model/ExportTest.php

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ class ExportTest extends TestCase
3434
*/
3535
protected $_exportConfigMock;
3636

37+
/**
38+
* @var AbstractEntity|MockObject
39+
*/
40+
private $abstractMockEntity;
41+
3742
/**
3843
* Return mock for \Magento\ImportExport\Model\Export class
3944
*
@@ -43,8 +48,7 @@ protected function _getMageImportExportModelExportMock()
4348
{
4449
$this->_exportConfigMock = $this->getMockForAbstractClass(ConfigInterface::class);
4550

46-
/** @var $abstractMockEntity \Magento\ImportExport\Model\Export\AbstractEntity */
47-
$abstractMockEntity = $this->getMockForAbstractClass(
51+
$this->abstractMockEntity = $this->getMockForAbstractClass(
4852
AbstractEntity::class,
4953
[],
5054
'',
@@ -75,28 +79,55 @@ protected function _getMageImportExportModelExportMock()
7579
$exportAdapterFac = $this->createMock(\Magento\ImportExport\Model\Export\Adapter\Factory::class);
7680
/** @var \Magento\ImportExport\Model\Export $mockModelExport */
7781
$mockModelExport = $this->getMockBuilder(Export::class)
78-
->setMethods(['getEntityAdapter', '_getEntityAdapter', '_getWriter'])
82+
->setMethods(['getEntityAdapter', '_getEntityAdapter', '_getWriter', 'setWriter'])
7983
->setConstructorArgs([$logger, $filesystem, $this->_exportConfigMock, $entityFactory, $exportAdapterFac])
8084
->getMock();
8185
$mockModelExport->expects(
8286
$this->any()
8387
)->method(
8488
'getEntityAdapter'
8589
)->willReturn(
86-
$abstractMockEntity
90+
$this->abstractMockEntity
8791
);
8892
$mockModelExport->expects(
8993
$this->any()
9094
)->method(
9195
'_getEntityAdapter'
9296
)->willReturn(
93-
$abstractMockEntity
97+
$this->abstractMockEntity
98+
);
99+
$mockModelExport->method(
100+
'setWriter'
101+
)->willReturn(
102+
$this->abstractMockEntity
94103
);
95104
$mockModelExport->expects($this->any())->method('_getWriter')->willReturn($mockAdapterTest);
96105

97106
return $mockModelExport;
98107
}
99108

109+
/**
110+
* Tests that export doesn't use `trim` function while counting the number of exported rows.
111+
*
112+
* Using PHP `trim` function allocates the same amount of memory as export result and leads
113+
* to `out of memory` error.
114+
*/
115+
public function testExportDoesntTrimResult()
116+
{
117+
$model = $this->_getMageImportExportModelExportMock();
118+
$this->abstractMockEntity->method('export')
119+
->willReturn("export data \n\n");
120+
$model->setData([
121+
Export::FILTER_ELEMENT_GROUP => [],
122+
'entity' => 'catalog_product'
123+
]);
124+
$model->export();
125+
$this->assertStringContainsString(
126+
'Exported 2 rows',
127+
var_export($model->getFormatedLogTrace(), true)
128+
);
129+
}
130+
100131
/**
101132
* Test get file name with adapter file name
102133
*/

0 commit comments

Comments
 (0)