diff --git a/tests/Composer/Test/Downloader/ArchiveDownloaderTest.php b/tests/Composer/Test/Downloader/ArchiveDownloaderTest.php index e2cc87bc9..bfe1399f0 100644 --- a/tests/Composer/Test/Downloader/ArchiveDownloaderTest.php +++ b/tests/Composer/Test/Downloader/ArchiveDownloaderTest.php @@ -16,6 +16,7 @@ use Composer\Test\TestCase; class ArchiveDownloaderTest extends TestCase { + /** @var \Composer\Config&\PHPUnit\Framework\MockObject\MockObject */ protected $config; public function testGetFileName() diff --git a/tests/Composer/Test/Downloader/DownloadManagerTest.php b/tests/Composer/Test/Downloader/DownloadManagerTest.php index 4253882b6..00037f0e5 100644 --- a/tests/Composer/Test/Downloader/DownloadManagerTest.php +++ b/tests/Composer/Test/Downloader/DownloadManagerTest.php @@ -17,7 +17,10 @@ use Composer\Test\TestCase; class DownloadManagerTest extends TestCase { + /** @var \Composer\Util\Filesystem&\PHPUnit\Framework\MockObject\MockObject */ protected $filesystem; + + /** @var \Composer\IO\IOInterface&\PHPUnit\Framework\MockObject\MockObject */ protected $io; public function setUp() @@ -1091,12 +1094,18 @@ class DownloadManagerTest extends TestCase $manager->download($package, 'target_dir'); } + /** + * @return \Composer\Downloader\DownloaderInterface&\PHPUnit\Framework\MockObject\MockObject + */ private function createDownloaderMock() { return $this->getMockBuilder('Composer\Downloader\DownloaderInterface') ->getMock(); } + /** + * @return \Composer\Package\PackageInterface&\PHPUnit\Framework\MockObject\MockObject + */ private function createPackageMock() { return $this->getMockBuilder('Composer\Package\PackageInterface') diff --git a/tests/Composer/Test/Downloader/FileDownloaderTest.php b/tests/Composer/Test/Downloader/FileDownloaderTest.php index 036410407..7ad59b30d 100644 --- a/tests/Composer/Test/Downloader/FileDownloaderTest.php +++ b/tests/Composer/Test/Downloader/FileDownloaderTest.php @@ -25,13 +25,30 @@ use Composer\Util\Loop; class FileDownloaderTest extends TestCase { + /** @var \Composer\Util\HttpDownloader&\PHPUnit\Framework\MockObject\MockObject */ private $httpDownloader; + /** @var \Composer\Config&\PHPUnit\Framework\MockObject\MockObject */ private $config; + public function setUp() + { + $this->httpDownloader = $this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock(); + $this->config = $this->getMockBuilder('Composer\Config')->getMock(); + } + + /** + * @param \Composer\IO\IOInterface $io + * @param \Composer\Config&\PHPUnit\Framework\MockObject\MockObject $config + * @param \Composer\EventDispatcher\EventDispatcher $eventDispatcher + * @param \Composer\Cache $cache + * @param \Composer\Util\HttpDownloader&\PHPUnit\Framework\MockObject\MockObject $httpDownloader + * @param \Composer\Util\Filesystem $filesystem + * @return \Composer\Downloader\FileDownloader + */ protected function getDownloader($io = null, $config = null, $eventDispatcher = null, $cache = null, $httpDownloader = null, $filesystem = null) { $io = $io ?: $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); - $this->config = $config ?: $this->getMockBuilder('Composer\Config')->getMock(); + $config = $config ?: $this->config; $httpDownloader = $httpDownloader ?: $this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock(); $httpDownloader ->expects($this->any()) @@ -166,7 +183,6 @@ class FileDownloaderTest extends TestCase $self = $this; $path = $this->getUniqueTmpDirectory(); - $config = new Config(false, $path); $packageMock = $this->getMockBuilder('Composer\Package\PackageInterface')->getMock(); $packageMock->expects($this->any()) @@ -187,7 +203,16 @@ class FileDownloaderTest extends TestCase ->will($this->returnValue($rootPackageMock)); $composerMock->expects($this->any()) ->method('getConfig') - ->will($this->returnValue($config)); + ->will($this->returnValue($this->config)); + $this->config->expects($this->any()) + ->method('get') + ->will($this->returnCallback(function ($key) use ($path) { + if ($key === 'vendor-dir') { + return $path.'/vendor'; + } elseif ($key === 'bin-dir') { + return $path.'/vendor/bin'; + } + })); $expectedUrl = 'foobar'; $expectedCacheKey = '/'.sha1($expectedUrl).'.'; @@ -233,7 +258,7 @@ class FileDownloaderTest extends TestCase ); })); - $downloader = $this->getDownloader(null, $config, $dispatcher, $cacheMock, $httpDownloaderMock); + $downloader = $this->getDownloader(null, $this->config, $dispatcher, $cacheMock, $httpDownloaderMock); try { $loop = new Loop($this->httpDownloader); @@ -259,7 +284,6 @@ class FileDownloaderTest extends TestCase $self = $this; $path = $this->getUniqueTmpDirectory(); - $config = new Config(false, $path); $packageMock = $this->getMockBuilder('Composer\Package\PackageInterface')->getMock(); $packageMock->expects($this->any()) @@ -280,7 +304,16 @@ class FileDownloaderTest extends TestCase ->will($this->returnValue($rootPackageMock)); $composerMock->expects($this->any()) ->method('getConfig') - ->will($this->returnValue($config)); + ->will($this->returnValue($this->config)); + $this->config->expects($this->any()) + ->method('get') + ->will($this->returnCallback(function ($key) use ($path) { + if ($key === 'vendor-dir') { + return $path.'/vendor'; + } elseif ($key === 'bin-dir') { + return $path.'/vendor/bin'; + } + })); $expectedUrl = 'url'; $customCacheKey = 'xyzzy'; @@ -327,7 +360,7 @@ class FileDownloaderTest extends TestCase ); })); - $downloader = $this->getDownloader(null, $config, $dispatcher, $cacheMock, $httpDownloaderMock); + $downloader = $this->getDownloader(null, $this->config, $dispatcher, $cacheMock, $httpDownloaderMock); try { $loop = new Loop($this->httpDownloader); @@ -352,13 +385,13 @@ class FileDownloaderTest extends TestCase { $expectedTtl = '99999999'; - $configMock = $this->getMockBuilder('Composer\Config')->getMock(); - $configMock + $this->config = $this->getMockBuilder('Composer\Config')->getMock(); + $this->config ->expects($this->at(0)) ->method('get') ->with('cache-files-ttl') ->will($this->returnValue($expectedTtl)); - $configMock + $this->config ->expects($this->at(1)) ->method('get') ->with('cache-files-maxsize') @@ -376,7 +409,7 @@ class FileDownloaderTest extends TestCase ->method('gc') ->with($expectedTtl, $this->anything()); - $downloader = $this->getDownloader(null, $configMock, null, $cacheMock, null, null); + $downloader = $this->getDownloader(null, $this->config, null, $cacheMock, null, null); } public function testDownloadFileWithInvalidChecksum() diff --git a/tests/Composer/Test/Downloader/FossilDownloaderTest.php b/tests/Composer/Test/Downloader/FossilDownloaderTest.php index 41611a459..f78e925e8 100644 --- a/tests/Composer/Test/Downloader/FossilDownloaderTest.php +++ b/tests/Composer/Test/Downloader/FossilDownloaderTest.php @@ -35,6 +35,12 @@ class FossilDownloaderTest extends TestCase } } + /** + * @param \Composer\IO\IOInterface $io + * @param \Composer\Config $config + * @param \Composer\Test\Mock\ProcessExecutorMock $executor + * @param \Composer\Util\Filesystem $filesystem + */ protected function getDownloaderMock($io = null, $config = null, $executor = null, $filesystem = null) { $io = $io ?: $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); diff --git a/tests/Composer/Test/Downloader/GitDownloaderTest.php b/tests/Composer/Test/Downloader/GitDownloaderTest.php index bfdefe055..ac3e62221 100644 --- a/tests/Composer/Test/Downloader/GitDownloaderTest.php +++ b/tests/Composer/Test/Downloader/GitDownloaderTest.php @@ -45,6 +45,10 @@ class GitDownloaderTest extends TestCase $this->initGitVersion(false); } + /** + * @param string|bool $version + * @return void + */ private function initGitVersion($version) { // reset the static version cache @@ -53,6 +57,10 @@ class GitDownloaderTest extends TestCase $refl->setValue(null, $version); } + /** + * @param ?\Composer\Config $config + * @return \Composer\Config + */ protected function setupConfig($config = null) { if (!$config) { @@ -66,6 +74,12 @@ class GitDownloaderTest extends TestCase return $config; } + /** + * @param \Composer\IO\IOInterface $io + * @param \Composer\Config $config + * @param \Composer\Test\Mock\ProcessExecutorMock $executor + * @param \Composer\Util\Filesystem $filesystem + */ protected function getDownloaderMock($io = null, $config = null, $executor = null, $filesystem = null) { $io = $io ?: $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); @@ -641,6 +655,10 @@ composer https://github.com/old/url (push) $this->assertEquals('source', $downloader->getInstallationSource()); } + /** + * @param string $cmd + * @return string + */ private function winCompat($cmd) { if (Platform::isWindows()) { diff --git a/tests/Composer/Test/Downloader/HgDownloaderTest.php b/tests/Composer/Test/Downloader/HgDownloaderTest.php index 19b5b723c..871e3b870 100644 --- a/tests/Composer/Test/Downloader/HgDownloaderTest.php +++ b/tests/Composer/Test/Downloader/HgDownloaderTest.php @@ -35,6 +35,12 @@ class HgDownloaderTest extends TestCase } } + /** + * @param \Composer\IO\IOInterface $io + * @param \Composer\Config $config + * @param \Composer\Test\Mock\ProcessExecutorMock $executor + * @param \Composer\Util\Filesystem $filesystem + */ protected function getDownloaderMock($io = null, $config = null, $executor = null, $filesystem = null) { $io = $io ?: $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); diff --git a/tests/Composer/Test/Downloader/PerforceDownloaderTest.php b/tests/Composer/Test/Downloader/PerforceDownloaderTest.php index cd47d8ecf..95bf048d3 100644 --- a/tests/Composer/Test/Downloader/PerforceDownloaderTest.php +++ b/tests/Composer/Test/Downloader/PerforceDownloaderTest.php @@ -26,14 +26,21 @@ use Composer\Test\Mock\ProcessExecutorMock; */ class PerforceDownloaderTest extends TestCase { + /** @var \Composer\Config */ protected $config; - /** @var ?PerforceDownloader */ + /** @var \Composer\Downloader\PerforceDownloader */ protected $downloader; + /** @var \Composer\IO\IOInterface&\PHPUnit\Framework\MockObject\MockObject */ protected $io; + /** @var \Composer\Package\PackageInterface&\PHPUnit\Framework\MockObject\MockObject */ protected $package; + /** @var \Composer\Test\Mock\ProcessExecutorMock */ protected $processExecutor; + /** @var string[] */ protected $repoConfig; + /** @var \Composer\Repository\VcsRepository&\PHPUnit\Framework\MockObject\MockObject */ protected $repository; + /** @var string */ protected $testPath; protected function setUp() @@ -48,20 +55,9 @@ class PerforceDownloaderTest extends TestCase $this->downloader = new PerforceDownloader($this->io, $this->config, $this->processExecutor); } - protected function tearDown() - { - $this->downloader = null; - $this->package = null; - $this->repository = null; - $this->io = null; - $this->config = null; - $this->repoConfig = null; - if (is_dir($this->testPath)) { - $fs = new Filesystem; - $fs->removeDirectory($this->testPath); - } - } - + /** + * @return \Composer\Config + */ protected function getConfig() { $config = new Config(); @@ -71,11 +67,17 @@ class PerforceDownloaderTest extends TestCase return $config; } + /** + * @return \Composer\IO\IOInterface&\PHPUnit\Framework\MockObject\MockObject + */ protected function getMockIoInterface() { return $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); } + /** + * @return \Composer\Package\PackageInterface&\PHPUnit\Framework\MockObject\MockObject + */ protected function getMockPackageInterface(VcsRepository $repository) { $package = $this->getMockBuilder('Composer\Package\PackageInterface')->getMock(); @@ -84,11 +86,20 @@ class PerforceDownloaderTest extends TestCase return $package; } + /** + * @return string[] + */ protected function getRepoConfig() { return array('url' => 'TEST_URL', 'p4user' => 'TEST_USER'); } + /** + * @param string[] $repoConfig + * @param \Composer\IO\IOInterface $io + * @param \Composer\Config $config + * @return \Composer\Repository\VcsRepository&\PHPUnit\Framework\MockObject\MockObject + */ protected function getMockRepository(array $repoConfig, IOInterface $io, Config $config) { $repository = $this->getMockBuilder('Composer\Repository\VcsRepository') diff --git a/tests/Composer/Test/Downloader/ZipDownloaderTest.php b/tests/Composer/Test/Downloader/ZipDownloaderTest.php index 9c9c974fd..b8e148f2b 100644 --- a/tests/Composer/Test/Downloader/ZipDownloaderTest.php +++ b/tests/Composer/Test/Downloader/ZipDownloaderTest.php @@ -21,13 +21,15 @@ use Composer\Util\Loop; class ZipDownloaderTest extends TestCase { - /** - * @var string - */ + /** @var string */ private $testDir; + /** @var \Composer\Util\HttpDownloader */ private $httpDownloader; + /** @var \Composer\IO\IOInterface&\PHPUnit\Framework\MockObject\MockObject */ private $io; + /** @var \Composer\Config&\PHPUnit\Framework\MockObject\MockObject */ private $config; + /** @var \Composer\Package\PackageInterface&\PHPUnit\Framework\MockObject\MockObject */ private $package; public function setUp() @@ -47,6 +49,12 @@ class ZipDownloaderTest extends TestCase $this->setPrivateProperty('hasZipArchive', null); } + /** + * @param string $name + * @param mixed $value + * @param ?\Composer\Test\Downloader\MockedZipDownloader $obj + * @return void + */ public function setPrivateProperty($name, $value, $obj = null) { $reflectionClass = new \ReflectionClass('Composer\Downloader\ZipDownloader'); @@ -296,6 +304,10 @@ class ZipDownloaderTest extends TestCase $this->wait($promise); } + /** + * @param ?\React\Promise\PromiseInterface $promise + * @return void + */ private function wait($promise) { if (null === $promise) {