Skip to content

Commit

Permalink
MAGETWO-51544: [Github] Cannot upgrade to Magento 2.0.4 #4013
Browse files Browse the repository at this point in the history
 - rename PathBuilder class per review
  • Loading branch information
monkeysee committed May 13, 2016
1 parent 0dbb605 commit f145821
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
use Magento\Framework\FileSystem\Directory\ReadFactory;

/**
* Prepares list of magento specific files and directory paths that updater will need access to perform the upgrade
* Information about the Magento base package.
*
*/
class PathBuilder
class BasePackageInfo
{
const MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE = 'magento/magento2-base/composer.json';

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

/**
* Builds list of important files and directory paths that used by magento that updater application will need
* access to perform upgrade operation
* Get the list of files and directory paths from magento-base extra/map section.
*
* @return string []
* @throws \Magento\Setup\Exception
*/
public function build()
public function getPaths()
{
// Locate composer.json for magento2-base module and read the extra map section for the list of
// magento specific files and directories that updater will need access to perform the upgrade

// Locate composer.json for magento2-base module
$filesPathList = [];
$vendorDir = require VENDOR_PATH;
$basePackageComposerFilePath = $vendorDir . '/' . self::MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE;
Expand All @@ -58,6 +56,8 @@ public function build()
'Could not read ' . self::MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE . ' file.'
);
}

// Fill array with list of files and directories from extra/map section
$composerJsonFileData = json_decode($this->reader->readFile($basePackageComposerFilePath), true);
if (!isset($composerJsonFileData[self::COMPOSER_KEY_EXTRA][self::COMPOSER_KEY_MAP])) {
return $filesPathList;
Expand Down
15 changes: 7 additions & 8 deletions setup/src/Magento/Setup/Model/Cron/ReadinessCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,9 @@
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Framework\Config\ConfigOptionsListConstants;
use Magento\Framework\Filesystem;
use Magento\Framework\View\Design\Theme\Customization\Path;
use Magento\Setup\Model\PhpReadinessCheck;
use Magento\Setup\Validator\DbValidator;
use Magento\Setup\Model\PathBuilder;
use Magento\Setup\Model\BasePackageInfo;

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

/**
* @var PathBuilder
* @var BasePackageInfo
*/
private $pathBuilder;
private $basePackageInfo;

/**
* Constructor
Expand All @@ -73,20 +72,20 @@ class ReadinessCheck
* @param DeploymentConfig $deploymentConfig
* @param Filesystem $filesystem
* @param PhpReadinessCheck $phpReadinessCheck
* @param PathBuilder $pathBuilder
* @param BasePackageInfo $basePackageInfo
*/
public function __construct(
DbValidator $dbValidator,
DeploymentConfig $deploymentConfig,
Filesystem $filesystem,
PhpReadinessCheck $phpReadinessCheck,
PathBuilder $pathBuilder
BasePackageInfo $basePackageInfo
) {
$this->dbValidator = $dbValidator;
$this->deploymentConfig = $deploymentConfig;
$this->filesystem = $filesystem;
$this->phpReadinessCheck = $phpReadinessCheck;
$this->pathBuilder = $pathBuilder;
$this->basePackageInfo = $basePackageInfo;
}

/**
Expand Down Expand Up @@ -127,7 +126,7 @@ public function runReadinessCheck()
// Prepare list of magento specific files and directory paths for updater application to check write
// permissions
try {
$filePaths = $this->pathBuilder->build();
$filePaths = $this->basePackageInfo->getPaths();
$resultJsonRawData[self::KEY_FILE_PATHS][self::KEY_LIST] = $filePaths;
} catch (\Exception $e) {
$errorMsg = $e->getMessage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@

namespace Magento\Setup\Test\Unit\Model;

use \Magento\Setup\Model\PathBuilder;
use \Magento\Setup\Model\BasePackageInfo;

class PathBuilderTest extends \PHPUnit_Framework_TestCase
/**
* Tests BasePackageInfo
*
*/
class BasePackageInfoTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Framework\FileSystem\Directory\ReadFactory
Expand All @@ -21,9 +25,9 @@ class PathBuilderTest extends \PHPUnit_Framework_TestCase
private $readerMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\PathBuilder
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\BasePackageInfo
*/
private $pathBuilder;
private $basePackageInfo;

public function setup()
{
Expand All @@ -41,43 +45,43 @@ public function setup()
false
);
$this->readFactoryMock->expects($this->once())->method('create')->willReturn($this->readerMock);
$this->pathBuilder = new PathBuilder($this->readFactoryMock);
$this->basePackageInfo = new BasePackageInfo($this->readFactoryMock);
}

// Error scenario: magento/magento2-base/composer.json not found
public function testBuildComposerJsonFileNotFound()
public function testBaseComposerJsonFileNotFound()
{
$this->readerMock->expects($this->once())->method('isExist')->willReturn(false);
$this->readerMock->expects($this->never())->method('isReadable');
$this->readerMock->expects($this->never())->method('readFile');
$this->setExpectedException(
'Magento\Setup\Exception',
sprintf('Could not locate %s file.', PathBuilder::MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE)
sprintf('Could not locate %s file.', BasePackageInfo::MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE)
);
$this->pathBuilder->build();
$this->basePackageInfo->getPaths();
}

// Error scenario: magento/magento2-base/composer.json file could not be read
public function testBuildComposerJsonFileNotReadable()
public function testBaseComposerJsonFileNotReadable()
{
$this->readerMock->expects($this->once())->method('isExist')->willReturn(true);
$this->readerMock->expects($this->once())->method('isReadable')->willReturn(false);
$this->readerMock->expects($this->never())->method('readFile');
$this->setExpectedException(
'Magento\Setup\Exception',
sprintf('Could not read %s file.', PathBuilder::MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE)
sprintf('Could not read %s file.', BasePackageInfo::MAGENTO_BASE_PACKAGE_COMPOSER_JSON_FILE)
);
$this->pathBuilder->build();
$this->basePackageInfo->getPaths();
}

// Scenario: ["extra"]["map"] is absent within magento/magento2-base/composer.json file
public function testBuildNoExtraMapSectionInComposerJsonFile()
public function testBaseNoExtraMapSectionInComposerJsonFile()
{
$this->readerMock->expects($this->once())->method('isExist')->willReturn(true);
$this->readerMock->expects($this->once())->method('isReadable')->willReturn(true);
$jsonData = json_encode(
[
PathBuilder::COMPOSER_KEY_EXTRA =>
BasePackageInfo::COMPOSER_KEY_EXTRA =>
[
__FILE__,
__FILE__
Expand All @@ -86,20 +90,20 @@ public function testBuildNoExtraMapSectionInComposerJsonFile()
);
$this->readerMock->expects($this->once())->method('readFile')->willReturn($jsonData);
$expectedList = [];
$actualList = $this->pathBuilder->build();
$actualList = $this->basePackageInfo->getPaths();
$this->assertEquals($expectedList, $actualList);
}

// Success scenario
public function testBuild()
public function testBasePackageInfo()
{
$this->readerMock->expects($this->once())->method('isExist')->willReturn(true);
$this->readerMock->expects($this->once())->method('isReadable')->willReturn(true);
$jsonData = json_encode(
[
PathBuilder::COMPOSER_KEY_EXTRA =>
BasePackageInfo::COMPOSER_KEY_EXTRA =>
[
PathBuilder::COMPOSER_KEY_MAP =>
BasePackageInfo::COMPOSER_KEY_MAP =>
[
[
__FILE__,
Expand All @@ -115,7 +119,7 @@ public function testBuild()
);
$this->readerMock->expects($this->once())->method('readFile')->willReturn($jsonData);
$expectedList = [__FILE__, __DIR__];
$actualList = $this->pathBuilder->build();
$actualList = $this->basePackageInfo->getPaths();
$this->assertEquals($expectedList, $actualList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ class ReadinessCheckTest extends \PHPUnit_Framework_TestCase
private $readinessCheck;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\PathBuilder
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Setup\Model\BasePackageInfo
*/
private $pathBuilder;
private $basePackageInfo;

/**
* @var array
Expand All @@ -68,14 +68,14 @@ public function setUp()
$this->write = $this->getMock('Magento\Framework\Filesystem\Directory\Write', [], [], '', false);
$this->filesystem->expects($this->once())->method('getDirectoryWrite')->willReturn($this->write);
$this->phpReadinessCheck = $this->getMock('Magento\Setup\Model\PhpReadinessCheck', [], [], '', false);
$this->pathBuilder = $this->getMock('Magento\Setup\Model\PathBuilder', [], [], '', false);
$this->pathBuilder->expects($this->once())->method('build')->willReturn([__FILE__]);
$this->basePackageInfo = $this->getMock('Magento\Setup\Model\BasePackageInfo', [], [], '', false);
$this->basePackageInfo->expects($this->once())->method('getPaths')->willReturn([__FILE__]);
$this->readinessCheck = new ReadinessCheck(
$this->dbValidator,
$this->deploymentConfig,
$this->filesystem,
$this->phpReadinessCheck,
$this->pathBuilder
$this->basePackageInfo
);
$this->phpReadinessCheck->expects($this->once())->method('checkPhpVersion')->willReturn(['success' => true]);
$this->phpReadinessCheck->expects($this->once())->method('checkPhpExtensions')->willReturn(['success' => true]);
Expand Down

0 comments on commit f145821

Please sign in to comment.