1
0
Fork 0

Add types to `Repository` tests (#10227)

pull/10233/head
Martin Herndl 2021-10-27 15:29:52 +02:00 committed by GitHub
parent 3d9e9ba66f
commit d51c7685da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 133 additions and 23 deletions

View File

@ -24,6 +24,9 @@ class ComposerRepositoryTest extends TestCase
{ {
/** /**
* @dataProvider loadDataProvider * @dataProvider loadDataProvider
*
* @param mixed[] $expected
* @param array<string, mixed> $repoPackages
*/ */
public function testLoadData(array $expected, 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()); $this->assertSame($packages['2'], $packages['2-alias']->getAliasOf());
} }
public function isPackageAcceptableReturnTrue()
{
return true;
}
public function testSearchWithType() public function testSearchWithType()
{ {
$repoConfig = array( $repoConfig = array(
@ -219,7 +217,7 @@ class ComposerRepositoryTest extends TestCase
} }
/** /**
* @dataProvider canonicalizeUrlProvider * @dataProvider provideCanonicalizeUrlTestCases
* *
* @param string $expected * @param string $expected
* @param string $url * @param string $url
@ -249,7 +247,7 @@ class ComposerRepositoryTest extends TestCase
$this->assertSame($expected, $method->invoke($repository, $url)); $this->assertSame($expected, $method->invoke($repository, $url));
} }
public function canonicalizeUrlProvider() public function provideCanonicalizeUrlTestCases()
{ {
return array( return array(
array( array(

View File

@ -128,6 +128,9 @@ class CompositeRepositoryTest extends TestCase
/** /**
* @dataProvider provideMethodCalls * @dataProvider provideMethodCalls
*
* @param string $method
* @param mixed[] $args
*/ */
public function testNoRepositories($method, $args) public function testNoRepositories($method, $args)
{ {

View File

@ -20,8 +20,6 @@ use Composer\Util\Filesystem;
class FilesystemRepositoryTest extends TestCase class FilesystemRepositoryTest extends TestCase
{ {
private $root;
public function testRepositoryRead() public function testRepositoryRead()
{ {
$json = $this->createJsonFileMock(); $json = $this->createJsonFileMock();
@ -129,7 +127,6 @@ class FilesystemRepositoryTest extends TestCase
public function testRepositoryWritesInstalledPhp() public function testRepositoryWritesInstalledPhp()
{ {
$dir = $this->getUniqueTmpDirectory(); $dir = $this->getUniqueTmpDirectory();
$this->root = $dir;
chdir($dir); chdir($dir);
$json = new JsonFile($dir.'/installed.json'); $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'); $this->assertSame(require __DIR__.'/Fixtures/installed.php', require $dir.'/installed.php');
} }
/**
* @return \PHPUnit\Framework\MockObject\MockObject&\Composer\Json\JsonFile
*/
private function createJsonFileMock() private function createJsonFileMock()
{ {
return $this->getMockBuilder('Composer\Json\JsonFile') return $this->getMockBuilder('Composer\Json\JsonFile')

View File

@ -35,7 +35,10 @@ class FilterRepositoryTest extends TestCase
} }
/** /**
* @dataProvider repoMatchingTests * @dataProvider provideRepoMatchingTestCases
*
* @param string[] $expected
* @param array{only?: array<string>, exclude?: array<string>, canonical?: bool} $config
*/ */
public function testRepoMatching($expected, $config) public function testRepoMatching($expected, $config)
{ {
@ -47,7 +50,7 @@ class FilterRepositoryTest extends TestCase
}, $packages)); }, $packages));
} }
public static function repoMatchingTests() public static function provideRepoMatchingTestCases()
{ {
return array( return array(
array(array('foo/aaa', 'foo/bbb'), array('only' => array('foo/*'))), array(array('foo/aaa', 'foo/bbb'), array('only' => array('foo/*'))),

View File

@ -12,6 +12,7 @@
namespace Composer\Test\Repository; namespace Composer\Test\Repository;
use Composer\Package\Link;
use Composer\Package\Package; use Composer\Package\Package;
use Composer\Package\PackageInterface; use Composer\Package\PackageInterface;
use Composer\Repository\PlatformRepository; use Composer\Repository\PlatformRepository;
@ -35,7 +36,7 @@ class PlatformRepositoryTest extends TestCase
self::assertSame('2.1.0', $hhvm->getPrettyVersion()); self::assertSame('2.1.0', $hhvm->getPrettyVersion());
} }
public function getPhpFlavorTestCases() public function providePhpFlavorTestCases()
{ {
return array( return array(
array( array(
@ -112,7 +113,13 @@ class PlatformRepositoryTest extends TestCase
); );
} }
/** @dataProvider getPhpFlavorTestCases */ /**
* @dataProvider providePhpFlavorTestCases
*
* @param array<string, mixed> $constants
* @param array<string, string> $packages
* @param array<string, mixed> $functions
*/
public function testPhpVersion(array $constants, array $packages, array $functions = array()) public function testPhpVersion(array $constants, array $packages, array $functions = array())
{ {
$runtime = $this->getMockBuilder('Composer\Platform\Runtime')->getMock(); $runtime = $this->getMockBuilder('Composer\Platform\Runtime')->getMock();
@ -178,7 +185,7 @@ class PlatformRepositoryTest extends TestCase
self::assertNull($package); self::assertNull($package);
} }
public static function getLibraryTestCases() public static function provideLibraryTestCases()
{ {
return array( return array(
'amqp' => array( 'amqp' => array(
@ -1074,7 +1081,7 @@ Linked Version => 1.2.11',
} }
/** /**
* @dataProvider getLibraryTestCases * @dataProvider provideLibraryTestCases
* *
* @param string|string[] $extensions * @param string|string[] $extensions
* @param string|null $info * @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) private function assertPackageLinks($context, array $expectedLinks, PackageInterface $sourcePackage, array $links)
{ {
self::assertCount(count($expectedLinks), $links, sprintf('%s: expected package count to match', $context)); 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'; const STUB_VERSION = '32.0.1';
/**
* @param string $locale
* @param string $bundleName
* @param bool $fallback
*
* @return ResourceBundleStub
*/
public static function create($locale, $bundleName, $fallback) public static function create($locale, $bundleName, $fallback)
{ {
Assert::assertSame(3, func_num_args()); Assert::assertSame(3, func_num_args());
@ -1216,6 +1237,11 @@ class ResourceBundleStub
return new self(); return new self();
} }
/**
* @param string|int $field
*
* @return string
*/
public function get($field) public function get($field)
{ {
Assert::assertSame(1, func_num_args()); Assert::assertSame(1, func_num_args());
@ -1227,13 +1253,23 @@ class ResourceBundleStub
class ImagickStub class ImagickStub
{ {
/**
* @var string
*/
private $versionString; private $versionString;
/**
* @param string $versionString
*/
public function __construct($versionString) public function __construct($versionString)
{ {
$this->versionString = $versionString; $this->versionString = $versionString;
} }
/**
* @return array<string, string>
* @phpstan-return array{versionString: string}
*/
public function getVersion() public function getVersion()
{ {
Assert::assertSame(0, func_num_args()); Assert::assertSame(0, func_num_args());

View File

@ -51,6 +51,13 @@ class RepositoryFactoryTest extends TestCase
/** /**
* @dataProvider generateRepositoryNameProvider * @dataProvider generateRepositoryNameProvider
*
* @param int|string $index
* @param array<string, string> $config
* @param array<string, mixed> $existingRepos
* @param int|string $expected
*
* @phpstan-param array{url?: string} $config
*/ */
public function testGenerateRepositoryName($index, array $config, array $existingRepos, $expected) public function testGenerateRepositoryName($index, array $config, array $existingRepos, $expected)
{ {

View File

@ -18,6 +18,7 @@ use Composer\Util\Filesystem;
class RepositoryManagerTest extends TestCase class RepositoryManagerTest extends TestCase
{ {
/** @var string */
protected $tmpdir; protected $tmpdir;
public function setUp() public function setUp()
@ -51,7 +52,11 @@ class RepositoryManagerTest extends TestCase
} }
/** /**
* @dataProvider creationCases * @dataProvider provideRepoCreationTestCases
*
* @param string $type
* @param array<string, mixed> $options
* @param string|null $exception
*/ */
public function testRepoCreation($type, $options, $exception = null) public function testRepoCreation($type, $options, $exception = null)
{ {
@ -89,7 +94,7 @@ class RepositoryManagerTest extends TestCase
$this->assertInstanceOf('Composer\Repository\RepositoryInterface', $rm->createRepository($type, $options)); $this->assertInstanceOf('Composer\Repository\RepositoryInterface', $rm->createRepository($type, $options));
} }
public function creationCases() public function provideRepoCreationTestCases()
{ {
$cases = array( $cases = array(
array('composer', array('url' => 'http://example.org')), array('composer', array('url' => 'http://example.org')),

View File

@ -56,6 +56,9 @@ class FossilDriverTest extends TestCase
/** /**
* @dataProvider supportProvider * @dataProvider supportProvider
*
* @param string $url
* @param bool $assertion
*/ */
public function testSupport($url, $assertion) public function testSupport($url, $assertion)
{ {

View File

@ -60,8 +60,10 @@ class GitBitbucketDriverTest extends TestCase
} }
/** /**
* @param array $repoConfig * @param array<string, mixed> $repoConfig
* @return GitBitbucketDriver * @return GitBitbucketDriver
*
* @phpstan-param array{url: string}&array<string, mixed> $repoConfig
*/ */
private function getDriver(array $repoConfig) private function getDriver(array $repoConfig)
{ {

View File

@ -24,7 +24,9 @@ use Symfony\Component\Process\Process;
class GitHubDriverTest extends TestCase class GitHubDriverTest extends TestCase
{ {
/** @var string */
private $home; private $home;
/** @var Config */
private $config; private $config;
public function setUp() public function setUp()
@ -340,6 +342,13 @@ class GitHubDriverTest extends TestCase
$process->assertComplete($this); $process->assertComplete($this);
} }
/**
* @param string|object $object
* @param string $attribute
* @param mixed $value
*
* @return void
*/
protected function setAttribute($object, $attribute, $value) protected function setAttribute($object, $attribute, $value)
{ {
$attr = new \ReflectionProperty($object, $attribute); $attr = new \ReflectionProperty($object, $attribute);

View File

@ -72,7 +72,7 @@ class GitLabDriverTest extends TestCase
$fs->removeDirectory($this->home); $fs->removeDirectory($this->home);
} }
public function getInitializeUrls() public function provideInitializeUrls()
{ {
return array( return array(
array('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject'), 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) 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) 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) public function testInitializePublicProjectAsAnonymous($url, $apiUrl)
{ {
@ -417,6 +426,9 @@ JSON;
/** /**
* @group gitlabHttpPort * @group gitlabHttpPort
* @dataProvider dataForTestSupports * @dataProvider dataForTestSupports
*
* @param string $url
* @param bool $expected
*/ */
public function testSupports($url, $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'); $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) private function mockResponse($url, $options, $return)
{ {
return $this->httpDownloader return $this->httpDownloader

View File

@ -46,6 +46,8 @@ class HgDriverTest extends TestCase
/** /**
* @dataProvider supportsDataProvider * @dataProvider supportsDataProvider
*
* @param string $repositoryUrl
*/ */
public function testSupports($repositoryUrl) public function testSupports($repositoryUrl)
{ {

View File

@ -85,6 +85,9 @@ class PerforceDriverTest extends TestCase
$fs->removeDirectory($this->testPath); $fs->removeDirectory($this->testPath);
} }
/**
* @return void
*/
protected function overrideDriverInternalPerforce(Perforce $perforce) protected function overrideDriverInternalPerforce(Perforce $perforce)
{ {
$reflectionClass = new \ReflectionClass($this->driver); $reflectionClass = new \ReflectionClass($this->driver);
@ -93,6 +96,11 @@ class PerforceDriverTest extends TestCase
$property->setValue($this->driver, $perforce); $property->setValue($this->driver, $perforce);
} }
/**
* @param string $testPath
*
* @return Config
*/
protected function getTestConfig($testPath) protected function getTestConfig($testPath)
{ {
$config = new Config(); $config = new Config();
@ -101,16 +109,25 @@ class PerforceDriverTest extends TestCase
return $config; return $config;
} }
/**
* @return \PHPUnit\Framework\MockObject\MockObject&\Composer\IO\IOInterface
*/
protected function getMockIOInterface() protected function getMockIOInterface()
{ {
return $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); return $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
} }
/**
* @return \PHPUnit\Framework\MockObject\MockObject&\Composer\Util\HttpDownloader
*/
protected function getMockHttpDownloader() protected function getMockHttpDownloader()
{ {
return $this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock(); return $this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock();
} }
/**
* @return \PHPUnit\Framework\MockObject\MockObject&\Composer\Util\Perforce
*/
protected function getMockPerforce() protected function getMockPerforce()
{ {
$methods = array('p4login', 'checkStream', 'writeP4ClientSpec', 'connectClient', 'getComposerInformation', 'cleanupClientSpec'); $methods = array('p4login', 'checkStream', 'writeP4ClientSpec', 'connectClient', 'getComposerInformation', 'cleanupClientSpec');

View File

@ -85,6 +85,9 @@ class SvnDriverTest extends TestCase
/** /**
* @dataProvider supportProvider * @dataProvider supportProvider
*
* @param string $url
* @param bool $assertion
*/ */
public function testSupport($url, $assertion) public function testSupport($url, $assertion)
{ {

View File

@ -39,6 +39,9 @@ class VcsRepositoryTest extends TestCase
*/ */
private $skipped = null; private $skipped = null;
/**
* @return void
*/
protected function initialize() protected function initialize()
{ {
$locator = new ExecutableFinder(); $locator = new ExecutableFinder();