Skip to content

Commit

Permalink
Merge pull request #422 from magento-thunder/MAGECLOUD-3187
Browse files Browse the repository at this point in the history
MAGECLOUD-3187: PHP validation failed redeploy in case of git based installation
  • Loading branch information
shiftedreality authored Feb 22, 2019
2 parents 8419d38 + 73f362b commit 5419380
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 30 deletions.
15 changes: 14 additions & 1 deletion src/Config/Validator/Deploy/PhpVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Composer\Composer;
use Composer\Package\Version\VersionParser;
use Composer\Semver\Constraint\ConstraintInterface;
use Magento\MagentoCloud\Config\GlobalSection;
use Magento\MagentoCloud\Config\ValidatorInterface;
use Magento\MagentoCloud\Config\Validator;
use Magento\MagentoCloud\Package\MagentoVersion;
Expand Down Expand Up @@ -44,25 +45,33 @@ class PhpVersion implements ValidatorInterface
*/
private $logger;

/**
* @var GlobalSection
*/
private $globalSection;

/**
* @param Composer $composer
* @param Validator\ResultFactory $resultFactory
* @param VersionParser $versionParser
* @param MagentoVersion $magentoVersion
* @param LoggerInterface $logger
* @param GlobalSection $globalSection
*/
public function __construct(
Composer $composer,
Validator\ResultFactory $resultFactory,
VersionParser $versionParser,
MagentoVersion $magentoVersion,
LoggerInterface $logger
LoggerInterface $logger,
GlobalSection $globalSection
) {
$this->composer = $composer;
$this->resultFactory = $resultFactory;
$this->versionParser = $versionParser;
$this->magentoVersion = $magentoVersion;
$this->logger = $logger;
$this->globalSection = $globalSection;
}

/**
Expand All @@ -73,6 +82,10 @@ public function __construct(
public function validate(): Validator\ResultInterface
{
try {
if ($this->globalSection->get(GlobalSection::VAR_DEPLOYED_MAGENTO_VERSION_FROM_GIT)) {
return $this->resultFactory->success();
}

$recommendedPhpConstraint = $this->getRecommendedPhpConstraint();
$currentPhpConstraint = $this->getCurrentPhpConstraint();

Expand Down
90 changes: 61 additions & 29 deletions src/Test/Unit/Config/Validator/Deploy/PhpVersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\MagentoCloud\Test\Unit\Config\Validator\Deploy;

use Composer\Composer;
use Magento\MagentoCloud\Config\GlobalSection;
use Magento\MagentoCloud\Config\Validator\Deploy\PhpVersion;
use Composer\Package\Version\VersionParser;
use Composer\Semver\Constraint\ConstraintInterface;
Expand Down Expand Up @@ -62,6 +63,11 @@ class PhpVersionTest extends TestCase
*/
private $phpConstraintMock;

/**
* @var GlobalSection|MockObject
*/
private $globalSectionMock;

/**
* @var PhpVersion
*/
Expand All @@ -77,42 +83,16 @@ protected function setUp()
$this->versionParserMock = $this->createMock(VersionParser::class);
$this->magentoVersionMock = $this->createMock(MagentoVersion::class);
$this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
$this->globalSectionMock = $this->createMock(GlobalSection::class);

$this->phpVersion = new PhpVersion(
$this->composerMock,
$this->resultFactoryMock,
$this->versionParserMock,
$this->magentoVersionMock,
$this->loggerMock
$this->loggerMock,
$this->globalSectionMock
);

$constraintMock = $this->getMockForAbstractClass(ConstraintInterface::class);
$linkMock = $this->createMock(Link::class);
$packageMock = $this->getMockForAbstractClass(PackageInterface::class);
$repoMock = $this->getMockForAbstractClass(RepositoryInterface::class);
$lockerMock = $this->createMock(Locker::class);
$this->composerConstraintMock = $this->getMockForAbstractClass(ConstraintInterface::class);
$this->phpConstraintMock = $this->getMockForAbstractClass(ConstraintInterface::class);

$constraintMock->expects($this->once())
->method('getPrettyString')
->willReturn('~7.1.13|~7.2.0');
$linkMock->expects($this->once())
->method('getConstraint')
->willReturn($constraintMock);
$packageMock->expects($this->once())
->method('getRequires')
->willReturn(['php' => $linkMock]);
$repoMock->expects($this->once())
->method('findPackage')
->with('magento/magento2-base', '*')
->willReturn($packageMock);
$lockerMock->expects($this->once())
->method('getLockedRepository')
->willReturn($repoMock);
$this->composerMock->expects($this->once())
->method('getLocker')
->willReturn($lockerMock);
}

/**
Expand All @@ -124,6 +104,7 @@ protected function setUp()
*/
public function testValidateSuccess($matchesResult, $calledMethod, $resultMock)
{
$this->setUpComposerMocks();
$this->versionParserMock->expects($this->exactly(2))
->method('parseConstraints')
->willReturnMap([
Expand Down Expand Up @@ -157,6 +138,7 @@ public function validateDataProvider(): array
*/
public function testValidateException()
{
$this->setUpComposerMocks();
$resultMock = $this->createMock(Success::class);
$this->versionParserMock->expects($this->any())
->method('parseConstraints')
Expand All @@ -170,4 +152,54 @@ public function testValidateException()

$this->assertSame($resultMock, $this->phpVersion->validate());
}

public function testValidationSuccessInstallFromGit()
{
$this->globalSectionMock->expects($this->once())
->method('get')
->with(GlobalSection::VAR_DEPLOYED_MAGENTO_VERSION_FROM_GIT)
->willReturn('2.2');
$this->versionParserMock->expects($this->never())
->method('parseConstraints');
$this->composerMock->expects($this->never())
->method('getLocker');

$this->assertInstanceOf(Success::class, $this->phpVersion->validate());
}

/**
* Configure composer mocks
*
* @return void
*/
protected function setUpComposerMocks()
{
$constraintMock = $this->getMockForAbstractClass(ConstraintInterface::class);
$linkMock = $this->createMock(Link::class);
$packageMock = $this->getMockForAbstractClass(PackageInterface::class);
$repoMock = $this->getMockForAbstractClass(RepositoryInterface::class);
$lockerMock = $this->createMock(Locker::class);
$this->composerConstraintMock = $this->getMockForAbstractClass(ConstraintInterface::class);
$this->phpConstraintMock = $this->getMockForAbstractClass(ConstraintInterface::class);

$constraintMock->expects($this->once())
->method('getPrettyString')
->willReturn('~7.1.13|~7.2.0');
$linkMock->expects($this->once())
->method('getConstraint')
->willReturn($constraintMock);
$packageMock->expects($this->once())
->method('getRequires')
->willReturn(['php' => $linkMock]);
$repoMock->expects($this->once())
->method('findPackage')
->with('magento/magento2-base', '*')
->willReturn($packageMock);
$lockerMock->expects($this->once())
->method('getLockedRepository')
->willReturn($repoMock);
$this->composerMock->expects($this->once())
->method('getLocker')
->willReturn($lockerMock);
}
}

0 comments on commit 5419380

Please sign in to comment.