Add types to `Repository` tests (#10227)

main
Martin Herndl 3 years ago committed by GitHub
parent 3d9e9ba66f
commit d51c7685da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -24,6 +24,9 @@ class ComposerRepositoryTest extends TestCase
{
/**
* @dataProvider loadDataProvider
*
* @param mixed[] $expected
* @param array<string, mixed> $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(

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

@ -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')

@ -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)
{
@ -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/*'))),

@ -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<string, mixed> $constants
* @param array<string, string> $packages
* @param array<string, mixed> $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<string, string>
* @phpstan-return array{versionString: string}
*/
public function getVersion()
{
Assert::assertSame(0, func_num_args());

@ -51,6 +51,13 @@ class RepositoryFactoryTest extends TestCase
/**
* @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)
{

@ -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<string, mixed> $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')),

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

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

@ -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);

@ -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

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

@ -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');

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

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

Loading…
Cancel
Save