Skip to content

Commit ef6b018

Browse files
author
Bohdan Korablov
committed
MAGETWO-58658: [PR] Delivery of bug fixes for Setup, Sample Data and Import/Export
1 parent 81d29d0 commit ef6b018

File tree

4 files changed

+82
-42
lines changed

4 files changed

+82
-42
lines changed

dev/tests/integration/testsuite/Magento/CatalogImportExport/Model/Import/ProductTest.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,8 +1242,7 @@ public function testImportWithoutUrlKeys()
12421242
'simple2' => 'simple-2',
12431243
'simple3' => 'simple-3'
12441244
];
1245-
$filesystem = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()
1246-
->create(\Magento\Framework\Filesystem::class);
1245+
$filesystem = $this->objectManager->create(\Magento\Framework\Filesystem::class);
12471246
$directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
12481247
$source = $this->objectManager->create(
12491248
\Magento\ImportExport\Model\Import\Source\Csv::class,
@@ -1262,9 +1261,7 @@ public function testImportWithoutUrlKeys()
12621261
$this->assertTrue($errors->getErrorsCount() == 0);
12631262
$this->_model->importData();
12641263

1265-
$productRepository = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
1266-
\Magento\Catalog\Api\ProductRepositoryInterface::class
1267-
);
1264+
$productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
12681265
foreach ($products as $productSku => $productUrlKey) {
12691266
$this->assertEquals($productUrlKey, $productRepository->get($productSku)->getUrlKey());
12701267
}
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
sku,product_type,store_view_code,name,price,attribute_set_code,url_key
22
simple1,simple,,"simple 1",25,Default,""
33
simple2,simple,,"simple 2",34,Default,""
4-
simple3,simple,,"simple 3",58,Default,""
4+
simple3,simple,,"simple 3",58,Default,""

setup/src/Magento/Setup/Test/Unit/Module/I18n/Pack/Writer/File/AbstractFileTest.php renamed to setup/src/Magento/Setup/Test/Unit/Module/I18n/Pack/Writer/File/CsvTest.php

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,15 @@
88
use Magento\Setup\Module\I18n\Context;
99
use Magento\Setup\Module\I18n\Locale;
1010
use Magento\Setup\Module\I18n\Dictionary;
11+
use Magento\Setup\Module\I18n\Factory;
1112
use Magento\Setup\Module\I18n\Dictionary\Phrase;
12-
use Magento\Setup\Module\I18n\Pack\Writer\File\AbstractFile;
13+
use Magento\Setup\Module\I18n\Pack\Writer\File\Csv;
14+
use Magento\Setup\Module\I18n\Dictionary\WriterInterface;
1315
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1416

15-
class AbstractFileTest extends \PHPUnit_Framework_TestCase
17+
require_once __DIR__ . '/_files/ioMock.php';
18+
19+
class CsvTest extends \PHPUnit_Framework_TestCase
1620
{
1721
/**
1822
* @var Context|\PHPUnit_Framework_MockObject_MockObject
@@ -35,7 +39,12 @@ class AbstractFileTest extends \PHPUnit_Framework_TestCase
3539
protected $phraseMock;
3640

3741
/**
38-
* @var AbstractFile|\PHPUnit_Framework_MockObject_MockObject
42+
* @var Factory|\PHPUnit_Framework_MockObject_MockObject
43+
*/
44+
protected $factoryMock;
45+
46+
/**
47+
* @var Csv|\PHPUnit_Framework_MockObject_MockObject
3948
*/
4049
protected $object;
4150

@@ -51,15 +60,16 @@ protected function setUp()
5160
$this->localeMock = $this->getMock(Locale::class, [], [], '', false, false);
5261
$this->dictionaryMock = $this->getMock(Dictionary::class, [], [], '', false, false);
5362
$this->phraseMock = $this->getMock(Phrase::class, [], [], '', false, false);
63+
$this->factoryMock = $this->getMock(Factory::class, [], [], '', false, false);
5464

5565
$constructorArguments = $objectManagerHelper->getConstructArguments(
56-
AbstractFile::class,
57-
['context' => $this->contextMock]
66+
Csv::class,
67+
[
68+
'context' => $this->contextMock,
69+
'factory' => $this->factoryMock
70+
]
5871
);
59-
$this->object = $this->getMockBuilder(AbstractFile::class)
60-
->setMethods(['_createDirectoryIfNotExist', '_writeFile'])
61-
->setConstructorArgs($constructorArguments)
62-
->getMockForAbstractClass();
72+
$this->object = $objectManagerHelper->getObject(Csv::class, $constructorArguments);
6373
}
6474

6575
/**
@@ -73,11 +83,6 @@ public function testWriteDictionaryWithRuntimeException($contextType, $contextVa
7383
{
7484
$this->configureGeneralPhrasesMock($contextType, $contextValue);
7585

76-
$this->object->expects($this->never())
77-
->method('_createDirectoryIfNotExist');
78-
$this->object->expects($this->never())
79-
->method('_writeFile');
80-
8186
$this->object->writeDictionary($this->dictionaryMock, $this->localeMock);
8287
}
8388

@@ -105,11 +110,6 @@ public function testWriteDictionaryWithInvalidArgumentException()
105110

106111
$this->configureGeneralPhrasesMock($contextType, [$contextValue]);
107112

108-
$this->object->expects($this->never())
109-
->method('_createDirectoryIfNotExist');
110-
$this->object->expects($this->never())
111-
->method('_writeFile');
112-
113113
$this->contextMock->expects($this->once())
114114
->method('buildPathToLocaleDirectoryByContext')
115115
->with($contextType, $contextValue)
@@ -128,16 +128,16 @@ public function testWriteDictionaryWherePathIsNull()
128128

129129
$this->configureGeneralPhrasesMock($contextType, [$contextValue]);
130130

131-
$this->object->expects($this->never())
132-
->method('_createDirectoryIfNotExist');
133-
$this->object->expects($this->never())
134-
->method('_writeFile');
135-
136131
$this->contextMock->expects($this->once())
137132
->method('buildPathToLocaleDirectoryByContext')
138133
->with($contextType, $contextValue)
139134
->willReturn(null);
140135

136+
$this->phraseMock->expects($this->never())
137+
->method('setContextType');
138+
$this->phraseMock->expects($this->never())
139+
->method('setContextValue');
140+
141141
$this->object->writeDictionary($this->dictionaryMock, $this->localeMock);
142142
}
143143

@@ -151,33 +151,37 @@ public function testWriteDictionary()
151151
$path = '/some/path/';
152152
$phrase = 'Phrase';
153153
$locale = 'en_EN';
154-
$fileExtension = 'csv';
155-
$file = $path . $locale . '.' . $fileExtension;
154+
$file = $path . $locale . '.' . Csv::FILE_EXTENSION;
156155

157156
$this->configureGeneralPhrasesMock($contextType, [$contextValue]);
158157

159158
$this->phraseMock->expects($this->once())
160159
->method('getPhrase')
161160
->willReturn($phrase);
161+
$this->phraseMock->expects($this->once())
162+
->method('setContextType')
163+
->with(null);
164+
$this->phraseMock->expects($this->once())
165+
->method('setContextValue')
166+
->with(null);
162167
$this->localeMock->expects($this->once())
163168
->method('__toString')
164169
->willReturn($locale);
165170

166-
$this->object->expects($this->once())
167-
->method('_getFileExtension')
168-
->willReturn($fileExtension);
169-
$this->object->expects($this->once())
170-
->method('_createDirectoryIfNotExist')
171-
->with(dirname($file));
172-
$this->object->expects($this->once())
173-
->method('_writeFile')
174-
->with($file, [$phrase => $this->phraseMock]);
175-
176171
$this->contextMock->expects($this->once())
177172
->method('buildPathToLocaleDirectoryByContext')
178173
->with($contextType, $contextValue)
179174
->willReturn($path);
180175

176+
$writerMock = $this->getMockForAbstractClass(WriterInterface::class);
177+
$writerMock->expects($this->once())
178+
->method('write')
179+
->with($this->phraseMock);
180+
$this->factoryMock->expects($this->once())
181+
->method('createDictionaryWriter')
182+
->with($file)
183+
->willReturn($writerMock);
184+
181185
$this->object->writeDictionary($this->dictionaryMock, $this->localeMock);
182186
}
183187

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Setup\Module\I18n\Pack\Writer\File;
7+
8+
/**
9+
* Mock is_dir function
10+
*
11+
* @see \Magento\Setup\Module\I18n\Pack\Writer\File\AbstractFile
12+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
13+
*/
14+
function is_dir($path)
15+
{
16+
return false;
17+
}
18+
19+
/**
20+
* Mock mkdir function
21+
*
22+
* @see \Magento\Setup\Module\I18n\Pack\Writer\File\AbstractFile
23+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
24+
*/
25+
function mkdir($pathname, $mode = 0777, $recursive = false, $context = null)
26+
{
27+
return true;
28+
}
29+
30+
/**
31+
* Mock chmod function
32+
*
33+
* @see \Magento\Setup\Module\I18n\Pack\Writer\File\AbstractFile
34+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
35+
*/
36+
function chmod($filename, $mode)
37+
{
38+
return true;
39+
}

0 commit comments

Comments
 (0)