1
0
Fork 0

Finalize phpstan level 6 for tests dir, closes #10159

pull/10257/head
Jordi Boggiano 2021-11-02 14:32:09 +01:00
parent a86046f9e4
commit cb0293cf30
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
20 changed files with 136 additions and 17 deletions

View File

@ -9,3 +9,8 @@ parameters:
message: "#^Parameter \\#2 \\$capabilityClassName of method Composer\\\\Plugin\\\\PluginManager\\:\\:getPluginCapability\\(\\) expects class\\-string\\<Composer\\\\Plugin\\\\Capability\\\\Capability\\>, string given\\.$#" message: "#^Parameter \\#2 \\$capabilityClassName of method Composer\\\\Plugin\\\\PluginManager\\:\\:getPluginCapability\\(\\) expects class\\-string\\<Composer\\\\Plugin\\\\Capability\\\\Capability\\>, string given\\.$#"
count: 2 count: 2
path: ../tests/Composer/Test/Plugin/PluginInstallerTest.php 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

View File

@ -3,7 +3,7 @@ includes:
- ./baseline.neon - ./baseline.neon
parameters: parameters:
level: 5 level: 6
excludePaths: excludePaths:
- '../tests/Composer/Test/Fixtures/*' - '../tests/Composer/Test/Fixtures/*'

View File

@ -102,6 +102,7 @@ class AllFunctionalTest extends TestCase
/** /**
* @dataProvider getTestFiles * @dataProvider getTestFiles
* @depends testBuildPhar * @depends testBuildPhar
* @param string $testFile
*/ */
public function testIntegration($testFile) public function testIntegration($testFile)
{ {

View File

@ -87,6 +87,10 @@ class ApplicationTest extends TestCase
$application->doRun($inputMock, $outputMock); $application->doRun($inputMock, $outputMock);
} }
/**
* @param string $command
* @return void
*/
public function ensureNoDevWarning($command) public function ensureNoDevWarning($command)
{ {
$application = new Application; $application = new Application;

View File

@ -27,6 +27,8 @@ class ClassMapGeneratorTest extends TestCase
{ {
/** /**
* @dataProvider getTestCreateMapTests * @dataProvider getTestCreateMapTests
* @param string $directory
* @param array<string, string> $expected
*/ */
public function testCreateMap($directory, $expected) public function testCreateMap($directory, $expected)
{ {

View File

@ -17,10 +17,15 @@ use Composer\Util\Filesystem;
class CacheTest extends TestCase class CacheTest extends TestCase
{ {
/** @var string[] */
private $files; private $files;
/** @var string */
private $root; private $root;
/** @var \Symfony\Component\Finder\Finder&\PHPUnit\Framework\MockObject\MockObject */
private $finder; private $finder;
/** @var Filesystem&\PHPUnit\Framework\MockObject\MockObject */
private $filesystem; private $filesystem;
/** @var Cache&\PHPUnit\Framework\MockObject\MockObject */
private $cache; private $cache;
public function setUp() public function setUp()
@ -108,7 +113,7 @@ class CacheTest extends TestCase
public function testClearCache() public function testClearCache()
{ {
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); $io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
$this->cache = new Cache($io, $this->root, 'a-z0-9.', $this->filesystem); $cache = new Cache($io, $this->root, 'a-z0-9.', $this->filesystem);
$this->assertTrue($this->cache->clear()); $this->assertTrue($cache->clear());
} }
} }

View File

@ -18,6 +18,9 @@ class ConfigTest extends TestCase
{ {
/** /**
* @dataProvider dataAddPackagistRepository * @dataProvider dataAddPackagistRepository
* @param mixed[] $expected
* @param mixed[] $localConfig
* @param ?mixed[] $systemConfig
*/ */
public function testAddPackagistRepository($expected, $localConfig, $systemConfig = null) 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() 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() public function prohibitedUrlProvider()
{ {

View File

@ -29,6 +29,13 @@ class PoolBuilderTest extends TestCase
{ {
/** /**
* @dataProvider getIntegrationTests * @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) public function testPoolBuilder($file, $message, $expect, $root, $requestData, $packageRepos, $fixed)
{ {

View File

@ -91,6 +91,7 @@ class ArchiveDownloaderTest extends TestCase
/** /**
* @dataProvider provideUrls * @dataProvider provideUrls
* @param string $url
*/ */
public function testProcessUrlRewriteDist($url) public function testProcessUrlRewriteDist($url)
{ {
@ -128,6 +129,8 @@ class ArchiveDownloaderTest extends TestCase
/** /**
* @dataProvider provideBitbucketUrls * @dataProvider provideBitbucketUrls
* @param string $url
* @param string $extension
*/ */
public function testProcessUrlRewriteBitbucketDist($url, $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() private function getArchiveDownloaderMock()
{ {
return $this->getMockForAbstractClass( return $this->getMockForAbstractClass(

View File

@ -632,6 +632,11 @@ class DownloadManagerTest extends TestCase
/** /**
* @dataProvider updatesProvider * @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) public function testGetAvailableSourcesUpdateSticksToSameSource($prevPkgSource, $prevPkgIsDev, $targetAvailable, $targetIsDev, $expected)
{ {

View File

@ -40,6 +40,7 @@ class FossilDownloaderTest extends TestCase
* @param \Composer\Config $config * @param \Composer\Config $config
* @param \Composer\Test\Mock\ProcessExecutorMock $executor * @param \Composer\Test\Mock\ProcessExecutorMock $executor
* @param \Composer\Util\Filesystem $filesystem * @param \Composer\Util\Filesystem $filesystem
* @return FossilDownloader
*/ */
protected function getDownloaderMock($io = null, $config = null, $executor = null, $filesystem = null) protected function getDownloaderMock($io = null, $config = null, $executor = null, $filesystem = null)
{ {

View File

@ -79,6 +79,7 @@ class GitDownloaderTest extends TestCase
* @param \Composer\Config $config * @param \Composer\Config $config
* @param \Composer\Test\Mock\ProcessExecutorMock $executor * @param \Composer\Test\Mock\ProcessExecutorMock $executor
* @param \Composer\Util\Filesystem $filesystem * @param \Composer\Util\Filesystem $filesystem
* @return GitDownloader
*/ */
protected function getDownloaderMock($io = null, $config = null, $executor = null, $filesystem = null) protected function getDownloaderMock($io = null, $config = null, $executor = null, $filesystem = null)
{ {
@ -238,6 +239,9 @@ class GitDownloaderTest extends TestCase
/** /**
* @dataProvider pushUrlProvider * @dataProvider pushUrlProvider
* @param string[] $protocols
* @param string $url
* @param string $pushUrl
*/ */
public function testDownloadAndSetPushUrlUseCustomVariousProtocolsForGithub($protocols, $url, $pushUrl) public function testDownloadAndSetPushUrlUseCustomVariousProtocolsForGithub($protocols, $url, $pushUrl)
{ {

View File

@ -40,6 +40,7 @@ class HgDownloaderTest extends TestCase
* @param \Composer\Config $config * @param \Composer\Config $config
* @param \Composer\Test\Mock\ProcessExecutorMock $executor * @param \Composer\Test\Mock\ProcessExecutorMock $executor
* @param \Composer\Util\Filesystem $filesystem * @param \Composer\Util\Filesystem $filesystem
* @return HgDownloader
*/ */
protected function getDownloaderMock($io = null, $config = null, $executor = null, $filesystem = null) protected function getDownloaderMock($io = null, $config = null, $executor = null, $filesystem = null)
{ {

View File

@ -62,6 +62,9 @@ class InstalledVersionsTest extends TestCase
/** /**
* @dataProvider isInstalledProvider * @dataProvider isInstalledProvider
* @param bool $expected
* @param string $name
* @param bool $includeDevRequirements
*/ */
public function testIsInstalled($expected, $name, $includeDevRequirements = true) public function testIsInstalled($expected, $name, $includeDevRequirements = true)
{ {
@ -84,6 +87,9 @@ class InstalledVersionsTest extends TestCase
/** /**
* @dataProvider satisfiesProvider * @dataProvider satisfiesProvider
* @param bool $expected
* @param string $name
* @param string $constraint
*/ */
public function testSatisfies($expected, $name, $constraint) public function testSatisfies($expected, $name, $constraint)
{ {
@ -122,6 +128,8 @@ class InstalledVersionsTest extends TestCase
/** /**
* @dataProvider getVersionRangesProvider * @dataProvider getVersionRangesProvider
* @param string $expected
* @param string $name
*/ */
public function testGetVersionRanges($expected, $name) public function testGetVersionRanges($expected, $name)
{ {
@ -144,6 +152,8 @@ class InstalledVersionsTest extends TestCase
/** /**
* @dataProvider getVersionProvider * @dataProvider getVersionProvider
* @param ?string $expected
* @param string $name
*/ */
public function testGetVersion($expected, $name) public function testGetVersion($expected, $name)
{ {
@ -166,6 +176,8 @@ class InstalledVersionsTest extends TestCase
/** /**
* @dataProvider getPrettyVersionProvider * @dataProvider getPrettyVersionProvider
* @param ?string $expected
* @param string $name
*/ */
public function testGetPrettyVersion($expected, $name) public function testGetPrettyVersion($expected, $name)
{ {
@ -219,6 +231,8 @@ class InstalledVersionsTest extends TestCase
/** /**
* @dataProvider getReferenceProvider * @dataProvider getReferenceProvider
* @param ?string $expected
* @param string $name
*/ */
public function testGetReference($expected, $name) public function testGetReference($expected, $name)
{ {

View File

@ -19,14 +19,17 @@ use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputOption;
use Composer\IO\BufferIO; use Composer\IO\BufferIO;
use Composer\Config;
use Composer\Json\JsonFile; use Composer\Json\JsonFile;
use Composer\Package\Dumper\ArrayDumper; use Composer\Package\Dumper\ArrayDumper;
use Composer\Util\Filesystem; use Composer\Util\Filesystem;
use Composer\Repository\ArrayRepository; use Composer\Repository\ArrayRepository;
use Composer\Repository\RepositoryManager; use Composer\Repository\RepositoryManager;
use Composer\Repository\RepositoryInterface;
use Composer\Repository\InstalledArrayRepository; use Composer\Repository\InstalledArrayRepository;
use Composer\Package\RootPackageInterface; use Composer\Package\RootPackageInterface;
use Composer\Package\BasePackage; use Composer\Package\BasePackage;
use Composer\Package\PackageInterface;
use Composer\Package\Link; use Composer\Package\Link;
use Composer\Package\Locker; use Composer\Package\Locker;
use Composer\Test\Mock\FactoryMock; use Composer\Test\Mock\FactoryMock;
@ -39,7 +42,9 @@ use Symfony\Component\Console\Formatter\OutputFormatter;
class InstallerTest extends TestCase class InstallerTest extends TestCase
{ {
/** @var string */
protected $prevCwd; protected $prevCwd;
/** @var ?string */
protected $tempComposerHome; protected $tempComposerHome;
public function setUp() public function setUp()
@ -60,6 +65,8 @@ class InstallerTest extends TestCase
/** /**
* @dataProvider provideInstaller * @dataProvider provideInstaller
* @param RootPackageInterface&BasePackage $rootPackage * @param RootPackageInterface&BasePackage $rootPackage
* @param RepositoryInterface[] $repositories
* @param array[] $options
*/ */
public function testInstaller(RootPackageInterface $rootPackage, $repositories, array $options) public function testInstaller(RootPackageInterface $rootPackage, $repositories, array $options)
{ {
@ -143,6 +150,10 @@ class InstallerTest extends TestCase
$this->assertSame($expectedUninstalled, $uninstalled); $this->assertSame($expectedUninstalled, $uninstalled);
} }
/**
* @param PackageInterface[] $packages
* @return mixed[]
*/
protected function makePackagesComparable($packages) protected function makePackagesComparable($packages)
{ {
$dumper = new ArrayDumper(); $dumper = new ArrayDumper();
@ -205,7 +216,19 @@ class InstallerTest extends TestCase
/** /**
* @group slow * @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) 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) 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/'); return $this->loadIntegrationTests('installer-slow/');
} }
public function getIntegrationTests() public function provideIntegrationTests()
{ {
return $this->loadIntegrationTests('installer/'); return $this->loadIntegrationTests('installer/');
} }
/**
* @param string $path
* @return mixed[]
*/
public function loadIntegrationTests($path) public function loadIntegrationTests($path)
{ {
$fixturesDir = realpath(__DIR__.'/Fixtures/'.$path); $fixturesDir = realpath(__DIR__.'/Fixtures/'.$path);
@ -499,6 +538,10 @@ class InstallerTest extends TestCase
return $tests; return $tests;
} }
/**
* @param string $fixturesDir
* @return mixed[]
*/
protected function readTestFile(\SplFileInfo $file, $fixturesDir) protected function readTestFile(\SplFileInfo $file, $fixturesDir)
{ {
$tokens = preg_split('#(?:^|\n*)--([A-Z-]+)--\n#', file_get_contents($file->getRealPath()), -1, PREG_SPLIT_DELIM_CAPTURE); $tokens = preg_split('#(?:^|\n*)--([A-Z-]+)--\n#', file_get_contents($file->getRealPath()), -1, PREG_SPLIT_DELIM_CAPTURE);

View File

@ -19,6 +19,11 @@ class JsonManipulatorTest extends TestCase
{ {
/** /**
* @dataProvider linkProvider * @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) public function testAddLink($json, $type, $package, $constraint, $expected)
{ {
@ -1289,6 +1294,12 @@ class JsonManipulatorTest extends TestCase
/** /**
* @dataProvider providerAddLinkAndSortPackages * @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) public function testAddLinkAndSortPackages($json, $type, $package, $constraint, $sortPackages, $expected)
{ {
@ -1369,6 +1380,10 @@ class JsonManipulatorTest extends TestCase
/** /**
* @dataProvider removeSubNodeProvider * @dataProvider removeSubNodeProvider
* @param string $json
* @param string $name
* @param string $expected
* @param ?string $expectedContent
*/ */
public function testRemoveSubNode($json, $name, $expected, $expectedContent = null) public function testRemoveSubNode($json, $name, $expected, $expectedContent = null)
{ {

View File

@ -19,6 +19,8 @@ class JsonValidationExceptionTest extends TestCase
{ {
/** /**
* @dataProvider errorProvider * @dataProvider errorProvider
* @param string|null $message
* @param string[]|null $errors
*/ */
public function testGetErrors($message, $errors) public function testGetErrors($message, $errors)
{ {

View File

@ -71,6 +71,9 @@ class HhvmDetectorTest extends TestCase
self::assertSame(self::getVersionParser()->normalize($version), self::getVersionParser()->normalize($detectedVersion)); self::assertSame(self::getVersionParser()->normalize($version), self::getVersionParser()->normalize($detectedVersion));
} }
/**
* @return ?string
*/
private static function versionIdToVersion() private static function versionIdToVersion()
{ {
if (!defined('HHVM_VERSION_ID')) { if (!defined('HHVM_VERSION_ID')) {

View File

@ -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 * 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 * 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( return array(
// Generated // Generated
@ -73,7 +73,7 @@ class VersionTest extends TestCase
} }
/** /**
* @dataProvider getOpenSslVersions * @dataProvider provideOpenSslVersions
* @param string $input * @param string $input
* @param string $parsedVersion * @param string $parsedVersion
* @param bool $fipsExpected * @param bool $fipsExpected
@ -88,7 +88,7 @@ class VersionTest extends TestCase
self::assertSame($normalizedVersion, $this->getVersionParser()->normalize($parsedVersion)); self::assertSame($normalizedVersion, $this->getVersionParser()->normalize($parsedVersion));
} }
public function getLibJpegVersions() public function provideLibJpegVersions()
{ {
return array( return array(
array('9', '9.0'), array('9', '9.0'),
@ -100,7 +100,7 @@ class VersionTest extends TestCase
} }
/** /**
* @dataProvider getLibJpegVersions * @dataProvider provideLibJpegVersions
* @param string $input * @param string $input
* @param string $parsedVersion * @param string $parsedVersion
*/ */
@ -109,7 +109,7 @@ class VersionTest extends TestCase
self::assertSame($parsedVersion, Version::parseLibjpeg($input)); self::assertSame($parsedVersion, Version::parseLibjpeg($input));
} }
public function getZoneinfoVersions() public function provideZoneinfoVersions()
{ {
return array( return array(
array('2019c', '2019.3'), array('2019c', '2019.3'),
@ -120,7 +120,7 @@ class VersionTest extends TestCase
} }
/** /**
* @dataProvider getZoneinfoVersions * @dataProvider provideZoneinfoVersions
* @param string $input * @param string $input
* @param string $parsedVersion * @param string $parsedVersion
*/ */

View File

@ -353,7 +353,6 @@ class PluginInstallerTest extends TestCase
{ {
$plugin = $this->getMockBuilder('Composer\Plugin\PluginInterface') $plugin = $this->getMockBuilder('Composer\Plugin\PluginInterface')
->getMock(); ->getMock();
/** @phpstan-ignore-next-line */
$this->assertNull($this->pm->getPluginCapability($plugin, 'Fake\Ability')); $this->assertNull($this->pm->getPluginCapability($plugin, 'Fake\Ability'));
} }
@ -442,7 +441,6 @@ class PluginInstallerTest extends TestCase
return array(); return array();
})); }));
/** @phpstan-ignore-next-line */
$this->assertNull($this->pm->getPluginCapability($plugin, $capabilityApi)); $this->assertNull($this->pm->getPluginCapability($plugin, $capabilityApi));
} }