6
6
namespace Magento \MagentoCloud \Test \Unit \Config \Validator \Deploy ;
7
7
8
8
use Composer \Composer ;
9
+ use Magento \MagentoCloud \Config \GlobalSection ;
9
10
use Magento \MagentoCloud \Config \Validator \Deploy \PhpVersion ;
10
11
use Composer \Package \Version \VersionParser ;
11
12
use Composer \Semver \Constraint \ConstraintInterface ;
@@ -62,6 +63,11 @@ class PhpVersionTest extends TestCase
62
63
*/
63
64
private $ phpConstraintMock ;
64
65
66
+ /**
67
+ * @var GlobalSection|MockObject
68
+ */
69
+ private $ globalSectionMock ;
70
+
65
71
/**
66
72
* @var PhpVersion
67
73
*/
@@ -77,42 +83,16 @@ protected function setUp()
77
83
$ this ->versionParserMock = $ this ->createMock (VersionParser::class);
78
84
$ this ->magentoVersionMock = $ this ->createMock (MagentoVersion::class);
79
85
$ this ->loggerMock = $ this ->getMockForAbstractClass (LoggerInterface::class);
86
+ $ this ->globalSectionMock = $ this ->createMock (GlobalSection::class);
80
87
81
88
$ this ->phpVersion = new PhpVersion (
82
89
$ this ->composerMock ,
83
90
$ this ->resultFactoryMock ,
84
91
$ this ->versionParserMock ,
85
92
$ this ->magentoVersionMock ,
86
- $ this ->loggerMock
93
+ $ this ->loggerMock ,
94
+ $ this ->globalSectionMock
87
95
);
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 );
116
96
}
117
97
118
98
/**
@@ -124,6 +104,7 @@ protected function setUp()
124
104
*/
125
105
public function testValidateSuccess ($ matchesResult , $ calledMethod , $ resultMock )
126
106
{
107
+ $ this ->setUpComposerMocks ();
127
108
$ this ->versionParserMock ->expects ($ this ->exactly (2 ))
128
109
->method ('parseConstraints ' )
129
110
->willReturnMap ([
@@ -157,6 +138,7 @@ public function validateDataProvider(): array
157
138
*/
158
139
public function testValidateException ()
159
140
{
141
+ $ this ->setUpComposerMocks ();
160
142
$ resultMock = $ this ->createMock (Success::class);
161
143
$ this ->versionParserMock ->expects ($ this ->any ())
162
144
->method ('parseConstraints ' )
@@ -170,4 +152,54 @@ public function testValidateException()
170
152
171
153
$ this ->assertSame ($ resultMock , $ this ->phpVersion ->validate ());
172
154
}
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
+ }
173
205
}
0 commit comments