From b84c3f0268d0aad8ba6752a536f3f6532dc62983 Mon Sep 17 00:00:00 2001 From: Craig Duncan Date: Mon, 8 Sep 2014 11:44:36 +0100 Subject: [PATCH 1/2] Don't display the dev warning time when running self-update Use the Application::find() method to resolve the command name, as Application::getCommandName() only returns whatever was entered as the first argument. If the user only entered enough of the command to be unambiguous (eg self-up) then the warning would still show By calling Application::find() we ensure that if we are going to run the self-update command then we will not show the warning, no matter what the user entered --- src/Composer/Console/Application.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index 4ecb8b1a3..e0037f655 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -94,9 +94,17 @@ class Application extends BaseApplication $output->writeln('Composer only officially supports PHP 5.3.2 and above, you will most likely encounter problems with your PHP '.PHP_VERSION.', upgrading is strongly recommended.'); } - if (defined('COMPOSER_DEV_WARNING_TIME') && $this->getCommandName($input) !== 'self-update' && $this->getCommandName($input) !== 'selfupdate') { - if (time() > COMPOSER_DEV_WARNING_TIME) { - $output->writeln(sprintf('Warning: This development build of composer is over 30 days old. It is recommended to update it by running "%s self-update" to get the latest version.', $_SERVER['PHP_SELF'])); + if (defined('COMPOSER_DEV_WARNING_TIME')) { + $commandName = ''; + if ($name = $this->getCommandName($input)) { + try { + $commandName = $this->find($name)->getName(); + } catch (\InvalidArgumentException $e) {} + } + if ($commandName !== 'self-update' && $commandName !== 'selfupdate') { + if (time() > COMPOSER_DEV_WARNING_TIME) { + $output->writeln(sprintf('Warning: This development build of composer is over 30 days old. It is recommended to update it by running "%s self-update" to get the latest version.', $_SERVER['PHP_SELF'])); + } } } From 647625ddc5b8dbec551cf47756acb919b6f34735 Mon Sep 17 00:00:00 2001 From: Craig Duncan Date: Mon, 8 Sep 2014 19:24:04 +0100 Subject: [PATCH 2/2] Added some tests for the dev version warning --- tests/Composer/Test/ApplicationTest.php | 76 +++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 tests/Composer/Test/ApplicationTest.php diff --git a/tests/Composer/Test/ApplicationTest.php b/tests/Composer/Test/ApplicationTest.php new file mode 100644 index 000000000..c99022671 --- /dev/null +++ b/tests/Composer/Test/ApplicationTest.php @@ -0,0 +1,76 @@ + + * Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Composer\Test; + +use Composer\Console\Application; +use Composer\TestCase; + +class ApplicationTest extends TestCase +{ + public function testDevWarning() + { + $application = new Application; + + $inputMock = $this->getMock('Symfony\Component\Console\Input\InputInterface'); + $outputMock = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); + + $inputMock->expects($this->once()) + ->method('getFirstArgument') + ->will($this->returnValue('list')); + + $outputMock->expects($this->once()) + ->method("writeln") + ->with($this->equalTo(sprintf('Warning: This development build of composer is over 30 days old. It is recommended to update it by running "%s self-update" to get the latest version.', $_SERVER['PHP_SELF']))); + + if (!defined('COMPOSER_DEV_WARNING_TIME')) { + define('COMPOSER_DEV_WARNING_TIME', time() - 1); + } + + $this->setExpectedException('RuntimeException'); + $application->doRun($inputMock, $outputMock); + } + + public function ensureNoDevWarning($command) + { + $application = new Application; + + $application->add(new \Composer\Command\SelfUpdateCommand); + + $inputMock = $this->getMock('Symfony\Component\Console\Input\InputInterface'); + $outputMock = $this->getMock('Symfony\Component\Console\Output\OutputInterface'); + + $inputMock->expects($this->once()) + ->method('getFirstArgument') + ->will($this->returnValue($command)); + + $outputMock->expects($this->never()) + ->method("writeln"); + + if (!defined('COMPOSER_DEV_WARNING_TIME')) { + define('COMPOSER_DEV_WARNING_TIME', time() - 1); + } + + $this->setExpectedException('RuntimeException'); + $application->doRun($inputMock, $outputMock); + } + + public function testDevWarningPrevented() + { + $this->ensureNoDevWarning('self-update'); + } + + public function testDevWarningPreventedAlias() + { + $this->ensureNoDevWarning('self-up'); + } +}