Add test for `ArchiveCommand` with package name (#11551)
* test(ArchiveCommand): Add test for ArchiveCommand with package name * fix : using explicit variable name for eventDispatcher Mock --------- Co-authored-by: Damien Carrier <damien.carrier@alximy.io>pull/11616/head
parent
e1587cf698
commit
e0abc40ded
|
@ -15,9 +15,16 @@ namespace Composer\Test\Command;
|
||||||
use Composer\Composer;
|
use Composer\Composer;
|
||||||
use Composer\Config;
|
use Composer\Config;
|
||||||
use Composer\Factory;
|
use Composer\Factory;
|
||||||
|
use Composer\Package\RootPackage;
|
||||||
use Composer\Test\TestCase;
|
use Composer\Test\TestCase;
|
||||||
use Composer\Util\Platform;
|
use Composer\Util\Platform;
|
||||||
use Symfony\Component\Console\Input\ArrayInput;
|
use Symfony\Component\Console\Input\ArrayInput;
|
||||||
|
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;
|
||||||
|
|
||||||
class ArchiveCommandTest extends TestCase
|
class ArchiveCommandTest extends TestCase
|
||||||
{
|
{
|
||||||
|
@ -98,4 +105,60 @@ class ArchiveCommandTest extends TestCase
|
||||||
|
|
||||||
$this->assertEquals(0, $command->run($input, $output));
|
$this->assertEquals(0, $command->run($input, $output));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue