66namespace Magento \MagentoCloud \Test \Unit \Config \Validator \Deploy ;
77
88use Composer \Composer ;
9+ use Magento \MagentoCloud \Config \GlobalSection ;
910use Magento \MagentoCloud \Config \Validator \Deploy \PhpVersion ;
1011use Composer \Package \Version \VersionParser ;
1112use 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