Skip to content

Commit c7d2822

Browse files
committed
MAGETWO-51544: [Github] Cannot upgrade to Magento 2.0.4 #4013
- Code updates based on review comments - Enhanced PathBuilder::build() logic. - Added couple of new error scenario tests to PathBuilderTest.php
1 parent db7c7ef commit c7d2822

File tree

4 files changed

+63
-17
lines changed

4 files changed

+63
-17
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ public function runReadinessCheck()
127127
// Prepare list of magento specific files and directory paths for updater application to check write
128128
// permissions
129129
try {
130-
$dirAndFilePaths = $this->pathBuilder->build();
131-
$resultJsonRawData[self::KEY_FILE_PATHS][self::KEY_LIST] = $dirAndFilePaths;
130+
$filePaths = $this->pathBuilder->build();
131+
$resultJsonRawData[self::KEY_FILE_PATHS][self::KEY_LIST] = $filePaths;
132132
} catch (\Exception $e) {
133133
$errorMsg = $e->getMessage();
134134
$returnValue = false;

setup/src/Magento/Setup/Model/PathBuilder.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ class PathBuilder
2222
* @var \Magento\Framework\Filesystem\Directory\ReadInterface $reader
2323
*/
2424
private $reader;
25+
2526
/**
2627
* Constructor
2728
*
@@ -43,16 +44,27 @@ public function build()
4344
{
4445
// Locate composer.json for magento2-base module and read the extra map section for the list of
4546
// magento specific files and directories that updater will need access to perform the upgrade
46-
$vendorDir = require VENDOR_PATH;
47-
4847

48+
$vendorDir = require VENDOR_PATH;
4949
$basePackageComposerFilePath = $vendorDir . '/' . self::MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE;
5050
if (!$this->reader->isExist($basePackageComposerFilePath)) {
5151
throw new \Magento\Setup\Exception(
5252
'Could not locate ' . self::MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE . ' file.'
5353
);
5454
}
55+
if (!$this->reader->isReadable($basePackageComposerFilePath)) {
56+
throw new \Magento\Setup\Exception(
57+
'Could not read ' . self::MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE . ' file.'
58+
);
59+
}
5560
$composerJsonFileData = json_decode($this->reader->readFile($basePackageComposerFilePath), true);
61+
if (!isset($composerJsonFileData[self::COMPOSER_KEY_EXTRA][self::COMPOSER_KEY_MAP])) {
62+
throw new \Magento\Setup\Exception(
63+
'Could not find "extra" => "map" section within '
64+
. self::MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE
65+
. ' file.'
66+
);
67+
}
5668
$extraMappings = $composerJsonFileData[self::COMPOSER_KEY_EXTRA][self::COMPOSER_KEY_MAP];
5769
$fileAndPathList = [];
5870
foreach ($extraMappings as $map) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function testRunReadinessCheckNoDbAccess()
101101
'error' => 'Connection failure'
102102
],
103103
ReadinessCheck::KEY_PHP_CHECKS => $this->expected,
104-
ReadinessCheck::KEY_DIR_AND_FILE_PATHS => [
104+
ReadinessCheck::KEY_FILE_PATHS => [
105105
ReadinessCheck::KEY_LIST => [__FILE__],
106106
ReadinessCheck::KEY_ERROR => ""
107107
],
@@ -127,7 +127,7 @@ public function testRunReadinessCheckNoDbWriteAccess()
127127
'error' => 'Database user username does not have write access.'
128128
],
129129
ReadinessCheck::KEY_PHP_CHECKS => $this->expected,
130-
ReadinessCheck::KEY_DIR_AND_FILE_PATHS => [
130+
ReadinessCheck::KEY_FILE_PATHS => [
131131
ReadinessCheck::KEY_LIST => [__FILE__],
132132
ReadinessCheck::KEY_ERROR => ""
133133
],
@@ -148,7 +148,7 @@ public function testRunReadinessCheck()
148148
$expected = [
149149
ReadinessCheck::KEY_READINESS_CHECKS => [ReadinessCheck::KEY_DB_WRITE_PERMISSION_VERIFIED => true],
150150
ReadinessCheck::KEY_PHP_CHECKS => $this->expected,
151-
ReadinessCheck::KEY_DIR_AND_FILE_PATHS => [
151+
ReadinessCheck::KEY_FILE_PATHS => [
152152
ReadinessCheck::KEY_LIST => [__FILE__],
153153
ReadinessCheck::KEY_ERROR => ""
154154
],
@@ -169,7 +169,7 @@ public function testRunReadinessCheckLastTimestamp()
169169
$expected = [
170170
ReadinessCheck::KEY_READINESS_CHECKS => [ReadinessCheck::KEY_DB_WRITE_PERMISSION_VERIFIED => true],
171171
ReadinessCheck::KEY_PHP_CHECKS => $this->expected,
172-
ReadinessCheck::KEY_DIR_AND_FILE_PATHS => [
172+
ReadinessCheck::KEY_FILE_PATHS => [
173173
ReadinessCheck::KEY_LIST => [__FILE__],
174174
ReadinessCheck::KEY_ERROR => ""
175175
],

setup/src/Magento/Setup/Test/Unit/Model/PathBuilderTest.php

Lines changed: 43 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
namespace Magento\Setup\Test\Unit\Model;
88

99
use \Magento\Setup\Model\PathBuilder;
10-
use \Magento\Setup\Model\Cron\ReadinessCheck;
1110

1211
class PathBuilderTest extends \PHPUnit_Framework_TestCase
1312
{
@@ -41,18 +40,15 @@ public function setup()
4140
'',
4241
false
4342
);
44-
$objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
4543
$this->readFactoryMock->expects($this->once())->method('create')->willReturn($this->readerMock);
46-
$this->pathBuilder = $objectManager->getObject(
47-
'Magento\Setup\Model\PathBuilder',
48-
['readFactory' => $this->readFactoryMock]
49-
);
44+
$this->pathBuilder = new PathBuilder($this->readFactoryMock);
5045
}
5146

52-
// Error scenario (magento/magento2-base/composer.json not found)
53-
public function testBuildNoComposerJsonFile()
47+
// Error scenario: magento/magento2-base/composer.json not found
48+
public function testBuildComposerJsonFileNotFound()
5449
{
5550
$this->readerMock->expects($this->once())->method('isExist')->willReturn(false);
51+
$this->readerMock->expects($this->never())->method('isReadable');
5652
$this->readerMock->expects($this->never())->method('readFile');
5753
$this->setExpectedException(
5854
'Magento\Setup\Exception',
@@ -61,10 +57,49 @@ public function testBuildNoComposerJsonFile()
6157
$this->pathBuilder->build();
6258
}
6359

60+
// Error scenario: magento/magento2-base/composer.json file could not be read
61+
public function testBuildComposerJsonFileNotReadable()
62+
{
63+
$this->readerMock->expects($this->once())->method('isExist')->willReturn(true);
64+
$this->readerMock->expects($this->once())->method('isReadable')->willReturn(false);
65+
$this->readerMock->expects($this->never())->method('readFile');
66+
$this->setExpectedException(
67+
'Magento\Setup\Exception',
68+
sprintf('Could not read %s file.', PathBuilder::MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE)
69+
);
70+
$this->pathBuilder->build();
71+
}
72+
73+
// Error scenario: ["extra"]["map"] is absent within magento/magento2-base/composer.json file
74+
public function testBuildNoExtraMapSectionInComposerJsonFile()
75+
{
76+
$this->readerMock->expects($this->once())->method('isExist')->willReturn(true);
77+
$this->readerMock->expects($this->once())->method('isReadable')->willReturn(true);
78+
$jsonData = json_encode(
79+
[
80+
PathBuilder::COMPOSER_KEY_EXTRA =>
81+
[
82+
__FILE__,
83+
__FILE__
84+
]
85+
]
86+
);
87+
$this->readerMock->expects($this->once())->method('readFile')->willReturn($jsonData);
88+
$this->setExpectedException(
89+
'Magento\Setup\Exception',
90+
sprintf(
91+
'Could not find "extra" => "map" section within %s file.',
92+
PathBuilder::MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE
93+
)
94+
);
95+
$this->pathBuilder->build();
96+
}
97+
6498
// Success scenario
6599
public function testBuild()
66100
{
67101
$this->readerMock->expects($this->once())->method('isExist')->willReturn(true);
102+
$this->readerMock->expects($this->once())->method('isReadable')->willReturn(true);
68103
$jsonData = json_encode(
69104
[
70105
PathBuilder::COMPOSER_KEY_EXTRA =>
@@ -88,5 +123,4 @@ public function testBuild()
88123
$actualList = $this->pathBuilder->build();
89124
$this->assertEquals($expectedList, $actualList);
90125
}
91-
92126
}

0 commit comments

Comments
 (0)