2022-02-23 15:58:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2020-01-30 12:38:53 +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\Command;
|
|
|
|
|
|
|
|
use Composer\Composer;
|
|
|
|
use Composer\Config;
|
|
|
|
use Composer\Factory;
|
2023-08-31 11:46:43 +00:00
|
|
|
use Composer\Package\RootPackage;
|
2020-01-30 12:38:53 +00:00
|
|
|
use Composer\Test\TestCase;
|
2022-02-22 15:47:09 +00:00
|
|
|
use Composer\Util\Platform;
|
2020-01-30 12:38:53 +00:00
|
|
|
use Symfony\Component\Console\Input\ArrayInput;
|
2023-08-31 11:46:43 +00:00
|
|
|
use Composer\Repository\RepositoryManager;
|
|
|
|
use Composer\Repository\InstalledRepositoryInterface;
|
|
|
|
use Composer\Package\Archiver\ArchiveManager;
|
|
|
|
use Composer\Command\ArchiveCommand;
|
|
|
|
use Composer\EventDispatcher\EventDispatcher;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
2020-01-30 12:38:53 +00:00
|
|
|
|
|
|
|
class ArchiveCommandTest extends TestCase
|
|
|
|
{
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testUsesConfigFromComposerObject(): void
|
2020-01-30 12:38:53 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
$input = new ArrayInput([]);
|
2020-01-30 12:38:53 +00:00
|
|
|
|
|
|
|
$output = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$ed = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
|
|
|
|
$composer = new Composer;
|
|
|
|
$config = new Config;
|
2022-08-17 12:20:07 +00:00
|
|
|
$config->merge(['config' => ['archive-format' => 'zip']]);
|
2020-01-30 12:38:53 +00:00
|
|
|
$composer->setConfig($config);
|
|
|
|
|
|
|
|
$manager = $this->getMockBuilder('Composer\Package\Archiver\ArchiveManager')
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
|
|
|
|
$package = $this->getMockBuilder('Composer\Package\RootPackageInterface')
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$manager->expects($this->once())->method('archive')
|
2022-02-22 15:47:09 +00:00
|
|
|
->with($package, 'zip', '.', null, false)->willReturn(Platform::getCwd());
|
2020-01-30 12:38:53 +00:00
|
|
|
|
|
|
|
$composer->setArchiveManager($manager);
|
|
|
|
$composer->setEventDispatcher($ed);
|
|
|
|
$composer->setPackage($package);
|
|
|
|
|
|
|
|
$command = $this->getMockBuilder('Composer\Command\ArchiveCommand')
|
2022-08-17 12:20:07 +00:00
|
|
|
->onlyMethods([
|
2020-01-30 12:38:53 +00:00
|
|
|
'mergeApplicationDefinition',
|
|
|
|
'getSynopsis',
|
|
|
|
'initialize',
|
2022-02-16 12:24:57 +00:00
|
|
|
'tryComposer',
|
|
|
|
'requireComposer',
|
2022-08-17 12:20:07 +00:00
|
|
|
])->getMock();
|
2022-02-16 12:24:57 +00:00
|
|
|
$command->expects($this->atLeastOnce())->method('tryComposer')
|
|
|
|
->willReturn($composer);
|
|
|
|
$command->expects($this->atLeastOnce())->method('requireComposer')
|
2020-01-30 12:38:53 +00:00
|
|
|
->willReturn($composer);
|
|
|
|
|
|
|
|
$command->run($input, $output);
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testUsesConfigFromFactoryWhenComposerIsNotDefined(): void
|
2020-01-30 12:38:53 +00:00
|
|
|
{
|
2022-08-17 12:20:07 +00:00
|
|
|
$input = new ArrayInput([]);
|
2020-01-30 12:38:53 +00:00
|
|
|
|
|
|
|
$output = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')
|
|
|
|
->getMock();
|
|
|
|
$config = Factory::createConfig();
|
|
|
|
|
|
|
|
$command = $this->getMockBuilder('Composer\Command\ArchiveCommand')
|
2022-08-17 12:20:07 +00:00
|
|
|
->onlyMethods([
|
2020-01-30 12:38:53 +00:00
|
|
|
'mergeApplicationDefinition',
|
|
|
|
'getSynopsis',
|
|
|
|
'initialize',
|
2022-02-16 12:24:57 +00:00
|
|
|
'tryComposer',
|
2020-01-30 12:38:53 +00:00
|
|
|
'archive',
|
2022-08-17 12:20:07 +00:00
|
|
|
])->getMock();
|
2022-02-16 12:24:57 +00:00
|
|
|
$command->expects($this->once())->method('tryComposer')
|
2020-02-11 09:14:50 +00:00
|
|
|
->willReturn(null);
|
|
|
|
$command->expects($this->once())->method('archive')
|
2020-01-30 12:38:53 +00:00
|
|
|
->with(
|
2020-02-11 09:14:50 +00:00
|
|
|
$this->isInstanceOf('Composer\IO\IOInterface'),
|
2020-01-30 12:38:53 +00:00
|
|
|
$config,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
'tar',
|
|
|
|
'.',
|
|
|
|
null,
|
|
|
|
false,
|
|
|
|
null
|
2020-02-11 10:41:31 +00:00
|
|
|
)->willReturn(0);
|
2020-01-30 12:38:53 +00:00
|
|
|
|
2020-02-11 10:41:31 +00:00
|
|
|
$this->assertEquals(0, $command->run($input, $output));
|
2020-01-30 12:38:53 +00:00
|
|
|
}
|
2023-08-31 11:46:43 +00:00
|
|
|
|
|
|
|
public function testUsesConfigFromComposerObjectWithPackageName(): void
|
|
|
|
{
|
|
|
|
$input = new ArrayInput([
|
|
|
|
'package' => 'foo/bar',
|
|
|
|
]);
|
|
|
|
|
|
|
|
$output = $this->getMockBuilder(OutputInterface::class)
|
|
|
|
->getMock();
|
|
|
|
|
|
|
|
$eventDispatcher = $this->getMockBuilder(EventDispatcher::class)
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
|
|
|
|
$composer = new Composer;
|
|
|
|
$config = new Config;
|
|
|
|
$config->merge(['config' => ['archive-format' => 'zip']]);
|
|
|
|
$composer->setConfig($config);
|
|
|
|
|
|
|
|
$manager = $this->getMockBuilder(ArchiveManager::class)
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
|
|
|
|
$package = new RootPackage('foo/bar', '1.0.0', '1.0');
|
|
|
|
|
|
|
|
$installedRepository = $this->getMockBuilder(InstalledRepositoryInterface::class)
|
|
|
|
->getMock();
|
|
|
|
$installedRepository->expects($this->once())->method('loadPackages')
|
|
|
|
->willReturn(['packages' => [$package], 'namesFound' => ['foo/bar']]);
|
|
|
|
|
|
|
|
$repositoryManager = $this->getMockBuilder(RepositoryManager::class)
|
|
|
|
->disableOriginalConstructor()->getMock();
|
|
|
|
$repositoryManager->expects($this->once())->method('getLocalRepository')
|
|
|
|
->willReturn($installedRepository);
|
|
|
|
$repositoryManager->expects($this->once())->method('getRepositories')
|
|
|
|
->willReturn([]);
|
|
|
|
|
|
|
|
$manager->expects($this->once())->method('archive')
|
|
|
|
->with($package, 'zip', '.', null, false)->willReturn(Platform::getCwd());
|
|
|
|
|
|
|
|
$composer->setArchiveManager($manager);
|
|
|
|
$composer->setEventDispatcher($eventDispatcher);
|
|
|
|
$composer->setPackage($package);
|
|
|
|
$composer->setRepositoryManager($repositoryManager);
|
|
|
|
|
|
|
|
$command = $this->getMockBuilder(ArchiveCommand::class)
|
|
|
|
->onlyMethods([
|
|
|
|
'mergeApplicationDefinition',
|
|
|
|
'getSynopsis',
|
|
|
|
'initialize',
|
|
|
|
'tryComposer',
|
|
|
|
'requireComposer',
|
|
|
|
])->getMock();
|
|
|
|
$command->expects($this->atLeastOnce())->method('tryComposer')
|
|
|
|
->willReturn($composer);
|
|
|
|
|
|
|
|
$command->run($input, $output);
|
|
|
|
}
|
2020-01-30 12:38:53 +00:00
|
|
|
}
|