2022-02-23 15:58:18 +00:00
< ? php declare ( strict_types = 1 );
2018-10-26 03:12:10 +00:00
/*
* 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\Factory ;
2024-08-22 08:48:56 +00:00
use Composer\Util\Platform ;
2018-10-26 03:12:10 +00:00
class FactoryTest extends TestCase
{
2024-08-22 08:48:56 +00:00
public function tearDown () : void
{
parent :: tearDown ();
Platform :: clearEnv ( 'COMPOSER' );
}
2018-10-26 03:12:10 +00:00
/**
* @ group TLS
*/
2022-02-18 09:38:54 +00:00
public function testDefaultValuesAreAsExpected () : void
2018-10-26 03:12:10 +00:00
{
$ioMock = $this -> getMockBuilder ( 'Composer\IO\IOInterface' ) -> getMock ();
$ioMock -> expects ( $this -> once ())
2018-10-26 03:17:38 +00:00
-> method ( " writeError " )
-> with ( $this -> equalTo ( '<warning>You are running Composer with SSL/TLS protection disabled.</warning>' ));
2018-10-26 03:12:10 +00:00
$config = $this
-> getMockBuilder ( 'Composer\Config' )
-> getMock ();
$config -> method ( 'get' )
-> with ( $this -> equalTo ( 'disable-tls' ))
-> will ( $this -> returnValue ( true ));
2018-11-12 15:19:06 +00:00
Factory :: createHttpDownloader ( $ioMock , $config );
2018-10-26 03:12:10 +00:00
}
2024-08-22 08:48:56 +00:00
public function testGetComposerJsonPath () : void
{
self :: assertSame ( './composer.json' , Factory :: getComposerFile ());
}
public function testGetComposerJsonPathFailsIfDir () : void
{
Platform :: putEnv ( 'COMPOSER' , __DIR__ );
self :: expectException ( 'RuntimeException' );
self :: expectExceptionMessage ( 'The COMPOSER environment variable is set to ' . __DIR__ . ' which is a directory, this variable should point to a composer.json or be left unset.' );
Factory :: getComposerFile ();
}
public function testGetComposerJsonPathFromEnv () : void
{
Platform :: putEnv ( 'COMPOSER' , ' foo.json ' );
self :: assertSame ( 'foo.json' , Factory :: getComposerFile ());
}
2018-10-26 03:12:10 +00:00
}