Skip to content

Commit 86b640d

Browse files
committed
MAGETWO-44547: [php7] "PHP Settings Check" fail in Web Setup Wizard blocks installation via web
- fixed incorrect version check
1 parent 94fdef3 commit 86b640d

File tree

2 files changed

+37
-10
lines changed

2 files changed

+37
-10
lines changed

setup/src/Magento/Setup/Model/PhpReadinessCheck.php

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,7 @@ public function checkPhpVersion()
6565
];
6666
}
6767
$multipleConstraints = $this->versionParser->parseConstraints($requiredVersion);
68-
try {
69-
$normalizedPhpVersion = $this->versionParser->normalize(PHP_VERSION);
70-
} catch (\UnexpectedValueException $e) {
71-
$prettyVersion = preg_replace('#^([^~+-]+).*$#', '$1', PHP_VERSION);
72-
$normalizedPhpVersion = $this->versionParser->normalize($prettyVersion);
73-
}
68+
$normalizedPhpVersion = $this->normalizePhpVersion(PHP_VERSION);
7469
$currentPhpVersion = $this->versionParser->parseConstraints($normalizedPhpVersion);
7570
$responseType = ResponseTypeInterface::RESPONSE_TYPE_SUCCESS;
7671
if (!$multipleConstraints->matches($currentPhpVersion)) {
@@ -200,8 +195,10 @@ private function checkPopulateRawPostSetting()
200195
$error = false;
201196
$iniSetting = intVal(ini_get('always_populate_raw_post_data'));
202197

203-
if (version_compare(PHP_VERSION, '5.6.0') >= 0
204-
&& version_compare(PHP_VERSION, '7.0.0') < 0
198+
$checkVersionConstraint = $this->versionParser->parseConstraints('~5.6.0');
199+
$normalizedPhpVersion = $this->normalizePhpVersion(PHP_VERSION);
200+
$currentVersion = $this->versionParser->parseConstraints($normalizedPhpVersion);
201+
if ($checkVersionConstraint->matches($currentVersion)
205202
&& $iniSetting !== -1
206203
) {
207204
$error = true;
@@ -225,4 +222,22 @@ private function checkPopulateRawPostSetting()
225222

226223
return $data;
227224
}
225+
226+
227+
/**
228+
* Normalize PHP Version
229+
*
230+
* @param string $version
231+
* @return string
232+
*/
233+
private function normalizePhpVersion($version)
234+
{
235+
try {
236+
$normalizedPhpVersion = $this->versionParser->normalize($version);
237+
} catch (\UnexpectedValueException $e) {
238+
$prettyVersion = preg_replace('#^([^~+-]+).*$#', '$1', $version);
239+
$normalizedPhpVersion = $this->versionParser->normalize($prettyVersion);
240+
}
241+
return $normalizedPhpVersion;
242+
}
228243
}

setup/src/Magento/Setup/Test/Unit/Model/PhpReadinessCheckTest.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,8 @@ public function testCheckPhpVersionPrettyVersionFailed()
117117
$this->assertEquals($expected, $this->phpReadinessCheck->checkPhpVersion());
118118
}
119119

120-
public function testCheckPhpVersion()
120+
private function setUpNoPrettyVersionParser()
121121
{
122-
$this->composerInfo->expects($this->once())->method('getRequiredPhpVersion')->willReturn('1.0');
123122
$multipleConstraints = $this->getMockForAbstractClass(
124123
'Composer\Package\LinkConstraint\LinkConstraintInterface',
125124
[],
@@ -136,6 +135,13 @@ public function testCheckPhpVersion()
136135
);
137136
$this->versionParser->expects($this->at(2))->method('parseConstraints')->willReturn($currentPhpVersion);
138137
$multipleConstraints->expects($this->once())->method('matches')->willReturn(true);
138+
}
139+
140+
public function testCheckPhpVersion()
141+
{
142+
$this->composerInfo->expects($this->once())->method('getRequiredPhpVersion')->willReturn('1.0');
143+
144+
$this->setUpNoPrettyVersionParser();
139145
$expected = [
140146
'responseType' => ResponseTypeInterface::RESPONSE_TYPE_SUCCESS,
141147
'data' => [
@@ -186,6 +192,8 @@ public function testCheckPhpSettings()
186192
100,
187193
50
188194
);
195+
196+
$this->setUpNoPrettyVersionParser();
189197
$rawPostMessage = sprintf(
190198
'Your PHP Version is %s, but always_populate_raw_post_data = -1.
191199
$HTTP_RAW_POST_DATA is deprecated from PHP 5.6 onwards and will be removed in PHP 7.0.
@@ -222,6 +230,8 @@ public function testCheckPhpSettingsFailed()
222230
100,
223231
200
224232
);
233+
234+
$this->setUpNoPrettyVersionParser();
225235
$rawPostMessage = sprintf(
226236
'Your PHP Version is %s, but always_populate_raw_post_data = -1.
227237
$HTTP_RAW_POST_DATA is deprecated from PHP 5.6 onwards and will be removed in PHP 7.0.
@@ -250,6 +260,8 @@ public function testCheckPhpSettingsFailed()
250260
public function testCheckPhpSettingsNoXDebug()
251261
{
252262
$this->phpInfo->expects($this->once())->method('getCurrent')->willReturn([]);
263+
264+
$this->setUpNoPrettyVersionParser();
253265
$rawPostMessage = sprintf(
254266
'Your PHP Version is %s, but always_populate_raw_post_data = -1.
255267
$HTTP_RAW_POST_DATA is deprecated from PHP 5.6 onwards and will be removed in PHP 7.0.

0 commit comments

Comments
 (0)