2014-09-08 18:24:04 +00:00
< ? php
/*
* This file is part of Composer .
*
* ( c ) Nils Adermann < naderman @ naderman . de >
* Jordi Boggiano < j . boggiano @ seld . be >
*
* 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 ;
2018-11-12 14:23:32 +00:00
use Composer\Test\TestCase ;
2016-01-28 13:41:19 +00:00
use Symfony\Component\Console\Output\OutputInterface ;
2014-09-08 18:24:04 +00:00
class ApplicationTest extends TestCase
{
public function testDevWarning ()
{
$application = new Application ;
2018-04-12 08:24:56 +00:00
$inputMock = $this -> getMockBuilder ( 'Symfony\Component\Console\Input\InputInterface' ) -> getMock ();
$outputMock = $this -> getMockBuilder ( 'Symfony\Component\Console\Output\OutputInterface' ) -> getMock ();
2014-09-08 18:24:04 +00:00
2016-05-05 23:28:45 +00:00
$index = 0 ;
2016-07-12 16:12:50 +00:00
$inputMock -> expects ( $this -> at ( $index ++ ))
-> method ( 'hasParameterOption' )
-> with ( $this -> equalTo ( '--no-plugins' ))
-> will ( $this -> returnValue ( true ));
2016-05-05 23:28:45 +00:00
$inputMock -> expects ( $this -> at ( $index ++ ))
-> method ( 'getParameterOption' )
-> with ( $this -> equalTo ( array ( '--working-dir' , '-d' )))
-> will ( $this -> returnValue ( false ));
2016-05-03 06:26:14 +00:00
2017-08-08 08:43:26 +00:00
$inputMock -> expects ( $this -> any ())
2014-09-08 18:24:04 +00:00
-> method ( 'getFirstArgument' )
2017-08-08 08:43:26 +00:00
-> will ( $this -> returnValue ( 'show' ));
2014-09-08 18:24:04 +00:00
2015-11-19 17:36:52 +00:00
$index = 0 ;
2016-04-18 21:17:04 +00:00
$outputMock -> expects ( $this -> at ( $index ++ ))
-> method ( " writeError " );
2015-11-19 17:36:52 +00:00
if ( extension_loaded ( 'xdebug' )) {
2016-01-28 13:41:19 +00:00
$outputMock -> expects ( $this -> at ( $index ++ ))
-> method ( " getVerbosity " )
-> willReturn ( OutputInterface :: VERBOSITY_NORMAL );
2015-11-19 17:36:52 +00:00
$outputMock -> expects ( $this -> at ( $index ++ ))
-> method ( " write " )
-> with ( $this -> equalTo ( '<warning>You are running composer with xdebug enabled. This has a major impact on runtime performance. See https://getcomposer.org/xdebug</warning>' ));
}
2016-01-28 13:41:19 +00:00
$outputMock -> expects ( $this -> at ( $index ++ ))
-> method ( " getVerbosity " )
-> willReturn ( OutputInterface :: VERBOSITY_NORMAL );
2015-11-19 17:36:52 +00:00
$outputMock -> expects ( $this -> at ( $index ++ ))
2015-02-06 12:52:44 +00:00
-> method ( " write " )
2015-05-01 10:54:55 +00:00
-> with ( $this -> equalTo ( sprintf ( '<warning>Warning: This development build of composer is over 60 days old. It is recommended to update it by running "%s self-update" to get the latest version.</warning>' , $_SERVER [ 'PHP_SELF' ])));
2014-09-08 18:24:04 +00:00
if ( ! defined ( 'COMPOSER_DEV_WARNING_TIME' )) {
define ( 'COMPOSER_DEV_WARNING_TIME' , time () - 1 );
}
$application -> doRun ( $inputMock , $outputMock );
}
public function ensureNoDevWarning ( $command )
{
$application = new Application ;
$application -> add ( new \Composer\Command\SelfUpdateCommand );
2018-04-12 08:24:56 +00:00
$inputMock = $this -> getMockBuilder ( 'Symfony\Component\Console\Input\InputInterface' ) -> getMock ();
$outputMock = $this -> getMockBuilder ( 'Symfony\Component\Console\Output\OutputInterface' ) -> getMock ();
2014-09-08 18:24:04 +00:00
2016-05-05 23:28:45 +00:00
$index = 0 ;
2016-07-12 16:12:50 +00:00
$inputMock -> expects ( $this -> at ( $index ++ ))
-> method ( 'hasParameterOption' )
-> with ( $this -> equalTo ( '--no-plugins' ))
-> will ( $this -> returnValue ( true ));
2016-05-05 23:28:45 +00:00
$inputMock -> expects ( $this -> at ( $index ++ ))
-> method ( 'getParameterOption' )
-> with ( $this -> equalTo ( array ( '--working-dir' , '-d' )))
-> will ( $this -> returnValue ( false ));
2017-08-08 08:43:26 +00:00
$inputMock -> expects ( $this -> any ())
2014-09-08 18:24:04 +00:00
-> method ( 'getFirstArgument' )
2017-08-08 08:43:26 +00:00
-> will ( $this -> returnValue ( 'show' ));
2016-05-05 23:28:45 +00:00
2014-09-08 18:24:04 +00:00
$outputMock -> expects ( $this -> never ())
-> method ( " writeln " );
if ( ! defined ( 'COMPOSER_DEV_WARNING_TIME' )) {
define ( 'COMPOSER_DEV_WARNING_TIME' , time () - 1 );
}
$application -> doRun ( $inputMock , $outputMock );
}
public function testDevWarningPrevented ()
{
$this -> ensureNoDevWarning ( 'self-update' );
}
public function testDevWarningPreventedAlias ()
{
$this -> ensureNoDevWarning ( 'self-up' );
}
}