diff --git a/phpstan/baseline.neon b/phpstan/baseline.neon index 9d3580e48..1eef49077 100644 --- a/phpstan/baseline.neon +++ b/phpstan/baseline.neon @@ -9,3 +9,8 @@ parameters: message: "#^Parameter \\#2 \\$capabilityClassName of method Composer\\\\Plugin\\\\PluginManager\\:\\:getPluginCapability\\(\\) expects class\\-string\\, string given\\.$#" count: 2 path: ../tests/Composer/Test/Plugin/PluginInstallerTest.php + + - + message: "#^Unable to resolve the template type CapabilityClass in call to method Composer\\\\Plugin\\\\PluginManager::getPluginCapability\\(\\)$#" + count: 2 + path: ../tests/Composer/Test/Plugin/PluginInstallerTest.php diff --git a/phpstan/config.neon b/phpstan/config.neon index ee1aec43a..75e399f20 100644 --- a/phpstan/config.neon +++ b/phpstan/config.neon @@ -3,7 +3,7 @@ includes: - ./baseline.neon parameters: - level: 5 + level: 6 excludePaths: - '../tests/Composer/Test/Fixtures/*' diff --git a/tests/Composer/Test/AllFunctionalTest.php b/tests/Composer/Test/AllFunctionalTest.php index 954db12e0..0f89f1f57 100644 --- a/tests/Composer/Test/AllFunctionalTest.php +++ b/tests/Composer/Test/AllFunctionalTest.php @@ -102,6 +102,7 @@ class AllFunctionalTest extends TestCase /** * @dataProvider getTestFiles * @depends testBuildPhar + * @param string $testFile */ public function testIntegration($testFile) { diff --git a/tests/Composer/Test/ApplicationTest.php b/tests/Composer/Test/ApplicationTest.php index f3fb28ab2..e55d31d99 100644 --- a/tests/Composer/Test/ApplicationTest.php +++ b/tests/Composer/Test/ApplicationTest.php @@ -87,6 +87,10 @@ class ApplicationTest extends TestCase $application->doRun($inputMock, $outputMock); } + /** + * @param string $command + * @return void + */ public function ensureNoDevWarning($command) { $application = new Application; diff --git a/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php b/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php index ab8ae5625..5b3b114ce 100644 --- a/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php +++ b/tests/Composer/Test/Autoload/ClassMapGeneratorTest.php @@ -27,6 +27,8 @@ class ClassMapGeneratorTest extends TestCase { /** * @dataProvider getTestCreateMapTests + * @param string $directory + * @param array $expected */ public function testCreateMap($directory, $expected) { diff --git a/tests/Composer/Test/CacheTest.php b/tests/Composer/Test/CacheTest.php index fbf188d29..2d2fba28c 100644 --- a/tests/Composer/Test/CacheTest.php +++ b/tests/Composer/Test/CacheTest.php @@ -17,10 +17,15 @@ use Composer\Util\Filesystem; class CacheTest extends TestCase { + /** @var string[] */ private $files; + /** @var string */ private $root; + /** @var \Symfony\Component\Finder\Finder&\PHPUnit\Framework\MockObject\MockObject */ private $finder; + /** @var Filesystem&\PHPUnit\Framework\MockObject\MockObject */ private $filesystem; + /** @var Cache&\PHPUnit\Framework\MockObject\MockObject */ private $cache; public function setUp() @@ -108,7 +113,7 @@ class CacheTest extends TestCase public function testClearCache() { $io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); - $this->cache = new Cache($io, $this->root, 'a-z0-9.', $this->filesystem); - $this->assertTrue($this->cache->clear()); + $cache = new Cache($io, $this->root, 'a-z0-9.', $this->filesystem); + $this->assertTrue($cache->clear()); } } diff --git a/tests/Composer/Test/ConfigTest.php b/tests/Composer/Test/ConfigTest.php index 91d4dde07..ebc75ce04 100644 --- a/tests/Composer/Test/ConfigTest.php +++ b/tests/Composer/Test/ConfigTest.php @@ -18,6 +18,9 @@ class ConfigTest extends TestCase { /** * @dataProvider dataAddPackagistRepository + * @param mixed[] $expected + * @param mixed[] $localConfig + * @param ?mixed[] $systemConfig */ public function testAddPackagistRepository($expected, $localConfig, $systemConfig = null) { @@ -265,7 +268,7 @@ class ConfigTest extends TestCase } /** - * @return array List of test URLs that should pass strict security + * @return string[][] List of test URLs that should pass strict security */ public function allowedUrlProvider() { @@ -286,7 +289,7 @@ class ConfigTest extends TestCase } /** - * @return array List of test URLs that should not pass strict security + * @return string[][] List of test URLs that should not pass strict security */ public function prohibitedUrlProvider() { diff --git a/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php b/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php index 52589d5dd..534e6db31 100644 --- a/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php +++ b/tests/Composer/Test/DependencyResolver/PoolBuilderTest.php @@ -29,6 +29,13 @@ class PoolBuilderTest extends TestCase { /** * @dataProvider getIntegrationTests + * @param string $file + * @param string $message + * @param mixed[] $expect + * @param mixed[] $root + * @param mixed[] $requestData + * @param mixed[] $packageRepos + * @param mixed[] $fixed */ public function testPoolBuilder($file, $message, $expect, $root, $requestData, $packageRepos, $fixed) { diff --git a/tests/Composer/Test/Downloader/ArchiveDownloaderTest.php b/tests/Composer/Test/Downloader/ArchiveDownloaderTest.php index bfe1399f0..9537e462a 100644 --- a/tests/Composer/Test/Downloader/ArchiveDownloaderTest.php +++ b/tests/Composer/Test/Downloader/ArchiveDownloaderTest.php @@ -91,6 +91,7 @@ class ArchiveDownloaderTest extends TestCase /** * @dataProvider provideUrls + * @param string $url */ public function testProcessUrlRewriteDist($url) { @@ -128,6 +129,8 @@ class ArchiveDownloaderTest extends TestCase /** * @dataProvider provideBitbucketUrls + * @param string $url + * @param string $extension */ public function testProcessUrlRewriteBitbucketDist($url, $extension) { @@ -160,6 +163,9 @@ class ArchiveDownloaderTest extends TestCase ); } + /** + * @return \Composer\Downloader\ArchiveDownloader&\PHPUnit\Framework\MockObject\MockObject + */ private function getArchiveDownloaderMock() { return $this->getMockForAbstractClass( diff --git a/tests/Composer/Test/Downloader/DownloadManagerTest.php b/tests/Composer/Test/Downloader/DownloadManagerTest.php index 00037f0e5..db4ccbda8 100644 --- a/tests/Composer/Test/Downloader/DownloadManagerTest.php +++ b/tests/Composer/Test/Downloader/DownloadManagerTest.php @@ -632,6 +632,11 @@ class DownloadManagerTest extends TestCase /** * @dataProvider updatesProvider + * @param ?string $prevPkgSource + * @param ?bool $prevPkgIsDev + * @param string[] $targetAvailable + * @param bool $targetIsDev + * @param string[] $expected */ public function testGetAvailableSourcesUpdateSticksToSameSource($prevPkgSource, $prevPkgIsDev, $targetAvailable, $targetIsDev, $expected) { diff --git a/tests/Composer/Test/Downloader/FossilDownloaderTest.php b/tests/Composer/Test/Downloader/FossilDownloaderTest.php index f78e925e8..05978d4db 100644 --- a/tests/Composer/Test/Downloader/FossilDownloaderTest.php +++ b/tests/Composer/Test/Downloader/FossilDownloaderTest.php @@ -40,6 +40,7 @@ class FossilDownloaderTest extends TestCase * @param \Composer\Config $config * @param \Composer\Test\Mock\ProcessExecutorMock $executor * @param \Composer\Util\Filesystem $filesystem + * @return FossilDownloader */ protected function getDownloaderMock($io = null, $config = null, $executor = null, $filesystem = null) { diff --git a/tests/Composer/Test/Downloader/GitDownloaderTest.php b/tests/Composer/Test/Downloader/GitDownloaderTest.php index ac3e62221..1999b423e 100644 --- a/tests/Composer/Test/Downloader/GitDownloaderTest.php +++ b/tests/Composer/Test/Downloader/GitDownloaderTest.php @@ -79,6 +79,7 @@ class GitDownloaderTest extends TestCase * @param \Composer\Config $config * @param \Composer\Test\Mock\ProcessExecutorMock $executor * @param \Composer\Util\Filesystem $filesystem + * @return GitDownloader */ protected function getDownloaderMock($io = null, $config = null, $executor = null, $filesystem = null) { @@ -238,6 +239,9 @@ class GitDownloaderTest extends TestCase /** * @dataProvider pushUrlProvider + * @param string[] $protocols + * @param string $url + * @param string $pushUrl */ public function testDownloadAndSetPushUrlUseCustomVariousProtocolsForGithub($protocols, $url, $pushUrl) { diff --git a/tests/Composer/Test/Downloader/HgDownloaderTest.php b/tests/Composer/Test/Downloader/HgDownloaderTest.php index 871e3b870..3c3015a23 100644 --- a/tests/Composer/Test/Downloader/HgDownloaderTest.php +++ b/tests/Composer/Test/Downloader/HgDownloaderTest.php @@ -40,6 +40,7 @@ class HgDownloaderTest extends TestCase * @param \Composer\Config $config * @param \Composer\Test\Mock\ProcessExecutorMock $executor * @param \Composer\Util\Filesystem $filesystem + * @return HgDownloader */ protected function getDownloaderMock($io = null, $config = null, $executor = null, $filesystem = null) { diff --git a/tests/Composer/Test/InstalledVersionsTest.php b/tests/Composer/Test/InstalledVersionsTest.php index c9e291d3e..d66005b54 100644 --- a/tests/Composer/Test/InstalledVersionsTest.php +++ b/tests/Composer/Test/InstalledVersionsTest.php @@ -62,6 +62,9 @@ class InstalledVersionsTest extends TestCase /** * @dataProvider isInstalledProvider + * @param bool $expected + * @param string $name + * @param bool $includeDevRequirements */ public function testIsInstalled($expected, $name, $includeDevRequirements = true) { @@ -84,6 +87,9 @@ class InstalledVersionsTest extends TestCase /** * @dataProvider satisfiesProvider + * @param bool $expected + * @param string $name + * @param string $constraint */ public function testSatisfies($expected, $name, $constraint) { @@ -122,6 +128,8 @@ class InstalledVersionsTest extends TestCase /** * @dataProvider getVersionRangesProvider + * @param string $expected + * @param string $name */ public function testGetVersionRanges($expected, $name) { @@ -144,6 +152,8 @@ class InstalledVersionsTest extends TestCase /** * @dataProvider getVersionProvider + * @param ?string $expected + * @param string $name */ public function testGetVersion($expected, $name) { @@ -166,6 +176,8 @@ class InstalledVersionsTest extends TestCase /** * @dataProvider getPrettyVersionProvider + * @param ?string $expected + * @param string $name */ public function testGetPrettyVersion($expected, $name) { @@ -219,6 +231,8 @@ class InstalledVersionsTest extends TestCase /** * @dataProvider getReferenceProvider + * @param ?string $expected + * @param string $name */ public function testGetReference($expected, $name) { diff --git a/tests/Composer/Test/InstallerTest.php b/tests/Composer/Test/InstallerTest.php index 5c3548336..11d501b62 100644 --- a/tests/Composer/Test/InstallerTest.php +++ b/tests/Composer/Test/InstallerTest.php @@ -19,14 +19,17 @@ use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Composer\IO\BufferIO; +use Composer\Config; use Composer\Json\JsonFile; use Composer\Package\Dumper\ArrayDumper; use Composer\Util\Filesystem; use Composer\Repository\ArrayRepository; use Composer\Repository\RepositoryManager; +use Composer\Repository\RepositoryInterface; use Composer\Repository\InstalledArrayRepository; use Composer\Package\RootPackageInterface; use Composer\Package\BasePackage; +use Composer\Package\PackageInterface; use Composer\Package\Link; use Composer\Package\Locker; use Composer\Test\Mock\FactoryMock; @@ -39,7 +42,9 @@ use Symfony\Component\Console\Formatter\OutputFormatter; class InstallerTest extends TestCase { + /** @var string */ protected $prevCwd; + /** @var ?string */ protected $tempComposerHome; public function setUp() @@ -60,6 +65,8 @@ class InstallerTest extends TestCase /** * @dataProvider provideInstaller * @param RootPackageInterface&BasePackage $rootPackage + * @param RepositoryInterface[] $repositories + * @param array[] $options */ public function testInstaller(RootPackageInterface $rootPackage, $repositories, array $options) { @@ -143,6 +150,10 @@ class InstallerTest extends TestCase $this->assertSame($expectedUninstalled, $uninstalled); } + /** + * @param PackageInterface[] $packages + * @return mixed[] + */ protected function makePackagesComparable($packages) { $dumper = new ArrayDumper(); @@ -205,7 +216,19 @@ class InstallerTest extends TestCase /** * @group slow - * @dataProvider getSlowIntegrationTests + * @dataProvider provideSlowIntegrationTests + * @param string $file + * @param string $message + * @param ?string $condition + * @param Config $composerConfig + * @param ?mixed[] $lock + * @param ?mixed[] $installed + * @param string $run + * @param mixed[]|false $expectLock + * @param ?mixed[] $expectInstalled + * @param ?string $expectOutput + * @param string $expect + * @param int|string $expectResult */ public function testSlowIntegration($file, $message, $condition, $composerConfig, $lock, $installed, $run, $expectLock, $expectInstalled, $expectOutput, $expect, $expectResult) { @@ -213,7 +236,19 @@ class InstallerTest extends TestCase } /** - * @dataProvider getIntegrationTests + * @dataProvider provideIntegrationTests + * @param string $file + * @param string $message + * @param ?string $condition + * @param Config $composerConfig + * @param ?mixed[] $lock + * @param ?mixed[] $installed + * @param string $run + * @param mixed[]|false $expectLock + * @param ?mixed[] $expectInstalled + * @param ?string $expectOutput + * @param string $expect + * @param int|string $expectResult */ public function testIntegration($file, $message, $condition, $composerConfig, $lock, $installed, $run, $expectLock, $expectInstalled, $expectOutput, $expect, $expectResult) { @@ -408,16 +443,20 @@ class InstallerTest extends TestCase } } - public function getSlowIntegrationTests() + public function provideSlowIntegrationTests() { return $this->loadIntegrationTests('installer-slow/'); } - public function getIntegrationTests() + public function provideIntegrationTests() { return $this->loadIntegrationTests('installer/'); } + /** + * @param string $path + * @return mixed[] + */ public function loadIntegrationTests($path) { $fixturesDir = realpath(__DIR__.'/Fixtures/'.$path); @@ -499,6 +538,10 @@ class InstallerTest extends TestCase return $tests; } + /** + * @param string $fixturesDir + * @return mixed[] + */ protected function readTestFile(\SplFileInfo $file, $fixturesDir) { $tokens = preg_split('#(?:^|\n*)--([A-Z-]+)--\n#', file_get_contents($file->getRealPath()), -1, PREG_SPLIT_DELIM_CAPTURE); diff --git a/tests/Composer/Test/Json/JsonManipulatorTest.php b/tests/Composer/Test/Json/JsonManipulatorTest.php index 61490b4c4..00fd74bae 100644 --- a/tests/Composer/Test/Json/JsonManipulatorTest.php +++ b/tests/Composer/Test/Json/JsonManipulatorTest.php @@ -19,6 +19,11 @@ class JsonManipulatorTest extends TestCase { /** * @dataProvider linkProvider + * @param string $json + * @param string $type + * @param string $package + * @param string $constraint + * @param string $expected */ public function testAddLink($json, $type, $package, $constraint, $expected) { @@ -1289,6 +1294,12 @@ class JsonManipulatorTest extends TestCase /** * @dataProvider providerAddLinkAndSortPackages + * @param string $json + * @param string $type + * @param string $package + * @param string $constraint + * @param bool $sortPackages + * @param string $expected */ public function testAddLinkAndSortPackages($json, $type, $package, $constraint, $sortPackages, $expected) { @@ -1369,6 +1380,10 @@ class JsonManipulatorTest extends TestCase /** * @dataProvider removeSubNodeProvider + * @param string $json + * @param string $name + * @param string $expected + * @param ?string $expectedContent */ public function testRemoveSubNode($json, $name, $expected, $expectedContent = null) { diff --git a/tests/Composer/Test/Json/JsonValidationExceptionTest.php b/tests/Composer/Test/Json/JsonValidationExceptionTest.php index 3846b8d28..2212b26c2 100644 --- a/tests/Composer/Test/Json/JsonValidationExceptionTest.php +++ b/tests/Composer/Test/Json/JsonValidationExceptionTest.php @@ -19,6 +19,8 @@ class JsonValidationExceptionTest extends TestCase { /** * @dataProvider errorProvider + * @param string|null $message + * @param string[]|null $errors */ public function testGetErrors($message, $errors) { diff --git a/tests/Composer/Test/Platform/HhvmDetectorTest.php b/tests/Composer/Test/Platform/HhvmDetectorTest.php index de47672ac..36290361a 100644 --- a/tests/Composer/Test/Platform/HhvmDetectorTest.php +++ b/tests/Composer/Test/Platform/HhvmDetectorTest.php @@ -71,6 +71,9 @@ class HhvmDetectorTest extends TestCase self::assertSame(self::getVersionParser()->normalize($version), self::getVersionParser()->normalize($detectedVersion)); } + /** + * @return ?string + */ private static function versionIdToVersion() { if (!defined('HHVM_VERSION_ID')) { diff --git a/tests/Composer/Test/Platform/VersionTest.php b/tests/Composer/Test/Platform/VersionTest.php index 5d5452143..3ebb03724 100644 --- a/tests/Composer/Test/Platform/VersionTest.php +++ b/tests/Composer/Test/Platform/VersionTest.php @@ -27,7 +27,7 @@ class VersionTest extends TestCase * 2) git log --pretty=%h --all -- crypto/opensslv.h include/openssl/opensslv.h | while read hash ; do (git show $hash:crypto/opensslv.h; git show $hash:include/openssl/opensslv.h) | grep "define OPENSSL_VERSION_TEXT" ; done > versions.txt * 3) cat versions.txt | awk -F "OpenSSL " '{print $2}' | awk -F " " '{print $1}' | sed -e "s:\([0-9]*\.[0-9]*\.[0-9]*\):1.2.3:g" -e "s:1\.2\.3[a-z]\(-.*\)\{0,1\}$:1.2.3a\1:g" -e "s:1\.2\.3[a-z]\{2\}\(-.*\)\{0,1\}$:1.2.3zh\1:g" -e "s:beta[0-9]:beta3:g" -e "s:pre[0-9]*:pre2:g" | sort | uniq */ - public static function getOpenSslVersions() + public static function provideOpenSslVersions() { return array( // Generated @@ -73,7 +73,7 @@ class VersionTest extends TestCase } /** - * @dataProvider getOpenSslVersions + * @dataProvider provideOpenSslVersions * @param string $input * @param string $parsedVersion * @param bool $fipsExpected @@ -88,7 +88,7 @@ class VersionTest extends TestCase self::assertSame($normalizedVersion, $this->getVersionParser()->normalize($parsedVersion)); } - public function getLibJpegVersions() + public function provideLibJpegVersions() { return array( array('9', '9.0'), @@ -100,7 +100,7 @@ class VersionTest extends TestCase } /** - * @dataProvider getLibJpegVersions + * @dataProvider provideLibJpegVersions * @param string $input * @param string $parsedVersion */ @@ -109,7 +109,7 @@ class VersionTest extends TestCase self::assertSame($parsedVersion, Version::parseLibjpeg($input)); } - public function getZoneinfoVersions() + public function provideZoneinfoVersions() { return array( array('2019c', '2019.3'), @@ -120,7 +120,7 @@ class VersionTest extends TestCase } /** - * @dataProvider getZoneinfoVersions + * @dataProvider provideZoneinfoVersions * @param string $input * @param string $parsedVersion */ diff --git a/tests/Composer/Test/Plugin/PluginInstallerTest.php b/tests/Composer/Test/Plugin/PluginInstallerTest.php index dc69fbb35..07468f4f0 100644 --- a/tests/Composer/Test/Plugin/PluginInstallerTest.php +++ b/tests/Composer/Test/Plugin/PluginInstallerTest.php @@ -353,7 +353,6 @@ class PluginInstallerTest extends TestCase { $plugin = $this->getMockBuilder('Composer\Plugin\PluginInterface') ->getMock(); - /** @phpstan-ignore-next-line */ $this->assertNull($this->pm->getPluginCapability($plugin, 'Fake\Ability')); } @@ -442,7 +441,6 @@ class PluginInstallerTest extends TestCase return array(); })); - /** @phpstan-ignore-next-line */ $this->assertNull($this->pm->getPluginCapability($plugin, $capabilityApi)); }