Skip to content

Commit f145821

Browse files
committed
MAGETWO-51544: [Github] Cannot upgrade to Magento 2.0.4 #4013
- rename PathBuilder class per review
1 parent 0dbb605 commit f145821

File tree

4 files changed

+42
-39
lines changed

4 files changed

+42
-39
lines changed

setup/src/Magento/Setup/Model/PathBuilder.php renamed to setup/src/Magento/Setup/Model/BasePackageInfo.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
use Magento\Framework\FileSystem\Directory\ReadFactory;
99

1010
/**
11-
* Prepares list of magento specific files and directory paths that updater will need access to perform the upgrade
11+
* Information about the Magento base package.
12+
*
1213
*/
13-
class PathBuilder
14+
class BasePackageInfo
1415
{
1516
const MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE = 'magento/magento2-base/composer.json';
1617

@@ -34,17 +35,14 @@ public function __construct(ReadFactory $readFactory)
3435
}
3536

3637
/**
37-
* Builds list of important files and directory paths that used by magento that updater application will need
38-
* access to perform upgrade operation
38+
* Get the list of files and directory paths from magento-base extra/map section.
3939
*
4040
* @return string []
4141
* @throws \Magento\Setup\Exception
4242
*/
43-
public function build()
43+
public function getPaths()
4444
{
45-
// Locate composer.json for magento2-base module and read the extra map section for the list of
46-
// magento specific files and directories that updater will need access to perform the upgrade
47-
45+
// Locate composer.json for magento2-base module
4846
$filesPathList = [];
4947
$vendorDir = require VENDOR_PATH;
5048
$basePackageComposerFilePath = $vendorDir . '/' . self::MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE;
@@ -58,6 +56,8 @@ public function build()
5856
'Could not read ' . self::MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE . ' file.'
5957
);
6058
}
59+
60+
// Fill array with list of files and directories from extra/map section
6161
$composerJsonFileData = json_decode($this->reader->readFile($basePackageComposerFilePath), true);
6262
if (!isset($composerJsonFileData[self::COMPOSER_KEY_EXTRA][self::COMPOSER_KEY_MAP])) {
6363
return $filesPathList;

setup/src/Magento/Setup/Model/Cron/ReadinessCheck.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
use Magento\Framework\App\Filesystem\DirectoryList;
1010
use Magento\Framework\Config\ConfigOptionsListConstants;
1111
use Magento\Framework\Filesystem;
12-
use Magento\Framework\View\Design\Theme\Customization\Path;
1312
use Magento\Setup\Model\PhpReadinessCheck;
1413
use Magento\Setup\Validator\DbValidator;
15-
use Magento\Setup\Model\PathBuilder;
14+
use Magento\Setup\Model\BasePackageInfo;
1615

1716
/**
1817
* This class is used by setup:cron:run command to check if this command can be run properly. It also checks if PHP
@@ -62,9 +61,9 @@ class ReadinessCheck
6261
private $phpReadinessCheck;
6362

6463
/**
65-
* @var PathBuilder
64+
* @var BasePackageInfo
6665
*/
67-
private $pathBuilder;
66+
private $basePackageInfo;
6867

6968
/**
7069
* Constructor
@@ -73,20 +72,20 @@ class ReadinessCheck
7372
* @param DeploymentConfig $deploymentConfig
7473
* @param Filesystem $filesystem
7574
* @param PhpReadinessCheck $phpReadinessCheck
76-
* @param PathBuilder $pathBuilder
75+
* @param BasePackageInfo $basePackageInfo
7776
*/
7877
public function __construct(
7978
DbValidator $dbValidator,
8079
DeploymentConfig $deploymentConfig,
8180
Filesystem $filesystem,
8281
PhpReadinessCheck $phpReadinessCheck,
83-
PathBuilder $pathBuilder
82+
BasePackageInfo $basePackageInfo
8483
) {
8584
$this->dbValidator = $dbValidator;
8685
$this->deploymentConfig = $deploymentConfig;
8786
$this->filesystem = $filesystem;
8887
$this->phpReadinessCheck = $phpReadinessCheck;
89-
$this->pathBuilder = $pathBuilder;
88+
$this->basePackageInfo = $basePackageInfo;
9089
}
9190

9291
/**
@@ -127,7 +126,7 @@ public function runReadinessCheck()
127126
// Prepare list of magento specific files and directory paths for updater application to check write
128127
// permissions
129128
try {
130-
$filePaths = $this->pathBuilder->build();
129+
$filePaths = $this->basePackageInfo->getPaths();
131130
$resultJsonRawData[self::KEY_FILE_PATHS][self::KEY_LIST] = $filePaths;
132131
} catch (\Exception $e) {
133132
$errorMsg = $e->getMessage();

setup/src/Magento/Setup/Test/Unit/Model/PathBuilderTest.php renamed to setup/src/Magento/Setup/Test/Unit/Model/BasePackageInfoTest.php

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,13 @@
66

77
namespace Magento\Setup\Test\Unit\Model;
88

9-
use \Magento\Setup\Model\PathBuilder;
9+
use \Magento\Setup\Model\BasePackageInfo;
1010

11-
class PathBuilderTest extends \PHPUnit_Framework_TestCase
11+
/**
12+
* Tests BasePackageInfo
13+
*
14+
*/
15+
class BasePackageInfoTest extends \PHPUnit_Framework_TestCase
1216
{
1317
/**
1418
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\FileSystem\Directory\ReadFactory
@@ -21,9 +25,9 @@ class PathBuilderTest extends \PHPUnit_Framework_TestCase
2125
private $readerMock;
2226

2327
/**
24-
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\PathBuilder
28+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\BasePackageInfo
2529
*/
26-
private $pathBuilder;
30+
private $basePackageInfo;
2731

2832
public function setup()
2933
{
@@ -41,43 +45,43 @@ public function setup()
4145
false
4246
);
4347
$this->readFactoryMock->expects($this->once())->method('create')->willReturn($this->readerMock);
44-
$this->pathBuilder = new PathBuilder($this->readFactoryMock);
48+
$this->basePackageInfo = new BasePackageInfo($this->readFactoryMock);
4549
}
4650

4751
// Error scenario: magento/magento2-base/composer.json not found
48-
public function testBuildComposerJsonFileNotFound()
52+
public function testBaseComposerJsonFileNotFound()
4953
{
5054
$this->readerMock->expects($this->once())->method('isExist')->willReturn(false);
5155
$this->readerMock->expects($this->never())->method('isReadable');
5256
$this->readerMock->expects($this->never())->method('readFile');
5357
$this->setExpectedException(
5458
'Magento\Setup\Exception',
55-
sprintf('Could not locate %s file.', PathBuilder::MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE)
59+
sprintf('Could not locate %s file.', BasePackageInfo::MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE)
5660
);
57-
$this->pathBuilder->build();
61+
$this->basePackageInfo->getPaths();
5862
}
5963

6064
// Error scenario: magento/magento2-base/composer.json file could not be read
61-
public function testBuildComposerJsonFileNotReadable()
65+
public function testBaseComposerJsonFileNotReadable()
6266
{
6367
$this->readerMock->expects($this->once())->method('isExist')->willReturn(true);
6468
$this->readerMock->expects($this->once())->method('isReadable')->willReturn(false);
6569
$this->readerMock->expects($this->never())->method('readFile');
6670
$this->setExpectedException(
6771
'Magento\Setup\Exception',
68-
sprintf('Could not read %s file.', PathBuilder::MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE)
72+
sprintf('Could not read %s file.', BasePackageInfo::MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE)
6973
);
70-
$this->pathBuilder->build();
74+
$this->basePackageInfo->getPaths();
7175
}
7276

7377
// Scenario: ["extra"]["map"] is absent within magento/magento2-base/composer.json file
74-
public function testBuildNoExtraMapSectionInComposerJsonFile()
78+
public function testBaseNoExtraMapSectionInComposerJsonFile()
7579
{
7680
$this->readerMock->expects($this->once())->method('isExist')->willReturn(true);
7781
$this->readerMock->expects($this->once())->method('isReadable')->willReturn(true);
7882
$jsonData = json_encode(
7983
[
80-
PathBuilder::COMPOSER_KEY_EXTRA =>
84+
BasePackageInfo::COMPOSER_KEY_EXTRA =>
8185
[
8286
__FILE__,
8387
__FILE__
@@ -86,20 +90,20 @@ public function testBuildNoExtraMapSectionInComposerJsonFile()
8690
);
8791
$this->readerMock->expects($this->once())->method('readFile')->willReturn($jsonData);
8892
$expectedList = [];
89-
$actualList = $this->pathBuilder->build();
93+
$actualList = $this->basePackageInfo->getPaths();
9094
$this->assertEquals($expectedList, $actualList);
9195
}
9296

9397
// Success scenario
94-
public function testBuild()
98+
public function testBasePackageInfo()
9599
{
96100
$this->readerMock->expects($this->once())->method('isExist')->willReturn(true);
97101
$this->readerMock->expects($this->once())->method('isReadable')->willReturn(true);
98102
$jsonData = json_encode(
99103
[
100-
PathBuilder::COMPOSER_KEY_EXTRA =>
104+
BasePackageInfo::COMPOSER_KEY_EXTRA =>
101105
[
102-
PathBuilder::COMPOSER_KEY_MAP =>
106+
BasePackageInfo::COMPOSER_KEY_MAP =>
103107
[
104108
[
105109
__FILE__,
@@ -115,7 +119,7 @@ public function testBuild()
115119
);
116120
$this->readerMock->expects($this->once())->method('readFile')->willReturn($jsonData);
117121
$expectedList = [__FILE__, __DIR__];
118-
$actualList = $this->pathBuilder->build();
122+
$actualList = $this->basePackageInfo->getPaths();
119123
$this->assertEquals($expectedList, $actualList);
120124
}
121125
}

setup/src/Magento/Setup/Test/Unit/Model/Cron/ReadinessCheckTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ class ReadinessCheckTest extends \PHPUnit_Framework_TestCase
4141
private $readinessCheck;
4242

4343
/**
44-
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\PathBuilder
44+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\BasePackageInfo
4545
*/
46-
private $pathBuilder;
46+
private $basePackageInfo;
4747

4848
/**
4949
* @var array
@@ -68,14 +68,14 @@ public function setUp()
6868
$this->write = $this->getMock('Magento\Framework\Filesystem\Directory\Write', [], [], '', false);
6969
$this->filesystem->expects($this->once())->method('getDirectoryWrite')->willReturn($this->write);
7070
$this->phpReadinessCheck = $this->getMock('Magento\Setup\Model\PhpReadinessCheck', [], [], '', false);
71-
$this->pathBuilder = $this->getMock('Magento\Setup\Model\PathBuilder', [], [], '', false);
72-
$this->pathBuilder->expects($this->once())->method('build')->willReturn([__FILE__]);
71+
$this->basePackageInfo = $this->getMock('Magento\Setup\Model\BasePackageInfo', [], [], '', false);
72+
$this->basePackageInfo->expects($this->once())->method('getPaths')->willReturn([__FILE__]);
7373
$this->readinessCheck = new ReadinessCheck(
7474
$this->dbValidator,
7575
$this->deploymentConfig,
7676
$this->filesystem,
7777
$this->phpReadinessCheck,
78-
$this->pathBuilder
78+
$this->basePackageInfo
7979
);
8080
$this->phpReadinessCheck->expects($this->once())->method('checkPhpVersion')->willReturn(['success' => true]);
8181
$this->phpReadinessCheck->expects($this->once())->method('checkPhpExtensions')->willReturn(['success' => true]);

0 commit comments

Comments
 (0)