2022-02-23 15:58:18 +00:00
|
|
|
<?php declare(strict_types=1);
|
2013-10-11 23:12:02 +00:00
|
|
|
|
2013-08-15 19:45:42 +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.
|
2013-08-09 19:24:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace Composer\Test\Downloader;
|
|
|
|
|
|
|
|
use Composer\Downloader\PerforceDownloader;
|
|
|
|
use Composer\Config;
|
|
|
|
use Composer\Repository\VcsRepository;
|
2014-03-14 19:45:31 +00:00
|
|
|
use Composer\IO\IOInterface;
|
2018-11-12 14:23:32 +00:00
|
|
|
use Composer\Test\TestCase;
|
2018-11-12 14:34:54 +00:00
|
|
|
use Composer\Factory;
|
2013-08-09 19:24:58 +00:00
|
|
|
|
2013-08-15 19:45:42 +00:00
|
|
|
/**
|
|
|
|
* @author Matt Whittom <Matt.Whittom@veteransunited.com>
|
|
|
|
*/
|
2016-01-21 12:01:55 +00:00
|
|
|
class PerforceDownloaderTest extends TestCase
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2021-10-30 08:21:50 +00:00
|
|
|
/** @var \Composer\Config */
|
2014-03-14 19:45:31 +00:00
|
|
|
protected $config;
|
2021-10-30 08:21:50 +00:00
|
|
|
/** @var \Composer\Downloader\PerforceDownloader */
|
2014-03-14 19:45:31 +00:00
|
|
|
protected $downloader;
|
2021-10-30 08:21:50 +00:00
|
|
|
/** @var \Composer\IO\IOInterface&\PHPUnit\Framework\MockObject\MockObject */
|
2014-03-14 19:45:31 +00:00
|
|
|
protected $io;
|
2021-10-30 08:21:50 +00:00
|
|
|
/** @var \Composer\Package\PackageInterface&\PHPUnit\Framework\MockObject\MockObject */
|
2014-03-14 19:45:31 +00:00
|
|
|
protected $package;
|
2021-10-30 08:21:50 +00:00
|
|
|
/** @var \Composer\Test\Mock\ProcessExecutorMock */
|
2014-03-14 19:45:31 +00:00
|
|
|
protected $processExecutor;
|
2021-10-30 08:21:50 +00:00
|
|
|
/** @var string[] */
|
2014-03-14 19:45:31 +00:00
|
|
|
protected $repoConfig;
|
2021-10-30 08:21:50 +00:00
|
|
|
/** @var \Composer\Repository\VcsRepository&\PHPUnit\Framework\MockObject\MockObject */
|
2014-03-14 19:45:31 +00:00
|
|
|
protected $repository;
|
2021-10-30 08:21:50 +00:00
|
|
|
/** @var string */
|
2014-03-14 19:45:31 +00:00
|
|
|
protected $testPath;
|
2013-08-09 19:24:58 +00:00
|
|
|
|
2021-12-08 16:03:05 +00:00
|
|
|
protected function setUp(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2022-05-11 14:05:35 +00:00
|
|
|
$this->testPath = self::getUniqueTmpDirectory();
|
2017-03-08 14:07:29 +00:00
|
|
|
$this->repoConfig = $this->getRepoConfig();
|
|
|
|
$this->config = $this->getConfig();
|
|
|
|
$this->io = $this->getMockIoInterface();
|
2021-12-09 16:09:07 +00:00
|
|
|
$this->processExecutor = $this->getProcessExecutorMock();
|
2017-03-08 14:07:29 +00:00
|
|
|
$this->repository = $this->getMockRepository($this->repoConfig, $this->io, $this->config);
|
|
|
|
$this->package = $this->getMockPackageInterface($this->repository);
|
|
|
|
$this->downloader = new PerforceDownloader($this->io, $this->config, $this->processExecutor);
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2022-02-22 15:47:09 +00:00
|
|
|
protected function getConfig(array $configOptions = [], bool $useEnvironment = false): Config
|
2014-03-14 19:45:31 +00:00
|
|
|
{
|
2022-02-22 15:47:09 +00:00
|
|
|
return parent::getConfig(array_merge(['home' => $this->testPath], $configOptions), $useEnvironment);
|
2014-03-14 19:45:31 +00:00
|
|
|
}
|
|
|
|
|
2021-10-30 08:21:50 +00:00
|
|
|
/**
|
|
|
|
* @return \Composer\IO\IOInterface&\PHPUnit\Framework\MockObject\MockObject
|
|
|
|
*/
|
2014-03-14 19:45:31 +00:00
|
|
|
protected function getMockIoInterface()
|
|
|
|
{
|
2018-04-12 08:24:56 +00:00
|
|
|
return $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
|
2014-03-14 19:45:31 +00:00
|
|
|
}
|
|
|
|
|
2021-10-30 08:21:50 +00:00
|
|
|
/**
|
|
|
|
* @return \Composer\Package\PackageInterface&\PHPUnit\Framework\MockObject\MockObject
|
|
|
|
*/
|
2014-03-14 19:45:31 +00:00
|
|
|
protected function getMockPackageInterface(VcsRepository $repository)
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2018-04-12 08:24:56 +00:00
|
|
|
$package = $this->getMockBuilder('Composer\Package\PackageInterface')->getMock();
|
2014-03-14 19:45:31 +00:00
|
|
|
$package->expects($this->any())->method('getRepository')->will($this->returnValue($repository));
|
2014-06-10 14:02:44 +00:00
|
|
|
|
2014-03-14 19:45:31 +00:00
|
|
|
return $package;
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
|
2021-10-30 08:21:50 +00:00
|
|
|
/**
|
|
|
|
* @return string[]
|
|
|
|
*/
|
2022-02-18 10:22:01 +00:00
|
|
|
protected function getRepoConfig(): array
|
2014-03-14 19:45:31 +00:00
|
|
|
{
|
2013-10-19 15:55:30 +00:00
|
|
|
return array('url' => 'TEST_URL', 'p4user' => 'TEST_USER');
|
2014-03-14 19:45:31 +00:00
|
|
|
}
|
|
|
|
|
2021-10-30 08:21:50 +00:00
|
|
|
/**
|
|
|
|
* @param string[] $repoConfig
|
|
|
|
* @param \Composer\IO\IOInterface $io
|
|
|
|
* @param \Composer\Config $config
|
|
|
|
* @return \Composer\Repository\VcsRepository&\PHPUnit\Framework\MockObject\MockObject
|
|
|
|
*/
|
2014-03-14 19:45:31 +00:00
|
|
|
protected function getMockRepository(array $repoConfig, IOInterface $io, Config $config)
|
|
|
|
{
|
2018-04-12 08:24:56 +00:00
|
|
|
$repository = $this->getMockBuilder('Composer\Repository\VcsRepository')
|
2021-12-09 21:14:04 +00:00
|
|
|
->onlyMethods(array('getRepoConfig'))
|
2018-11-12 14:34:54 +00:00
|
|
|
->setConstructorArgs(array($repoConfig, $io, $config, Factory::createHttpDownloader($io, $config)))
|
2018-04-12 08:24:56 +00:00
|
|
|
->getMock();
|
2014-03-14 19:45:31 +00:00
|
|
|
$repository->expects($this->any())->method('getRepoConfig')->will($this->returnValue($repoConfig));
|
2014-06-10 14:02:44 +00:00
|
|
|
|
2014-03-14 19:45:31 +00:00
|
|
|
return $repository;
|
|
|
|
}
|
|
|
|
|
2020-02-07 06:35:07 +00:00
|
|
|
/**
|
|
|
|
* @doesNotPerformAssertions
|
|
|
|
*/
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testInitPerforceInstantiatesANewPerforceObject(): void
|
2014-03-14 19:45:31 +00:00
|
|
|
{
|
|
|
|
$this->downloader->initPerforce($this->package, $this->testPath, 'SOURCE_REF');
|
|
|
|
}
|
|
|
|
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testInitPerforceDoesNothingIfPerforceAlreadySet(): void
|
2014-03-14 19:45:31 +00:00
|
|
|
{
|
|
|
|
$perforce = $this->getMockBuilder('Composer\Util\Perforce')->disableOriginalConstructor()->getMock();
|
|
|
|
$this->downloader->setPerforce($perforce);
|
|
|
|
$this->repository->expects($this->never())->method('getRepoConfig');
|
|
|
|
$this->downloader->initPerforce($this->package, $this->testPath, 'SOURCE_REF');
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testInitPerforceInstantiatesANewPerforceObject
|
|
|
|
* @depends testInitPerforceDoesNothingIfPerforceAlreadySet
|
|
|
|
*/
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testDoInstallWithTag(): void
|
2013-09-04 14:24:49 +00:00
|
|
|
{
|
2014-03-14 19:45:31 +00:00
|
|
|
//I really don't like this test but the logic of each Perforce method is tested in the Perforce class. Really I am just enforcing workflow.
|
2014-03-24 20:19:35 +00:00
|
|
|
$ref = 'SOURCE_REF@123';
|
|
|
|
$label = 123;
|
|
|
|
$this->package->expects($this->once())->method('getSourceReference')->will($this->returnValue($ref));
|
2015-02-06 12:52:44 +00:00
|
|
|
$this->io->expects($this->once())->method('writeError')->with($this->stringContains('Cloning '.$ref));
|
2014-03-24 20:19:35 +00:00
|
|
|
$perforceMethods = array('setStream', 'p4Login', 'writeP4ClientSpec', 'connectClient', 'syncCodeBase', 'cleanupClientSpec');
|
2019-02-18 12:03:34 +00:00
|
|
|
$perforce = $this->getMockBuilder('Composer\Util\Perforce')->disableOriginalConstructor()->getMock();
|
2021-12-09 16:09:07 +00:00
|
|
|
$perforce->expects($this->once())->method('initializePath')->with($this->equalTo($this->testPath));
|
|
|
|
$perforce->expects($this->once())->method('setStream')->with($this->equalTo($ref));
|
|
|
|
$perforce->expects($this->once())->method('p4Login');
|
|
|
|
$perforce->expects($this->once())->method('writeP4ClientSpec');
|
|
|
|
$perforce->expects($this->once())->method('connectClient');
|
|
|
|
$perforce->expects($this->once())->method('syncCodeBase')->with($label);
|
|
|
|
$perforce->expects($this->once())->method('cleanupClientSpec');
|
2014-03-24 20:19:35 +00:00
|
|
|
$this->downloader->setPerforce($perforce);
|
2019-01-17 16:12:33 +00:00
|
|
|
$this->downloader->doInstall($this->package, $this->testPath, 'url');
|
2014-03-24 20:19:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testInitPerforceInstantiatesANewPerforceObject
|
|
|
|
* @depends testInitPerforceDoesNothingIfPerforceAlreadySet
|
|
|
|
*/
|
2022-02-18 09:38:54 +00:00
|
|
|
public function testDoInstallWithNoTag(): void
|
2014-03-24 20:19:35 +00:00
|
|
|
{
|
2013-09-09 19:48:24 +00:00
|
|
|
$ref = 'SOURCE_REF';
|
2014-03-24 20:19:35 +00:00
|
|
|
$label = null;
|
2014-03-14 19:45:31 +00:00
|
|
|
$this->package->expects($this->once())->method('getSourceReference')->will($this->returnValue($ref));
|
2015-02-06 12:52:44 +00:00
|
|
|
$this->io->expects($this->once())->method('writeError')->with($this->stringContains('Cloning '.$ref));
|
2014-03-14 19:45:31 +00:00
|
|
|
$perforceMethods = array('setStream', 'p4Login', 'writeP4ClientSpec', 'connectClient', 'syncCodeBase', 'cleanupClientSpec');
|
2019-02-18 12:03:34 +00:00
|
|
|
$perforce = $this->getMockBuilder('Composer\Util\Perforce')->disableOriginalConstructor()->getMock();
|
2021-12-09 16:09:07 +00:00
|
|
|
$perforce->expects($this->once())->method('initializePath')->with($this->equalTo($this->testPath));
|
|
|
|
$perforce->expects($this->once())->method('setStream')->with($this->equalTo($ref));
|
|
|
|
$perforce->expects($this->once())->method('p4Login');
|
|
|
|
$perforce->expects($this->once())->method('writeP4ClientSpec');
|
|
|
|
$perforce->expects($this->once())->method('connectClient');
|
|
|
|
$perforce->expects($this->once())->method('syncCodeBase')->with($label);
|
|
|
|
$perforce->expects($this->once())->method('cleanupClientSpec');
|
2014-03-14 19:45:31 +00:00
|
|
|
$this->downloader->setPerforce($perforce);
|
2019-01-17 16:12:33 +00:00
|
|
|
$this->downloader->doInstall($this->package, $this->testPath, 'url');
|
2013-08-09 19:24:58 +00:00
|
|
|
}
|
|
|
|
}
|