Skip to content

Commit 0e66366

Browse files
committed
Merge remote-tracking branch 'ogresCE/MAGETWO-44547-php7-readiness-check-fail' into PR_Branch
2 parents cc59883 + 89ea86b commit 0e66366

File tree

2 files changed

+48
-21
lines changed

2 files changed

+48
-21
lines changed

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

Lines changed: 25 additions & 10 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->getNormalizedCurrentPhpVersion(PHP_VERSION);
7469
$currentPhpVersion = $this->versionParser->parseConstraints($normalizedPhpVersion);
7570
$responseType = ResponseTypeInterface::RESPONSE_TYPE_SUCCESS;
7671
if (!$multipleConstraints->matches($currentPhpVersion)) {
@@ -200,16 +195,19 @@ 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 && $iniSetting !== -1) {
198+
$checkVersionConstraint = $this->versionParser->parseConstraints('~5.6.0');
199+
$normalizedPhpVersion = $this->getNormalizedCurrentPhpVersion(PHP_VERSION);
200+
$currentVersion = $this->versionParser->parseConstraints($normalizedPhpVersion);
201+
if ($checkVersionConstraint->matches($currentVersion) && $iniSetting !== -1) {
204202
$error = true;
205203
}
206204

207205
$message = sprintf(
208206
'Your PHP Version is %s, but always_populate_raw_post_data = %d.
209-
$HTTP_RAW_POST_DATA is deprecated from PHP 5.6 onwards and will stop the installer from running.
207+
$HTTP_RAW_POST_DATA is deprecated from PHP 5.6 onwards and will be removed in PHP 7.0.
208+
This will stop the installer from running.
210209
Please open your php.ini file and set always_populate_raw_post_data to -1.
211-
If you need more help please call your hosting provider.
212-
',
210+
If you need more help please call your hosting provider.',
213211
PHP_VERSION,
214212
intVal(ini_get('always_populate_raw_post_data'))
215213
);
@@ -222,4 +220,21 @@ private function checkPopulateRawPostSetting()
222220

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

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

Lines changed: 23 additions & 11 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,12 +192,14 @@ 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.
191-
$HTTP_RAW_POST_DATA is deprecated from PHP 5.6 onwards and will stop the installer from running.
199+
$HTTP_RAW_POST_DATA is deprecated from PHP 5.6 onwards and will be removed in PHP 7.0.
200+
This will stop the installer from running.
192201
Please open your php.ini file and set always_populate_raw_post_data to -1.
193-
If you need more help please call your hosting provider.
194-
',
202+
If you need more help please call your hosting provider.',
195203
PHP_VERSION
196204
);
197205
$expected = [
@@ -222,12 +230,14 @@ 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.
227-
$HTTP_RAW_POST_DATA is deprecated from PHP 5.6 onwards and will stop the installer from running.
237+
$HTTP_RAW_POST_DATA is deprecated from PHP 5.6 onwards and will be removed in PHP 7.0.
238+
This will stop the installer from running.
228239
Please open your php.ini file and set always_populate_raw_post_data to -1.
229-
If you need more help please call your hosting provider.
230-
',
240+
If you need more help please call your hosting provider.',
231241
PHP_VERSION
232242
);
233243
$expected = [
@@ -250,12 +260,14 @@ 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.
255-
$HTTP_RAW_POST_DATA is deprecated from PHP 5.6 onwards and will stop the installer from running.
267+
$HTTP_RAW_POST_DATA is deprecated from PHP 5.6 onwards and will be removed in PHP 7.0.
268+
This will stop the installer from running.
256269
Please open your php.ini file and set always_populate_raw_post_data to -1.
257-
If you need more help please call your hosting provider.
258-
',
270+
If you need more help please call your hosting provider.',
259271
PHP_VERSION
260272
);
261273
$expected = [

0 commit comments

Comments
 (0)