From d51c7685dad75f97f99609a4d54e694b63301064 Mon Sep 17 00:00:00 2001 From: Martin Herndl Date: Wed, 27 Oct 2021 15:29:52 +0200 Subject: [PATCH] Add types to `Repository` tests (#10227) --- .../Repository/ComposerRepositoryTest.php | 12 +++-- .../Repository/CompositeRepositoryTest.php | 3 ++ .../Repository/FilesystemRepositoryTest.php | 6 +-- .../Test/Repository/FilterRepositoryTest.php | 7 ++- .../Repository/PlatformRepositoryTest.php | 44 +++++++++++++++++-- .../Test/Repository/RepositoryFactoryTest.php | 7 +++ .../Test/Repository/RepositoryManagerTest.php | 9 +++- .../Test/Repository/Vcs/FossilDriverTest.php | 3 ++ .../Repository/Vcs/GitBitbucketDriverTest.php | 4 +- .../Test/Repository/Vcs/GitHubDriverTest.php | 9 ++++ .../Test/Repository/Vcs/GitLabDriverTest.php | 27 ++++++++++-- .../Test/Repository/Vcs/HgDriverTest.php | 2 + .../Repository/Vcs/PerforceDriverTest.php | 17 +++++++ .../Test/Repository/Vcs/SvnDriverTest.php | 3 ++ .../Test/Repository/VcsRepositoryTest.php | 3 ++ 15 files changed, 133 insertions(+), 23 deletions(-) diff --git a/tests/Composer/Test/Repository/ComposerRepositoryTest.php b/tests/Composer/Test/Repository/ComposerRepositoryTest.php index d7e2ab1f7..6d2194728 100644 --- a/tests/Composer/Test/Repository/ComposerRepositoryTest.php +++ b/tests/Composer/Test/Repository/ComposerRepositoryTest.php @@ -24,6 +24,9 @@ class ComposerRepositoryTest extends TestCase { /** * @dataProvider loadDataProvider + * + * @param mixed[] $expected + * @param array $repoPackages */ public function testLoadData(array $expected, array $repoPackages) { @@ -161,11 +164,6 @@ class ComposerRepositoryTest extends TestCase $this->assertSame($packages['2'], $packages['2-alias']->getAliasOf()); } - public function isPackageAcceptableReturnTrue() - { - return true; - } - public function testSearchWithType() { $repoConfig = array( @@ -219,7 +217,7 @@ class ComposerRepositoryTest extends TestCase } /** - * @dataProvider canonicalizeUrlProvider + * @dataProvider provideCanonicalizeUrlTestCases * * @param string $expected * @param string $url @@ -249,7 +247,7 @@ class ComposerRepositoryTest extends TestCase $this->assertSame($expected, $method->invoke($repository, $url)); } - public function canonicalizeUrlProvider() + public function provideCanonicalizeUrlTestCases() { return array( array( diff --git a/tests/Composer/Test/Repository/CompositeRepositoryTest.php b/tests/Composer/Test/Repository/CompositeRepositoryTest.php index 978587133..c6a1e3dc6 100644 --- a/tests/Composer/Test/Repository/CompositeRepositoryTest.php +++ b/tests/Composer/Test/Repository/CompositeRepositoryTest.php @@ -128,6 +128,9 @@ class CompositeRepositoryTest extends TestCase /** * @dataProvider provideMethodCalls + * + * @param string $method + * @param mixed[] $args */ public function testNoRepositories($method, $args) { diff --git a/tests/Composer/Test/Repository/FilesystemRepositoryTest.php b/tests/Composer/Test/Repository/FilesystemRepositoryTest.php index 0ea13fce6..a5ec5f73c 100644 --- a/tests/Composer/Test/Repository/FilesystemRepositoryTest.php +++ b/tests/Composer/Test/Repository/FilesystemRepositoryTest.php @@ -20,8 +20,6 @@ use Composer\Util\Filesystem; class FilesystemRepositoryTest extends TestCase { - private $root; - public function testRepositoryRead() { $json = $this->createJsonFileMock(); @@ -129,7 +127,6 @@ class FilesystemRepositoryTest extends TestCase public function testRepositoryWritesInstalledPhp() { $dir = $this->getUniqueTmpDirectory(); - $this->root = $dir; chdir($dir); $json = new JsonFile($dir.'/installed.json'); @@ -196,6 +193,9 @@ class FilesystemRepositoryTest extends TestCase $this->assertSame(require __DIR__.'/Fixtures/installed.php', require $dir.'/installed.php'); } + /** + * @return \PHPUnit\Framework\MockObject\MockObject&\Composer\Json\JsonFile + */ private function createJsonFileMock() { return $this->getMockBuilder('Composer\Json\JsonFile') diff --git a/tests/Composer/Test/Repository/FilterRepositoryTest.php b/tests/Composer/Test/Repository/FilterRepositoryTest.php index bf2953a08..930d44e02 100644 --- a/tests/Composer/Test/Repository/FilterRepositoryTest.php +++ b/tests/Composer/Test/Repository/FilterRepositoryTest.php @@ -35,7 +35,10 @@ class FilterRepositoryTest extends TestCase } /** - * @dataProvider repoMatchingTests + * @dataProvider provideRepoMatchingTestCases + * + * @param string[] $expected + * @param array{only?: array, exclude?: array, canonical?: bool} $config */ public function testRepoMatching($expected, $config) { @@ -47,7 +50,7 @@ class FilterRepositoryTest extends TestCase }, $packages)); } - public static function repoMatchingTests() + public static function provideRepoMatchingTestCases() { return array( array(array('foo/aaa', 'foo/bbb'), array('only' => array('foo/*'))), diff --git a/tests/Composer/Test/Repository/PlatformRepositoryTest.php b/tests/Composer/Test/Repository/PlatformRepositoryTest.php index 30a464b24..6a77fa318 100644 --- a/tests/Composer/Test/Repository/PlatformRepositoryTest.php +++ b/tests/Composer/Test/Repository/PlatformRepositoryTest.php @@ -12,6 +12,7 @@ namespace Composer\Test\Repository; +use Composer\Package\Link; use Composer\Package\Package; use Composer\Package\PackageInterface; use Composer\Repository\PlatformRepository; @@ -35,7 +36,7 @@ class PlatformRepositoryTest extends TestCase self::assertSame('2.1.0', $hhvm->getPrettyVersion()); } - public function getPhpFlavorTestCases() + public function providePhpFlavorTestCases() { return array( array( @@ -112,7 +113,13 @@ class PlatformRepositoryTest extends TestCase ); } - /** @dataProvider getPhpFlavorTestCases */ + /** + * @dataProvider providePhpFlavorTestCases + * + * @param array $constants + * @param array $packages + * @param array $functions + */ public function testPhpVersion(array $constants, array $packages, array $functions = array()) { $runtime = $this->getMockBuilder('Composer\Platform\Runtime')->getMock(); @@ -178,7 +185,7 @@ class PlatformRepositoryTest extends TestCase self::assertNull($package); } - public static function getLibraryTestCases() + public static function provideLibraryTestCases() { return array( 'amqp' => array( @@ -1074,7 +1081,7 @@ Linked Version => 1.2.11', } /** - * @dataProvider getLibraryTestCases + * @dataProvider provideLibraryTestCases * * @param string|string[] $extensions * @param string|null $info @@ -1190,6 +1197,13 @@ Linked Version => 1.2.11', } } + /** + * @param string $context + * @param string[] $expectedLinks + * @param Link[] $links + * + * @return void + */ private function assertPackageLinks($context, array $expectedLinks, PackageInterface $sourcePackage, array $links) { self::assertCount(count($expectedLinks), $links, sprintf('%s: expected package count to match', $context)); @@ -1206,6 +1220,13 @@ class ResourceBundleStub { const STUB_VERSION = '32.0.1'; + /** + * @param string $locale + * @param string $bundleName + * @param bool $fallback + * + * @return ResourceBundleStub + */ public static function create($locale, $bundleName, $fallback) { Assert::assertSame(3, func_num_args()); @@ -1216,6 +1237,11 @@ class ResourceBundleStub return new self(); } + /** + * @param string|int $field + * + * @return string + */ public function get($field) { Assert::assertSame(1, func_num_args()); @@ -1227,13 +1253,23 @@ class ResourceBundleStub class ImagickStub { + /** + * @var string + */ private $versionString; + /** + * @param string $versionString + */ public function __construct($versionString) { $this->versionString = $versionString; } + /** + * @return array + * @phpstan-return array{versionString: string} + */ public function getVersion() { Assert::assertSame(0, func_num_args()); diff --git a/tests/Composer/Test/Repository/RepositoryFactoryTest.php b/tests/Composer/Test/Repository/RepositoryFactoryTest.php index 20b1fad28..f64bf0aca 100644 --- a/tests/Composer/Test/Repository/RepositoryFactoryTest.php +++ b/tests/Composer/Test/Repository/RepositoryFactoryTest.php @@ -51,6 +51,13 @@ class RepositoryFactoryTest extends TestCase /** * @dataProvider generateRepositoryNameProvider + * + * @param int|string $index + * @param array $config + * @param array $existingRepos + * @param int|string $expected + * + * @phpstan-param array{url?: string} $config */ public function testGenerateRepositoryName($index, array $config, array $existingRepos, $expected) { diff --git a/tests/Composer/Test/Repository/RepositoryManagerTest.php b/tests/Composer/Test/Repository/RepositoryManagerTest.php index c70e395f1..a7f07c85a 100644 --- a/tests/Composer/Test/Repository/RepositoryManagerTest.php +++ b/tests/Composer/Test/Repository/RepositoryManagerTest.php @@ -18,6 +18,7 @@ use Composer\Util\Filesystem; class RepositoryManagerTest extends TestCase { + /** @var string */ protected $tmpdir; public function setUp() @@ -51,7 +52,11 @@ class RepositoryManagerTest extends TestCase } /** - * @dataProvider creationCases + * @dataProvider provideRepoCreationTestCases + * + * @param string $type + * @param array $options + * @param string|null $exception */ public function testRepoCreation($type, $options, $exception = null) { @@ -89,7 +94,7 @@ class RepositoryManagerTest extends TestCase $this->assertInstanceOf('Composer\Repository\RepositoryInterface', $rm->createRepository($type, $options)); } - public function creationCases() + public function provideRepoCreationTestCases() { $cases = array( array('composer', array('url' => 'http://example.org')), diff --git a/tests/Composer/Test/Repository/Vcs/FossilDriverTest.php b/tests/Composer/Test/Repository/Vcs/FossilDriverTest.php index d43afb7f4..501893cbf 100644 --- a/tests/Composer/Test/Repository/Vcs/FossilDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/FossilDriverTest.php @@ -56,6 +56,9 @@ class FossilDriverTest extends TestCase /** * @dataProvider supportProvider + * + * @param string $url + * @param bool $assertion */ public function testSupport($url, $assertion) { diff --git a/tests/Composer/Test/Repository/Vcs/GitBitbucketDriverTest.php b/tests/Composer/Test/Repository/Vcs/GitBitbucketDriverTest.php index 23c7fb766..89cc7f7f5 100644 --- a/tests/Composer/Test/Repository/Vcs/GitBitbucketDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/GitBitbucketDriverTest.php @@ -60,8 +60,10 @@ class GitBitbucketDriverTest extends TestCase } /** - * @param array $repoConfig + * @param array $repoConfig * @return GitBitbucketDriver + * + * @phpstan-param array{url: string}&array $repoConfig */ private function getDriver(array $repoConfig) { diff --git a/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php b/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php index 38dd7bc34..fb07d34f2 100644 --- a/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/GitHubDriverTest.php @@ -24,7 +24,9 @@ use Symfony\Component\Process\Process; class GitHubDriverTest extends TestCase { + /** @var string */ private $home; + /** @var Config */ private $config; public function setUp() @@ -340,6 +342,13 @@ class GitHubDriverTest extends TestCase $process->assertComplete($this); } + /** + * @param string|object $object + * @param string $attribute + * @param mixed $value + * + * @return void + */ protected function setAttribute($object, $attribute, $value) { $attr = new \ReflectionProperty($object, $attribute); diff --git a/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php b/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php index e6374a545..f06a26526 100644 --- a/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php @@ -72,7 +72,7 @@ class GitLabDriverTest extends TestCase $fs->removeDirectory($this->home); } - public function getInitializeUrls() + public function provideInitializeUrls() { return array( array('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject'), @@ -82,7 +82,10 @@ class GitLabDriverTest extends TestCase } /** - * @dataProvider getInitializeUrls + * @dataProvider provideInitializeUrls + * + * @param string $url + * @param string $apiUrl */ public function testInitialize($url, $apiUrl) { @@ -119,7 +122,10 @@ JSON; } /** - * @dataProvider getInitializeUrls + * @dataProvider provideInitializeUrls + * + * @param string $url + * @param string $apiUrl */ public function testInitializePublicProject($url, $apiUrl) { @@ -156,7 +162,10 @@ JSON; } /** - * @dataProvider getInitializeUrls + * @dataProvider provideInitializeUrls + * + * @param string $url + * @param string $apiUrl */ public function testInitializePublicProjectAsAnonymous($url, $apiUrl) { @@ -417,6 +426,9 @@ JSON; /** * @group gitlabHttpPort * @dataProvider dataForTestSupports + * + * @param string $url + * @param bool $expected */ public function testSupports($url, $expected) { @@ -608,6 +620,13 @@ JSON; $this->assertEquals('https://gitlab.com/mygroup/myproject.git', $driver->getRepositoryUrl(), 'Repository URL matches config request for http not git'); } + /** + * @param string $url + * @param mixed[] $options + * @param string|null $return + * + * @return \Prophecy\Prophecy\MethodProphecy + */ private function mockResponse($url, $options, $return) { return $this->httpDownloader diff --git a/tests/Composer/Test/Repository/Vcs/HgDriverTest.php b/tests/Composer/Test/Repository/Vcs/HgDriverTest.php index d7bae8a11..2fcd27bdf 100644 --- a/tests/Composer/Test/Repository/Vcs/HgDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/HgDriverTest.php @@ -46,6 +46,8 @@ class HgDriverTest extends TestCase /** * @dataProvider supportsDataProvider + * + * @param string $repositoryUrl */ public function testSupports($repositoryUrl) { diff --git a/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php b/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php index 520c85e32..6dfbc3f26 100644 --- a/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/PerforceDriverTest.php @@ -85,6 +85,9 @@ class PerforceDriverTest extends TestCase $fs->removeDirectory($this->testPath); } + /** + * @return void + */ protected function overrideDriverInternalPerforce(Perforce $perforce) { $reflectionClass = new \ReflectionClass($this->driver); @@ -93,6 +96,11 @@ class PerforceDriverTest extends TestCase $property->setValue($this->driver, $perforce); } + /** + * @param string $testPath + * + * @return Config + */ protected function getTestConfig($testPath) { $config = new Config(); @@ -101,16 +109,25 @@ class PerforceDriverTest extends TestCase return $config; } + /** + * @return \PHPUnit\Framework\MockObject\MockObject&\Composer\IO\IOInterface + */ protected function getMockIOInterface() { return $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); } + /** + * @return \PHPUnit\Framework\MockObject\MockObject&\Composer\Util\HttpDownloader + */ protected function getMockHttpDownloader() { return $this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock(); } + /** + * @return \PHPUnit\Framework\MockObject\MockObject&\Composer\Util\Perforce + */ protected function getMockPerforce() { $methods = array('p4login', 'checkStream', 'writeP4ClientSpec', 'connectClient', 'getComposerInformation', 'cleanupClientSpec'); diff --git a/tests/Composer/Test/Repository/Vcs/SvnDriverTest.php b/tests/Composer/Test/Repository/Vcs/SvnDriverTest.php index fe3e896bb..b99658ebf 100644 --- a/tests/Composer/Test/Repository/Vcs/SvnDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/SvnDriverTest.php @@ -85,6 +85,9 @@ class SvnDriverTest extends TestCase /** * @dataProvider supportProvider + * + * @param string $url + * @param bool $assertion */ public function testSupport($url, $assertion) { diff --git a/tests/Composer/Test/Repository/VcsRepositoryTest.php b/tests/Composer/Test/Repository/VcsRepositoryTest.php index d517422fb..1e0a541fe 100644 --- a/tests/Composer/Test/Repository/VcsRepositoryTest.php +++ b/tests/Composer/Test/Repository/VcsRepositoryTest.php @@ -39,6 +39,9 @@ class VcsRepositoryTest extends TestCase */ private $skipped = null; + /** + * @return void + */ protected function initialize() { $locator = new ExecutableFinder();