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 ;
2021-04-13 07:59:06 +00:00
use Composer\XdebugHandler\XdebugHandler ;
2021-12-09 16:09:07 +00:00
use Symfony\Component\Console\Output\BufferedOutput ;
2014-09-08 18:24:04 +00:00
class ApplicationTest extends TestCase
{
2021-12-09 16:09:07 +00:00
protected function tearDown () : void
2021-06-03 08:17:54 +00:00
{
parent :: tearDown ();
putenv ( 'COMPOSER_NO_INTERACTION' );
}
2022-02-18 09:38:54 +00:00
public function testDevWarning () : void
2014-09-08 18:24:04 +00:00
{
$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
2019-08-29 13:09:26 +00:00
putenv ( 'COMPOSER_NO_INTERACTION=1' );
2021-12-09 16:09:07 +00:00
$inputMock -> expects ( $this -> any ())
2021-12-20 13:23:35 +00:00
-> method ( 'hasParameterOption' )
2021-12-09 16:09:07 +00:00
-> willReturnCallback ( function ( $opt ) : bool {
switch ( $opt ) {
case '--no-plugins' :
return true ;
case '--no-scripts' :
return false ;
case '--no-cache' :
return false ;
}
return false ;
});
$inputMock -> expects ( $this -> once ())
2019-08-29 13:23:45 +00:00
-> method ( 'setInteractive' )
-> with ( $this -> equalTo ( false ));
2021-12-09 16:09:07 +00:00
$inputMock -> expects ( $this -> once ())
2016-05-05 23:28:45 +00:00
-> 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' )
2022-02-16 12:24:57 +00:00
-> will ( $this -> returnValue ( 'about' ));
2014-09-08 18:24:04 +00:00
2021-12-09 16:09:07 +00:00
$output = new BufferedOutput ();
$expectedOutput = '' ;
2016-04-18 21:17:04 +00:00
2021-04-13 07:59:06 +00:00
if ( XdebugHandler :: isXdebugActive ()) {
2021-12-09 16:09:07 +00:00
$expectedOutput .= '<warning>Composer is operating slower than normal because you have Xdebug enabled. See https://getcomposer.org/xdebug</warning>' . PHP_EOL ;
2015-11-19 17:36:52 +00:00
}
2021-12-09 16:09:07 +00:00
$expectedOutput .= 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' ]) . PHP_EOL ;
2014-09-08 18:24:04 +00:00
if ( ! defined ( 'COMPOSER_DEV_WARNING_TIME' )) {
define ( 'COMPOSER_DEV_WARNING_TIME' , time () - 1 );
}
2021-12-09 16:09:07 +00:00
$application -> doRun ( $inputMock , $output );
$this -> assertStringContainsString ( $expectedOutput , $output -> fetch ());
2014-09-08 18:24:04 +00:00
}
2021-11-02 13:32:09 +00:00
/**
* @ param string $command
* @ return void
*/
2022-02-18 09:38:54 +00:00
public function ensureNoDevWarning ( $command ) : void
2014-09-08 18:24:04 +00:00
{
$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
2019-08-29 13:09:26 +00:00
putenv ( 'COMPOSER_NO_INTERACTION=1' );
2021-12-09 16:09:07 +00:00
$inputMock -> expects ( $this -> any ())
2021-12-20 13:23:35 +00:00
-> method ( 'hasParameterOption' )
2021-12-09 16:09:07 +00:00
-> willReturnCallback ( function ( $opt ) : bool {
switch ( $opt ) {
case '--no-plugins' :
return true ;
case '--no-scripts' :
return false ;
case '--no-cache' :
return false ;
}
return false ;
});
$inputMock -> expects ( $this -> once ())
2019-08-29 13:23:45 +00:00
-> method ( 'setInteractive' )
-> with ( $this -> equalTo ( false ));
2021-12-09 16:09:07 +00:00
$inputMock -> expects ( $this -> once ())
2016-05-05 23:28:45 +00:00
-> 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' )
2022-02-16 12:24:57 +00:00
-> will ( $this -> returnValue ( 'about' ));
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 );
}
2022-02-18 09:38:54 +00:00
public function testDevWarningPrevented () : void
2014-09-08 18:24:04 +00:00
{
$this -> ensureNoDevWarning ( 'self-update' );
}
2022-02-18 09:38:54 +00:00
public function testDevWarningPreventedAlias () : void
2014-09-08 18:24:04 +00:00
{
$this -> ensureNoDevWarning ( 'self-up' );
}
}