Skip to content

Commit 5419380

Browse files
Merge pull request #422 from magento-thunder/MAGECLOUD-3187
MAGECLOUD-3187: PHP validation failed redeploy in case of git based installation
2 parents 8419d38 + 73f362b commit 5419380

File tree

2 files changed

+75
-30
lines changed

2 files changed

+75
-30
lines changed

src/Config/Validator/Deploy/PhpVersion.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Composer\Composer;
99
use Composer\Package\Version\VersionParser;
1010
use Composer\Semver\Constraint\ConstraintInterface;
11+
use Magento\MagentoCloud\Config\GlobalSection;
1112
use Magento\MagentoCloud\Config\ValidatorInterface;
1213
use Magento\MagentoCloud\Config\Validator;
1314
use Magento\MagentoCloud\Package\MagentoVersion;
@@ -44,25 +45,33 @@ class PhpVersion implements ValidatorInterface
4445
*/
4546
private $logger;
4647

48+
/**
49+
* @var GlobalSection
50+
*/
51+
private $globalSection;
52+
4753
/**
4854
* @param Composer $composer
4955
* @param Validator\ResultFactory $resultFactory
5056
* @param VersionParser $versionParser
5157
* @param MagentoVersion $magentoVersion
5258
* @param LoggerInterface $logger
59+
* @param GlobalSection $globalSection
5360
*/
5461
public function __construct(
5562
Composer $composer,
5663
Validator\ResultFactory $resultFactory,
5764
VersionParser $versionParser,
5865
MagentoVersion $magentoVersion,
59-
LoggerInterface $logger
66+
LoggerInterface $logger,
67+
GlobalSection $globalSection
6068
) {
6169
$this->composer = $composer;
6270
$this->resultFactory = $resultFactory;
6371
$this->versionParser = $versionParser;
6472
$this->magentoVersion = $magentoVersion;
6573
$this->logger = $logger;
74+
$this->globalSection = $globalSection;
6675
}
6776

6877
/**
@@ -73,6 +82,10 @@ public function __construct(
7382
public function validate(): Validator\ResultInterface
7483
{
7584
try {
85+
if ($this->globalSection->get(GlobalSection::VAR_DEPLOYED_MAGENTO_VERSION_FROM_GIT)) {
86+
return $this->resultFactory->success();
87+
}
88+
7689
$recommendedPhpConstraint = $this->getRecommendedPhpConstraint();
7790
$currentPhpConstraint = $this->getCurrentPhpConstraint();
7891

src/Test/Unit/Config/Validator/Deploy/PhpVersionTest.php

Lines changed: 61 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\MagentoCloud\Test\Unit\Config\Validator\Deploy;
77

88
use Composer\Composer;
9+
use Magento\MagentoCloud\Config\GlobalSection;
910
use Magento\MagentoCloud\Config\Validator\Deploy\PhpVersion;
1011
use Composer\Package\Version\VersionParser;
1112
use Composer\Semver\Constraint\ConstraintInterface;
@@ -62,6 +63,11 @@ class PhpVersionTest extends TestCase
6263
*/
6364
private $phpConstraintMock;
6465

66+
/**
67+
* @var GlobalSection|MockObject
68+
*/
69+
private $globalSectionMock;
70+
6571
/**
6672
* @var PhpVersion
6773
*/
@@ -77,42 +83,16 @@ protected function setUp()
7783
$this->versionParserMock = $this->createMock(VersionParser::class);
7884
$this->magentoVersionMock = $this->createMock(MagentoVersion::class);
7985
$this->loggerMock = $this->getMockForAbstractClass(LoggerInterface::class);
86+
$this->globalSectionMock = $this->createMock(GlobalSection::class);
8087

8188
$this->phpVersion = new PhpVersion(
8289
$this->composerMock,
8390
$this->resultFactoryMock,
8491
$this->versionParserMock,
8592
$this->magentoVersionMock,
86-
$this->loggerMock
93+
$this->loggerMock,
94+
$this->globalSectionMock
8795
);
88-
89-
$constraintMock = $this->getMockForAbstractClass(ConstraintInterface::class);
90-
$linkMock = $this->createMock(Link::class);
91-
$packageMock = $this->getMockForAbstractClass(PackageInterface::class);
92-
$repoMock = $this->getMockForAbstractClass(RepositoryInterface::class);
93-
$lockerMock = $this->createMock(Locker::class);
94-
$this->composerConstraintMock = $this->getMockForAbstractClass(ConstraintInterface::class);
95-
$this->phpConstraintMock = $this->getMockForAbstractClass(ConstraintInterface::class);
96-
97-
$constraintMock->expects($this->once())
98-
->method('getPrettyString')
99-
->willReturn('~7.1.13|~7.2.0');
100-
$linkMock->expects($this->once())
101-
->method('getConstraint')
102-
->willReturn($constraintMock);
103-
$packageMock->expects($this->once())
104-
->method('getRequires')
105-
->willReturn(['php' => $linkMock]);
106-
$repoMock->expects($this->once())
107-
->method('findPackage')
108-
->with('magento/magento2-base', '*')
109-
->willReturn($packageMock);
110-
$lockerMock->expects($this->once())
111-
->method('getLockedRepository')
112-
->willReturn($repoMock);
113-
$this->composerMock->expects($this->once())
114-
->method('getLocker')
115-
->willReturn($lockerMock);
11696
}
11797

11898
/**
@@ -124,6 +104,7 @@ protected function setUp()
124104
*/
125105
public function testValidateSuccess($matchesResult, $calledMethod, $resultMock)
126106
{
107+
$this->setUpComposerMocks();
127108
$this->versionParserMock->expects($this->exactly(2))
128109
->method('parseConstraints')
129110
->willReturnMap([
@@ -157,6 +138,7 @@ public function validateDataProvider(): array
157138
*/
158139
public function testValidateException()
159140
{
141+
$this->setUpComposerMocks();
160142
$resultMock = $this->createMock(Success::class);
161143
$this->versionParserMock->expects($this->any())
162144
->method('parseConstraints')
@@ -170,4 +152,54 @@ public function testValidateException()
170152

171153
$this->assertSame($resultMock, $this->phpVersion->validate());
172154
}
155+
156+
public function testValidationSuccessInstallFromGit()
157+
{
158+
$this->globalSectionMock->expects($this->once())
159+
->method('get')
160+
->with(GlobalSection::VAR_DEPLOYED_MAGENTO_VERSION_FROM_GIT)
161+
->willReturn('2.2');
162+
$this->versionParserMock->expects($this->never())
163+
->method('parseConstraints');
164+
$this->composerMock->expects($this->never())
165+
->method('getLocker');
166+
167+
$this->assertInstanceOf(Success::class, $this->phpVersion->validate());
168+
}
169+
170+
/**
171+
* Configure composer mocks
172+
*
173+
* @return void
174+
*/
175+
protected function setUpComposerMocks()
176+
{
177+
$constraintMock = $this->getMockForAbstractClass(ConstraintInterface::class);
178+
$linkMock = $this->createMock(Link::class);
179+
$packageMock = $this->getMockForAbstractClass(PackageInterface::class);
180+
$repoMock = $this->getMockForAbstractClass(RepositoryInterface::class);
181+
$lockerMock = $this->createMock(Locker::class);
182+
$this->composerConstraintMock = $this->getMockForAbstractClass(ConstraintInterface::class);
183+
$this->phpConstraintMock = $this->getMockForAbstractClass(ConstraintInterface::class);
184+
185+
$constraintMock->expects($this->once())
186+
->method('getPrettyString')
187+
->willReturn('~7.1.13|~7.2.0');
188+
$linkMock->expects($this->once())
189+
->method('getConstraint')
190+
->willReturn($constraintMock);
191+
$packageMock->expects($this->once())
192+
->method('getRequires')
193+
->willReturn(['php' => $linkMock]);
194+
$repoMock->expects($this->once())
195+
->method('findPackage')
196+
->with('magento/magento2-base', '*')
197+
->willReturn($packageMock);
198+
$lockerMock->expects($this->once())
199+
->method('getLockedRepository')
200+
->willReturn($repoMock);
201+
$this->composerMock->expects($this->once())
202+
->method('getLocker')
203+
->willReturn($lockerMock);
204+
}
173205
}

0 commit comments

Comments
 (0)