From a8dbd0c996244b611333823fd5c5051ad8ce9ef2 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 6 Jun 2016 15:14:04 +0200 Subject: [PATCH 01/19] Check that the system has the PHP version required by Symfony --- src/Symfony/Installer/NewCommand.php | 10 +++++++++- tests/Symfony/Installer/Tests/IntegrationTest.php | 13 +++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Installer/NewCommand.php b/src/Symfony/Installer/NewCommand.php index 048c4aa..525ed2e 100644 --- a/src/Symfony/Installer/NewCommand.php +++ b/src/Symfony/Installer/NewCommand.php @@ -123,7 +123,6 @@ protected function checkSymfonyVersionIsInstallable() if (preg_match('/^[23]\.\d$/', $this->version)) { // Check if we have a minor version in order to retrieve the last patch from symfony.com - $client = $this->getGuzzleClient(); $versionsList = $client->get('http://symfony.com/versions.json')->json(); @@ -188,6 +187,15 @@ protected function checkSymfonyVersionIsInstallable() )); } + // check that the system has the PHP version required by the Symfony version to be installed + if (version_compare($this->version, '3.0.0', '>=') && version_compare(phpversion(), '5.5.9', '<')) { + throw new \RuntimeException(sprintf( + "The selected version (%s) cannot be installed because it requires\n". + "PHP 5.5.9 or higher and your system has PHP %s installed.\n", + $this->version, phpversion() + )); + } + // warn the user when downloading an unstable version if (preg_match('/^.*\-(BETA|RC)\d*$/i', $this->version)) { $this->output->writeln("\n WARNING You are downloading an unstable Symfony version."); diff --git a/tests/Symfony/Installer/Tests/IntegrationTest.php b/tests/Symfony/Installer/Tests/IntegrationTest.php index 27f4160..293f8e0 100644 --- a/tests/Symfony/Installer/Tests/IntegrationTest.php +++ b/tests/Symfony/Installer/Tests/IntegrationTest.php @@ -92,6 +92,19 @@ public function testSymfonyInstallation($versionToInstall, $messageRegexp, $vers ); } + /** + * @expectedException \RuntimeException + * @expectedExceptionMessageRegExp /The selected version \(.+\) cannot be installed because it requires\nPHP 5.5.9 or higher and your system has PHP .+ installed\./ + */ + public function testSymfonyRequiresNewerPhpVersion() + { + if (version_compare(phpversion(), '5.5.0', '>=')) { + $this->markTestSkipped('This test requires PHP 5.4 or lower.'); + } + + $this->runCommand(sprintf('php %s/symfony.phar new . 2.7.5', $this->rootDir)); + } + public function testSymfonyInstallationInCurrentDirectory() { $projectDir = sprintf('%s/my_test_project', sys_get_temp_dir()); From a1c841ab6756f9738bd5f5181c510b6dc4e51a37 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 6 Jun 2016 15:20:10 +0200 Subject: [PATCH 02/19] Fixed a test --- tests/Symfony/Installer/Tests/IntegrationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Symfony/Installer/Tests/IntegrationTest.php b/tests/Symfony/Installer/Tests/IntegrationTest.php index 293f8e0..f5c0a2c 100644 --- a/tests/Symfony/Installer/Tests/IntegrationTest.php +++ b/tests/Symfony/Installer/Tests/IntegrationTest.php @@ -102,7 +102,7 @@ public function testSymfonyRequiresNewerPhpVersion() $this->markTestSkipped('This test requires PHP 5.4 or lower.'); } - $this->runCommand(sprintf('php %s/symfony.phar new . 2.7.5', $this->rootDir)); + $this->runCommand(sprintf('php %s/symfony.phar new my_test_project', $this->rootDir)); } public function testSymfonyInstallationInCurrentDirectory() From fe643ccb24e6d3e35186593bbaf9d911c77f4eea Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 6 Jun 2016 15:32:56 +0200 Subject: [PATCH 03/19] Fixed the exception class thrown --- tests/Symfony/Installer/Tests/IntegrationTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/Symfony/Installer/Tests/IntegrationTest.php b/tests/Symfony/Installer/Tests/IntegrationTest.php index f5c0a2c..9564464 100644 --- a/tests/Symfony/Installer/Tests/IntegrationTest.php +++ b/tests/Symfony/Installer/Tests/IntegrationTest.php @@ -12,6 +12,7 @@ namespace Symfony\Installer\Tests; use Symfony\Component\Console\Command\Command; +use Symfony\Component\Process\Exception\RuntimeException; use Symfony\Component\Process\Process; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Process\Exception\ProcessFailedException; @@ -93,7 +94,7 @@ public function testSymfonyInstallation($versionToInstall, $messageRegexp, $vers } /** - * @expectedException \RuntimeException + * @expectedException RuntimeException * @expectedExceptionMessageRegExp /The selected version \(.+\) cannot be installed because it requires\nPHP 5.5.9 or higher and your system has PHP .+ installed\./ */ public function testSymfonyRequiresNewerPhpVersion() From 7c8ba5891ae3330ac326d12dd70b49057d1b10f2 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 6 Jun 2016 15:52:31 +0200 Subject: [PATCH 04/19] Make sure that the Symfony version can be installed in the system --- tests/Symfony/Installer/Tests/IntegrationTest.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/Symfony/Installer/Tests/IntegrationTest.php b/tests/Symfony/Installer/Tests/IntegrationTest.php index 9564464..90e36e5 100644 --- a/tests/Symfony/Installer/Tests/IntegrationTest.php +++ b/tests/Symfony/Installer/Tests/IntegrationTest.php @@ -64,8 +64,12 @@ public function testDemoApplicationInstallation() /** * @dataProvider provideSymfonyInstallationData */ - public function testSymfonyInstallation($versionToInstall, $messageRegexp, $versionRegexp) + public function testSymfonyInstallation($versionToInstall, $messageRegexp, $versionRegexp, $minPhpVersion) { + if (version_compare(phpversion(), $minPhpVersion, '<')) { + $this->markTestSkipped(sprintf('This test requires PHP %s or higher.', $minPhpVersion)); + } + $projectDir = sprintf('%s/my_test_project', sys_get_temp_dir()); $this->fs->remove($projectDir); @@ -151,42 +155,49 @@ public function provideSymfonyInstallationData() '', '/.*Symfony 3\.1\.\d+ was successfully installed.*/', '/Symfony version 3\.1\.\d+(-DEV)? - app\/dev\/debug/', + '5.5.9', ), array( '3.0', '/.*Symfony 3\.0\.\d+ was successfully installed.*/', '/Symfony version 3\.0\.\d+(-DEV)? - app\/dev\/debug/', + '5.5.9', ), array( 'lts', '/.*Symfony 2\.8\.\d+ was successfully installed.*/', '/Symfony version 2\.8\.\d+(-DEV)? - app\/dev\/debug/', + '5.3.9', ), array( '2.3', '/.*Symfony 2\.3\.\d+ was successfully installed.*/', '/Symfony version 2\.3\.\d+ - app\/dev\/debug/', + '5.3.9', ), array( '2.5.6', '/.*Symfony 2\.5\.6 was successfully installed.*/', '/Symfony version 2\.5\.6 - app\/dev\/debug/', + '5.3.9', ), array( '2.7.0-BETA1', '/.*Symfony 2\.7\.0\-BETA1 was successfully installed.*/', '/Symfony version 2\.7\.0\-BETA1 - app\/dev\/debug/', + '5.3.9', ), array( '3.0.0-BETA1', '/.*Symfony dev\-master was successfully installed.*/', '/Symfony version 3\.0\.0\-BETA1 - app\/dev\/debug/', + '5.5.9', ), ); } From a10d8025f552a5b070ba8daa21cb153d9088ca18 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 6 Jun 2016 15:53:24 +0200 Subject: [PATCH 05/19] Renamed a variable --- tests/Symfony/Installer/Tests/IntegrationTest.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/Symfony/Installer/Tests/IntegrationTest.php b/tests/Symfony/Installer/Tests/IntegrationTest.php index 90e36e5..6b06287 100644 --- a/tests/Symfony/Installer/Tests/IntegrationTest.php +++ b/tests/Symfony/Installer/Tests/IntegrationTest.php @@ -64,10 +64,10 @@ public function testDemoApplicationInstallation() /** * @dataProvider provideSymfonyInstallationData */ - public function testSymfonyInstallation($versionToInstall, $messageRegexp, $versionRegexp, $minPhpVersion) + public function testSymfonyInstallation($versionToInstall, $messageRegexp, $versionRegexp, $requiredPhpVersion) { - if (version_compare(phpversion(), $minPhpVersion, '<')) { - $this->markTestSkipped(sprintf('This test requires PHP %s or higher.', $minPhpVersion)); + if (version_compare(phpversion(), $requiredPhpVersion, '<')) { + $this->markTestSkipped(sprintf('This test requires PHP %s or higher.', $requiredPhpVersion)); } $projectDir = sprintf('%s/my_test_project', sys_get_temp_dir()); From 4d89198df3bdc195dc2dcd037f8ada22bfc824d6 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 6 Jun 2016 16:12:48 +0200 Subject: [PATCH 06/19] Fixed exception message --- tests/Symfony/Installer/Tests/IntegrationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Symfony/Installer/Tests/IntegrationTest.php b/tests/Symfony/Installer/Tests/IntegrationTest.php index 6b06287..031e1bd 100644 --- a/tests/Symfony/Installer/Tests/IntegrationTest.php +++ b/tests/Symfony/Installer/Tests/IntegrationTest.php @@ -99,7 +99,7 @@ public function testSymfonyInstallation($versionToInstall, $messageRegexp, $vers /** * @expectedException RuntimeException - * @expectedExceptionMessageRegExp /The selected version \(.+\) cannot be installed because it requires\nPHP 5.5.9 or higher and your system has PHP .+ installed\./ + * @expectedExceptionMessageRegExp /.+The selected version .+ cannot be installed because it requires.+PHP .+ or higher and your system has PHP .+ installed.+/s */ public function testSymfonyRequiresNewerPhpVersion() { From 96cfb1351e70d8ae36d4ce2e77a3ea883ce6512e Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 6 Jun 2016 16:16:56 +0200 Subject: [PATCH 07/19] Fixed the exception again --- tests/Symfony/Installer/Tests/IntegrationTest.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/Symfony/Installer/Tests/IntegrationTest.php b/tests/Symfony/Installer/Tests/IntegrationTest.php index 031e1bd..367192a 100644 --- a/tests/Symfony/Installer/Tests/IntegrationTest.php +++ b/tests/Symfony/Installer/Tests/IntegrationTest.php @@ -12,7 +12,6 @@ namespace Symfony\Installer\Tests; use Symfony\Component\Console\Command\Command; -use Symfony\Component\Process\Exception\RuntimeException; use Symfony\Component\Process\Process; use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Process\Exception\ProcessFailedException; @@ -98,7 +97,7 @@ public function testSymfonyInstallation($versionToInstall, $messageRegexp, $vers } /** - * @expectedException RuntimeException + * @expectedException \RuntimeException * @expectedExceptionMessageRegExp /.+The selected version .+ cannot be installed because it requires.+PHP .+ or higher and your system has PHP .+ installed.+/s */ public function testSymfonyRequiresNewerPhpVersion() From 23e0b4abe17e5c13114ba90a06aaa4028ae6b0c8 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Sun, 12 Jun 2016 12:49:42 +0200 Subject: [PATCH 08/19] Forced the display of the exception by PHPUnit so we can fix the failing tests --- tests/Symfony/Installer/Tests/IntegrationTest.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/Symfony/Installer/Tests/IntegrationTest.php b/tests/Symfony/Installer/Tests/IntegrationTest.php index 367192a..c3f0304 100644 --- a/tests/Symfony/Installer/Tests/IntegrationTest.php +++ b/tests/Symfony/Installer/Tests/IntegrationTest.php @@ -96,10 +96,7 @@ public function testSymfonyInstallation($versionToInstall, $messageRegexp, $vers ); } - /** - * @expectedException \RuntimeException - * @expectedExceptionMessageRegExp /.+The selected version .+ cannot be installed because it requires.+PHP .+ or higher and your system has PHP .+ installed.+/s - */ + public function testSymfonyRequiresNewerPhpVersion() { if (version_compare(phpversion(), '5.5.0', '>=')) { From e6b7946ac00d9d636129a5833a6a02ca75ad6965 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Sun, 12 Jun 2016 12:55:08 +0200 Subject: [PATCH 09/19] Added a var_dump() to try to solve a hard to debug fail --- src/Symfony/Installer/NewCommand.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Symfony/Installer/NewCommand.php b/src/Symfony/Installer/NewCommand.php index 525ed2e..f51ad4c 100644 --- a/src/Symfony/Installer/NewCommand.php +++ b/src/Symfony/Installer/NewCommand.php @@ -188,6 +188,7 @@ protected function checkSymfonyVersionIsInstallable() } // check that the system has the PHP version required by the Symfony version to be installed +var_dump("VERSION", $this->version, "PHP version", phpversion()); if (version_compare($this->version, '3.0.0', '>=') && version_compare(phpversion(), '5.5.9', '<')) { throw new \RuntimeException(sprintf( "The selected version (%s) cannot be installed because it requires\n". From 1c5e1e0baff84a0af09e40517269072c557bbdf6 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Sun, 12 Jun 2016 12:58:54 +0200 Subject: [PATCH 10/19] Remove the previous symfony.phar if it exists --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index ed70733..865e36a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,6 +21,7 @@ before_install: - curl -LSs https://box-project.github.io/box2/installer.php | php - mv box.phar box - chmod 755 box + - rm -f symfony.phar install: - composer install From 972bf2304147c8b55f4da93b5e38d816de7d5b60 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Sun, 12 Jun 2016 13:05:07 +0200 Subject: [PATCH 11/19] Reverted the previous changes --- .travis.yml | 1 - src/Symfony/Installer/NewCommand.php | 1 - tests/Symfony/Installer/Tests/IntegrationTest.php | 7 +++++-- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 865e36a..ed70733 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,6 @@ before_install: - curl -LSs https://box-project.github.io/box2/installer.php | php - mv box.phar box - chmod 755 box - - rm -f symfony.phar install: - composer install diff --git a/src/Symfony/Installer/NewCommand.php b/src/Symfony/Installer/NewCommand.php index f51ad4c..525ed2e 100644 --- a/src/Symfony/Installer/NewCommand.php +++ b/src/Symfony/Installer/NewCommand.php @@ -188,7 +188,6 @@ protected function checkSymfonyVersionIsInstallable() } // check that the system has the PHP version required by the Symfony version to be installed -var_dump("VERSION", $this->version, "PHP version", phpversion()); if (version_compare($this->version, '3.0.0', '>=') && version_compare(phpversion(), '5.5.9', '<')) { throw new \RuntimeException(sprintf( "The selected version (%s) cannot be installed because it requires\n". diff --git a/tests/Symfony/Installer/Tests/IntegrationTest.php b/tests/Symfony/Installer/Tests/IntegrationTest.php index c3f0304..13de015 100644 --- a/tests/Symfony/Installer/Tests/IntegrationTest.php +++ b/tests/Symfony/Installer/Tests/IntegrationTest.php @@ -96,14 +96,17 @@ public function testSymfonyInstallation($versionToInstall, $messageRegexp, $vers ); } - + /** + * @expectedException \RuntimeException + * @expectedExceptionMessageRegExp /.+The selected version .+ cannot be installed because it requires.+PHP .+ or higher and your system has PHP .+ installed.+/s + */ public function testSymfonyRequiresNewerPhpVersion() { if (version_compare(phpversion(), '5.5.0', '>=')) { $this->markTestSkipped('This test requires PHP 5.4 or lower.'); } - $this->runCommand(sprintf('php %s/symfony.phar new my_test_project', $this->rootDir)); + $this->runCommand(sprintf('php %s/symfony.phar new my_test_project 3.0', $this->rootDir)); } public function testSymfonyInstallationInCurrentDirectory() From 2d3bc1b50c544b49320bc199a5c749477d02907f Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Sun, 12 Jun 2016 13:10:02 +0200 Subject: [PATCH 12/19] Made the test more precise --- tests/Symfony/Installer/Tests/IntegrationTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Symfony/Installer/Tests/IntegrationTest.php b/tests/Symfony/Installer/Tests/IntegrationTest.php index 13de015..3429ec0 100644 --- a/tests/Symfony/Installer/Tests/IntegrationTest.php +++ b/tests/Symfony/Installer/Tests/IntegrationTest.php @@ -98,7 +98,7 @@ public function testSymfonyInstallation($versionToInstall, $messageRegexp, $vers /** * @expectedException \RuntimeException - * @expectedExceptionMessageRegExp /.+The selected version .+ cannot be installed because it requires.+PHP .+ or higher and your system has PHP .+ installed.+/s + * @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 */ public function testSymfonyRequiresNewerPhpVersion() { @@ -106,7 +106,7 @@ public function testSymfonyRequiresNewerPhpVersion() $this->markTestSkipped('This test requires PHP 5.4 or lower.'); } - $this->runCommand(sprintf('php %s/symfony.phar new my_test_project 3.0', $this->rootDir)); + $this->runCommand(sprintf('php %s/symfony.phar new my_test_project 3.0.0', $this->rootDir)); } public function testSymfonyInstallationInCurrentDirectory() From fc2cb901a9b40a1ca5453afbad5359bb64b54a1a Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Sun, 12 Jun 2016 13:12:30 +0200 Subject: [PATCH 13/19] Fixed the test exception message --- tests/Symfony/Installer/Tests/IntegrationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Symfony/Installer/Tests/IntegrationTest.php b/tests/Symfony/Installer/Tests/IntegrationTest.php index 3429ec0..5c3e84f 100644 --- a/tests/Symfony/Installer/Tests/IntegrationTest.php +++ b/tests/Symfony/Installer/Tests/IntegrationTest.php @@ -98,7 +98,7 @@ public function testSymfonyInstallation($versionToInstall, $messageRegexp, $vers /** * @expectedException \RuntimeException - * @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 + * @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 */ public function testSymfonyRequiresNewerPhpVersion() { From 50a4468749b8c3e3fdfa2ce49c78cbe65343b13d Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Mon, 13 Jun 2016 16:33:53 +0200 Subject: [PATCH 14/19] Simplified a comparison --- tests/Symfony/Installer/Tests/IntegrationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Symfony/Installer/Tests/IntegrationTest.php b/tests/Symfony/Installer/Tests/IntegrationTest.php index 5c3e84f..0c8d4b8 100644 --- a/tests/Symfony/Installer/Tests/IntegrationTest.php +++ b/tests/Symfony/Installer/Tests/IntegrationTest.php @@ -102,7 +102,7 @@ public function testSymfonyInstallation($versionToInstall, $messageRegexp, $vers */ public function testSymfonyRequiresNewerPhpVersion() { - if (version_compare(phpversion(), '5.5.0', '>=')) { + if (PHP_VERSION_ID >= 55000) { $this->markTestSkipped('This test requires PHP 5.4 or lower.'); } From 8aa9e1bcb4008a0ce356f4b6a1007bfdd1f24608 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 5 Jul 2016 16:36:40 +0200 Subject: [PATCH 15/19] Revamped the checkSymfonyVersionIsInstallable() method --- src/Symfony/Installer/NewCommand.php | 91 ++++++++++------------------ 1 file changed, 33 insertions(+), 58 deletions(-) diff --git a/src/Symfony/Installer/NewCommand.php b/src/Symfony/Installer/NewCommand.php index 525ed2e..28bc218 100644 --- a/src/Symfony/Installer/NewCommand.php +++ b/src/Symfony/Installer/NewCommand.php @@ -110,83 +110,61 @@ protected function execute(InputInterface $input, OutputInterface $output) */ protected function checkSymfonyVersionIsInstallable() { - // 'latest' is a special version name that refers to the latest stable version - // 'lts' is a special version name that refers to the current long term support version - if (in_array($this->version, array('latest', 'lts'))) { - return $this; - } - // validate semver syntax - if (!preg_match('/^[23]\.\d(?:\.\d{1,2})?(?:-(?:dev|BETA\d*|RC\d*))?$/i', $this->version)) { + if (!preg_match('/^[2-9]\.\d(?:\.\d{1,2})?(?:-(?:dev|BETA\d*|RC\d*))?$/i', $this->version)) { 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.'); } - if (preg_match('/^[23]\.\d$/', $this->version)) { - // Check if we have a minor version in order to retrieve the last patch from symfony.com - $client = $this->getGuzzleClient(); - $versionsList = $client->get('http://symfony.com/versions.json')->json(); + // Get the full list of Symfony versions to check if it's installable + $client = $this->getGuzzleClient(); + $symfonyVersions = $client->get('http://symfony.com/versions.json')->json(); + if (empty($symfonyVersions)) { + throw new \RuntimeException( + "There was a problem that prevented to get the list of Symfony versions.\n". + "from symfony.com. Check that you are online and the following URL is acceisble::\n\n". + 'http://symfony.com/versions.json' + ); + } - if ($versionsList && isset($versionsList[$this->version])) { - // Get the latest patch of the minor version the user asked - $this->version = $versionsList[$this->version]; - } elseif ($versionsList && !isset($versionsList[$this->version])) { + // if a branch number is used, transform it into a real version number + if (preg_match('/^[2-9]\.\d$/', $this->version)) { + if (!isset($symfonyVersions[$this->version])) { throw new \RuntimeException(sprintf( "The selected branch (%s) does not exist, or is not maintained.\n". "To solve this issue, install Symfony with the latest stable release:\n\n". - '%s %s %s', - $this->version, - $_SERVER['PHP_SELF'], - $this->getName(), - $this->projectDir + '%s %s %s', $this->version, $_SERVER['PHP_SELF'], $this->getName(), $this->projectDir )); } + + $this->version = $symfonyVersions[$this->version]; } - // 2.0, 2.1, 2.2 and 2.4 cannot be installed because they are unmaintained - if (preg_match('/^2\.[0124]\.\d{1,2}$/', $this->version)) { - throw new \RuntimeException(sprintf( - "The selected version (%s) cannot be installed because it belongs\n". - "to an unmaintained Symfony branch which is not compatible with this installer.\n". - "To solve this issue install Symfony manually executing the following command:\n\n". - 'composer create-project symfony/framework-standard-edition %s %s', - $this->version, $this->projectDir, $this->version - )); + // if a special version name is used, transform it into a real version number + if (in_array($this->version, array('latest', 'lts'))) { + $this->version = $symfonyVersions[$this->version]; } - // 2.3 can be installed starting from version 2.3.21 (inclusive) - if (preg_match('/^2\.3\.\d{1,2}$/', $this->version) && version_compare($this->version, '2.3.21', '<')) { - throw new \RuntimeException(sprintf( - "The selected version (%s) cannot be installed because this installer\n". - "is compatible with Symfony 2.3 versions starting from 2.3.21.\n". - "To solve this issue install Symfony manually executing the following command:\n\n". - 'composer create-project symfony/framework-standard-edition %s %s', - $this->version, $this->projectDir, $this->version - )); + // versions are case-sensitive in the download server (3.1.0-rc1 must be 3.1.0-RC1) + if ($isUnstableVersion = preg_match('/^.*\-(BETA|RC)\d*$/i', $this->version)) { + $this->version = strtoupper($this->version); } - // 2.5 can be installed starting from version 2.5.6 (inclusive) - if (preg_match('/^2\.5\.\d{1,2}$/', $this->version) && version_compare($this->version, '2.5.6', '<')) { + $isNonInstallable = in_array($this->version, $symfonyVersions['non_installable']); + $isInstallable = in_array($this->version, $symfonyVersions['installable']); + + // installable and non-installable versions are explicitly declared in the + // list of versions; there is an edge-case: unstable versions are not listed + // and they are generally installable (e.g. 3.1.0-RC1) + if ($isNonInstallable || (!$isInstallable && !$isUnstableVersion)) { throw new \RuntimeException(sprintf( - "The selected version (%s) cannot be installed because this installer\n". - "is compatible with Symfony 2.5 versions starting from 2.5.6.\n". + "The selected version (%s) cannot be installed because it is not compatible\n". + "with this installer or because it hasn't been published as a package yet.\n". "To solve this issue install Symfony manually executing the following command:\n\n". 'composer create-project symfony/framework-standard-edition %s %s', $this->version, $this->projectDir, $this->version )); } - // "-dev" versions are not supported because Symfony doesn't provide packages for them - if (preg_match('/^.*\-dev$/i', $this->version)) { - throw new \RuntimeException(sprintf( - "The selected version (%s) cannot be installed because it hasn't\n". - "been published as a package yet. Read the following article for\n". - "an alternative installation method:\n\n". - "> How to Install or Upgrade to the Latest, Unreleased Symfony Version\n". - '> http://symfony.com/doc/current/cookbook/install/unstable_versions.html', - $this->version - )); - } - // check that the system has the PHP version required by the Symfony version to be installed if (version_compare($this->version, '3.0.0', '>=') && version_compare(phpversion(), '5.5.9', '<')) { throw new \RuntimeException(sprintf( @@ -196,11 +174,8 @@ protected function checkSymfonyVersionIsInstallable() )); } - // warn the user when downloading an unstable version - if (preg_match('/^.*\-(BETA|RC)\d*$/i', $this->version)) { + if ($isUnstableVersion) { $this->output->writeln("\n WARNING You are downloading an unstable Symfony version."); - // versions provided by the download server are case sensitive - $this->version = strtoupper($this->version); } return $this; From 97587ef95c50a707112a27496ea03eac8fded5d3 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 5 Jul 2016 16:46:02 +0200 Subject: [PATCH 16/19] Fixed typos --- src/Symfony/Installer/NewCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Installer/NewCommand.php b/src/Symfony/Installer/NewCommand.php index 28bc218..221e052 100644 --- a/src/Symfony/Installer/NewCommand.php +++ b/src/Symfony/Installer/NewCommand.php @@ -120,8 +120,8 @@ protected function checkSymfonyVersionIsInstallable() $symfonyVersions = $client->get('http://symfony.com/versions.json')->json(); if (empty($symfonyVersions)) { throw new \RuntimeException( - "There was a problem that prevented to get the list of Symfony versions.\n". - "from symfony.com. Check that you are online and the following URL is acceisble::\n\n". + "There was a problem while downloading the list of Symfony versions from.\n". + "symfony.com. Check that you are online and the following URL is accessible::\n\n". 'http://symfony.com/versions.json' ); } From 127171e3a6dcb228bfafa1c0982fb4fd15b504b3 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 5 Jul 2016 16:52:12 +0200 Subject: [PATCH 17/19] Imrpoved the version validator --- src/Symfony/Installer/NewCommand.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Installer/NewCommand.php b/src/Symfony/Installer/NewCommand.php index 221e052..01fb202 100644 --- a/src/Symfony/Installer/NewCommand.php +++ b/src/Symfony/Installer/NewCommand.php @@ -110,9 +110,13 @@ protected function execute(InputInterface $input, OutputInterface $output) */ protected function checkSymfonyVersionIsInstallable() { - // validate semver syntax - if (!preg_match('/^[2-9]\.\d(?:\.\d{1,2})?(?:-(?:dev|BETA\d*|RC\d*))?$/i', $this->version)) { - 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.'); + // validate the given version syntax + if (!preg_match('/^latest|lts|[2-9]\.\d(?:\.\d{1,2})?(?:-(?:dev|BETA\d*|RC\d*))?$/i', $this->version)) { + throw new \RuntimeException(sprintf( + "The Symfony version can be a branch number (e.g. 2.8), a full version\n". + "number (e.g. 3.1.4), a special word ('latest' or 'lts') and a unstable\n". + "version number (e.g. 3.2.0-rc1) but '%s' was given.", $this->version + )); } // Get the full list of Symfony versions to check if it's installable From 9f79b6765098d055e6c58efd0a38c5f94341f261 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Tue, 5 Jul 2016 16:58:16 +0200 Subject: [PATCH 18/19] Fixed a test condition --- tests/Symfony/Installer/Tests/IntegrationTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Symfony/Installer/Tests/IntegrationTest.php b/tests/Symfony/Installer/Tests/IntegrationTest.php index 0c8d4b8..90a8d5a 100644 --- a/tests/Symfony/Installer/Tests/IntegrationTest.php +++ b/tests/Symfony/Installer/Tests/IntegrationTest.php @@ -102,7 +102,7 @@ public function testSymfonyInstallation($versionToInstall, $messageRegexp, $vers */ public function testSymfonyRequiresNewerPhpVersion() { - if (PHP_VERSION_ID >= 55000) { + if (PHP_VERSION_ID >= 50500) { $this->markTestSkipped('This test requires PHP 5.4 or lower.'); } From bad321a38e7ad65758304bc4bba773cd15098d52 Mon Sep 17 00:00:00 2001 From: Javier Eguiluz Date: Sun, 10 Jul 2016 19:35:24 +0200 Subject: [PATCH 19/19] Fixed some error messages --- src/Symfony/Installer/NewCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Installer/NewCommand.php b/src/Symfony/Installer/NewCommand.php index 01fb202..f6df447 100644 --- a/src/Symfony/Installer/NewCommand.php +++ b/src/Symfony/Installer/NewCommand.php @@ -124,8 +124,8 @@ protected function checkSymfonyVersionIsInstallable() $symfonyVersions = $client->get('http://symfony.com/versions.json')->json(); if (empty($symfonyVersions)) { throw new \RuntimeException( - "There was a problem while downloading the list of Symfony versions from.\n". - "symfony.com. Check that you are online and the following URL is accessible::\n\n". + "There was a problem while downloading the list of Symfony versions from\n". + "symfony.com. Check that you are online and the following URL is accessible:\n\n". 'http://symfony.com/versions.json' ); }