Skip to content
This repository was archived by the owner on Nov 14, 2019. It is now read-only.

Commit d8b490c

Browse files
committed
feature #257 Check that the system has the PHP version required by Symfony (javiereguiluz)
This PR was squashed before being merged into the 1.0-dev branch (closes #257). Discussion ---------- Check that the system has the PHP version required by Symfony This fixes #239. Commits ------- e7b3fc3 Check that the system has the PHP version required by Symfony
2 parents ce0acc8 + e7b3fc3 commit d8b490c

File tree

2 files changed

+68
-57
lines changed

2 files changed

+68
-57
lines changed

src/Symfony/Installer/NewCommand.php

Lines changed: 43 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -110,89 +110,76 @@ protected function execute(InputInterface $input, OutputInterface $output)
110110
*/
111111
protected function checkSymfonyVersionIsInstallable()
112112
{
113-
// 'latest' is a special version name that refers to the latest stable version
114-
// 'lts' is a special version name that refers to the current long term support version
115-
if (in_array($this->version, array('latest', 'lts'))) {
116-
return $this;
113+
// validate the given version syntax
114+
if (!preg_match('/^latest|lts|[2-9]\.\d(?:\.\d{1,2})?(?:-(?:dev|BETA\d*|RC\d*))?$/i', $this->version)) {
115+
throw new \RuntimeException(sprintf(
116+
"The Symfony version can be a branch number (e.g. 2.8), a full version\n".
117+
"number (e.g. 3.1.4), a special word ('latest' or 'lts') and a unstable\n".
118+
"version number (e.g. 3.2.0-rc1) but '%s' was given.", $this->version
119+
));
117120
}
118121

119-
// validate semver syntax
120-
if (!preg_match('/^[23]\.\d(?:\.\d{1,2})?(?:-(?:dev|BETA\d*|RC\d*))?$/i', $this->version)) {
121-
throw new \RuntimeException('The Symfony version must be 2.N, 2.N.M, 3.N or 3.N.M (where N and M are positive integers). The special "-dev", "-BETA" and "-RC" versions are also supported.');
122+
// Get the full list of Symfony versions to check if it's installable
123+
$client = $this->getGuzzleClient();
124+
$symfonyVersions = $client->get('http://symfony.com/versions.json')->json();
125+
if (empty($symfonyVersions)) {
126+
throw new \RuntimeException(
127+
"There was a problem while downloading the list of Symfony versions from\n".
128+
"symfony.com. Check that you are online and the following URL is accessible:\n\n".
129+
'http://symfony.com/versions.json'
130+
);
122131
}
123132

124-
if (preg_match('/^[23]\.\d$/', $this->version)) {
125-
// Check if we have a minor version in order to retrieve the last patch from symfony.com
126-
127-
$client = $this->getGuzzleClient();
128-
$versionsList = $client->get('http://symfony.com/versions.json')->json();
129-
130-
if ($versionsList && isset($versionsList[$this->version])) {
131-
// Get the latest patch of the minor version the user asked
132-
$this->version = $versionsList[$this->version];
133-
} elseif ($versionsList && !isset($versionsList[$this->version])) {
133+
// if a branch number is used, transform it into a real version number
134+
if (preg_match('/^[2-9]\.\d$/', $this->version)) {
135+
if (!isset($symfonyVersions[$this->version])) {
134136
throw new \RuntimeException(sprintf(
135137
"The selected branch (%s) does not exist, or is not maintained.\n".
136138
"To solve this issue, install Symfony with the latest stable release:\n\n".
137-
'%s %s %s',
138-
$this->version,
139-
$_SERVER['PHP_SELF'],
140-
$this->getName(),
141-
$this->projectDir
139+
'%s %s %s', $this->version, $_SERVER['PHP_SELF'], $this->getName(), $this->projectDir
142140
));
143141
}
142+
143+
$this->version = $symfonyVersions[$this->version];
144144
}
145145

146-
// 2.0, 2.1, 2.2 and 2.4 cannot be installed because they are unmaintained
147-
if (preg_match('/^2\.[0124]\.\d{1,2}$/', $this->version)) {
148-
throw new \RuntimeException(sprintf(
149-
"The selected version (%s) cannot be installed because it belongs\n".
150-
"to an unmaintained Symfony branch which is not compatible with this installer.\n".
151-
"To solve this issue install Symfony manually executing the following command:\n\n".
152-
'composer create-project symfony/framework-standard-edition %s %s',
153-
$this->version, $this->projectDir, $this->version
154-
));
146+
// if a special version name is used, transform it into a real version number
147+
if (in_array($this->version, array('latest', 'lts'))) {
148+
$this->version = $symfonyVersions[$this->version];
155149
}
156150

157-
// 2.3 can be installed starting from version 2.3.21 (inclusive)
158-
if (preg_match('/^2\.3\.\d{1,2}$/', $this->version) && version_compare($this->version, '2.3.21', '<')) {
159-
throw new \RuntimeException(sprintf(
160-
"The selected version (%s) cannot be installed because this installer\n".
161-
"is compatible with Symfony 2.3 versions starting from 2.3.21.\n".
162-
"To solve this issue install Symfony manually executing the following command:\n\n".
163-
'composer create-project symfony/framework-standard-edition %s %s',
164-
$this->version, $this->projectDir, $this->version
165-
));
151+
// versions are case-sensitive in the download server (3.1.0-rc1 must be 3.1.0-RC1)
152+
if ($isUnstableVersion = preg_match('/^.*\-(BETA|RC)\d*$/i', $this->version)) {
153+
$this->version = strtoupper($this->version);
166154
}
167155

168-
// 2.5 can be installed starting from version 2.5.6 (inclusive)
169-
if (preg_match('/^2\.5\.\d{1,2}$/', $this->version) && version_compare($this->version, '2.5.6', '<')) {
156+
$isNonInstallable = in_array($this->version, $symfonyVersions['non_installable']);
157+
$isInstallable = in_array($this->version, $symfonyVersions['installable']);
158+
159+
// installable and non-installable versions are explicitly declared in the
160+
// list of versions; there is an edge-case: unstable versions are not listed
161+
// and they are generally installable (e.g. 3.1.0-RC1)
162+
if ($isNonInstallable || (!$isInstallable && !$isUnstableVersion)) {
170163
throw new \RuntimeException(sprintf(
171-
"The selected version (%s) cannot be installed because this installer\n".
172-
"is compatible with Symfony 2.5 versions starting from 2.5.6.\n".
164+
"The selected version (%s) cannot be installed because it is not compatible\n".
165+
"with this installer or because it hasn't been published as a package yet.\n".
173166
"To solve this issue install Symfony manually executing the following command:\n\n".
174167
'composer create-project symfony/framework-standard-edition %s %s',
175168
$this->version, $this->projectDir, $this->version
176169
));
177170
}
178171

179-
// "-dev" versions are not supported because Symfony doesn't provide packages for them
180-
if (preg_match('/^.*\-dev$/i', $this->version)) {
172+
// check that the system has the PHP version required by the Symfony version to be installed
173+
if (version_compare($this->version, '3.0.0', '>=') && version_compare(phpversion(), '5.5.9', '<')) {
181174
throw new \RuntimeException(sprintf(
182-
"The selected version (%s) cannot be installed because it hasn't\n".
183-
"been published as a package yet. Read the following article for\n".
184-
"an alternative installation method:\n\n".
185-
"> How to Install or Upgrade to the Latest, Unreleased Symfony Version\n".
186-
'> http://symfony.com/doc/current/cookbook/install/unstable_versions.html',
187-
$this->version
175+
"The selected version (%s) cannot be installed because it requires\n".
176+
"PHP 5.5.9 or higher and your system has PHP %s installed.\n",
177+
$this->version, phpversion()
188178
));
189179
}
190180

191-
// warn the user when downloading an unstable version
192-
if (preg_match('/^.*\-(BETA|RC)\d*$/i', $this->version)) {
181+
if ($isUnstableVersion) {
193182
$this->output->writeln("\n <bg=red> WARNING </> You are downloading an unstable Symfony version.");
194-
// versions provided by the download server are case sensitive
195-
$this->version = strtoupper($this->version);
196183
}
197184

198185
return $this;

tests/Symfony/Installer/Tests/IntegrationTest.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,12 @@ public function testDemoApplicationInstallation()
6363
/**
6464
* @dataProvider provideSymfonyInstallationData
6565
*/
66-
public function testSymfonyInstallation($versionToInstall, $messageRegexp, $versionRegexp)
66+
public function testSymfonyInstallation($versionToInstall, $messageRegexp, $versionRegexp, $requiredPhpVersion)
6767
{
68+
if (version_compare(phpversion(), $requiredPhpVersion, '<')) {
69+
$this->markTestSkipped(sprintf('This test requires PHP %s or higher.', $requiredPhpVersion));
70+
}
71+
6872
$projectDir = sprintf('%s/my_test_project', sys_get_temp_dir());
6973
$this->fs->remove($projectDir);
7074

@@ -92,6 +96,19 @@ public function testSymfonyInstallation($versionToInstall, $messageRegexp, $vers
9296
);
9397
}
9498

99+
/**
100+
* @expectedException \RuntimeException
101+
* @expectedExceptionMessageRegExp /.+The selected version \(3.0.0\) cannot be installed because it requires.+PHP 5.5.9 or higher and your system has PHP 5.4.* installed.+/s
102+
*/
103+
public function testSymfonyRequiresNewerPhpVersion()
104+
{
105+
if (PHP_VERSION_ID >= 50500) {
106+
$this->markTestSkipped('This test requires PHP 5.4 or lower.');
107+
}
108+
109+
$this->runCommand(sprintf('php %s/symfony.phar new my_test_project 3.0.0', $this->rootDir));
110+
}
111+
95112
public function testSymfonyInstallationInCurrentDirectory()
96113
{
97114
$projectDir = sprintf('%s/my_test_project', sys_get_temp_dir());
@@ -137,42 +154,49 @@ public function provideSymfonyInstallationData()
137154
'',
138155
'/.*Symfony 3\.1\.\d+ was successfully installed.*/',
139156
'/Symfony version 3\.1\.\d+(-DEV)? - app\/dev\/debug/',
157+
'5.5.9',
140158
),
141159

142160
array(
143161
'3.0',
144162
'/.*Symfony 3\.0\.\d+ was successfully installed.*/',
145163
'/Symfony version 3\.0\.\d+(-DEV)? - app\/dev\/debug/',
164+
'5.5.9',
146165
),
147166

148167
array(
149168
'lts',
150169
'/.*Symfony 2\.8\.\d+ was successfully installed.*/',
151170
'/Symfony version 2\.8\.\d+(-DEV)? - app\/dev\/debug/',
171+
'5.3.9',
152172
),
153173

154174
array(
155175
'2.3',
156176
'/.*Symfony 2\.3\.\d+ was successfully installed.*/',
157177
'/Symfony version 2\.3\.\d+ - app\/dev\/debug/',
178+
'5.3.9',
158179
),
159180

160181
array(
161182
'2.5.6',
162183
'/.*Symfony 2\.5\.6 was successfully installed.*/',
163184
'/Symfony version 2\.5\.6 - app\/dev\/debug/',
185+
'5.3.9',
164186
),
165187

166188
array(
167189
'2.7.0-BETA1',
168190
'/.*Symfony 2\.7\.0\-BETA1 was successfully installed.*/',
169191
'/Symfony version 2\.7\.0\-BETA1 - app\/dev\/debug/',
192+
'5.3.9',
170193
),
171194

172195
array(
173196
'3.0.0-BETA1',
174197
'/.*Symfony dev\-master was successfully installed.*/',
175198
'/Symfony version 3\.0\.0\-BETA1 - app\/dev\/debug/',
199+
'5.5.9',
176200
),
177201
);
178202
}

0 commit comments

Comments
 (0)