1
0
Fork 0

Add types to `Package` tests (#10245)

pull/10250/head
Martin Herndl 2021-11-01 21:44:12 +01:00 committed by GitHub
parent a155c076db
commit bcbd8fdb61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 159 additions and 21 deletions

View File

@ -302,6 +302,9 @@ class ArchivableFilesFinderTest extends TestCase
));
}
/**
* @return string[]
*/
protected function getArchivableFiles()
{
$files = array();
@ -316,11 +319,17 @@ class ArchivableFilesFinderTest extends TestCase
return $files;
}
/**
* @param string $command
*
* @return string[]
*/
protected function getArchivedFiles($command)
{
if (method_exists('Symfony\Component\Process\Process', 'fromShellCommandline')) {
$process = Process::fromShellCommandline($command, $this->sources);
} else {
// @phpstan-ignore-next-line symfony/process 2.8 accepts a string but not 5.3 which is used only for PHPStan
$process = new Process($command, $this->sources);
}
$process->run();
@ -339,6 +348,11 @@ class ArchivableFilesFinderTest extends TestCase
return $files;
}
/**
* @param string[] $expectedFiles
*
* @return void
*/
protected function assertArchivableFiles($expectedFiles)
{
$actualFiles = $this->getArchivableFiles();

View File

@ -98,6 +98,12 @@ class ArchiveManagerTest extends ArchiverTest
unlink($target);
}
/**
* @param string $format
* @param string|null $fileName
*
* @return string
*/
protected function getTargetName(CompletePackage $package, $format, $fileName = null)
{
if (null === $fileName) {
@ -111,6 +117,8 @@ class ArchiveManagerTest extends ArchiverTest
/**
* Create local git repository to run tests against!
*
* @return void
*/
protected function setupGitRepo()
{

View File

@ -18,7 +18,10 @@ use Composer\Test\TestCase;
class GitExcludeFilterTest extends TestCase
{
/**
* @dataProvider patterns
* @dataProvider providePatterns
*
* @param string $ignore
* @param mixed[] $expected
*/
public function testPatternEscape($ignore, $expected)
{
@ -27,7 +30,7 @@ class GitExcludeFilterTest extends TestCase
$this->assertEquals($expected, $filter->parseGitIgnoreLine($ignore));
}
public function patterns()
public function providePatterns()
{
return array(
array('app/config/parameters.yml', array('{(?=[^\.])app/(?=[^\.])config/(?=[^\.])parameters\.yml(?=$|/)}', false, false)),

View File

@ -18,7 +18,10 @@ use Composer\Test\TestCase;
class HgExcludeFilterTest extends TestCase
{
/**
* @dataProvider patterns
* @dataProvider providePatterns
*
* @param string $ignore
* @param mixed[] $expected
*/
public function testPatternEscape($ignore, $expected)
{
@ -27,7 +30,7 @@ class HgExcludeFilterTest extends TestCase
$this->assertEquals($expected, $filter->patternFromRegex($ignore));
}
public function patterns()
public function providePatterns()
{
return array(
array('.#', array('#.\\##', false, true)),

View File

@ -48,6 +48,8 @@ class PharArchiverTest extends ArchiverTest
/**
* Create a local dummy repository to run tests against!
*
* @return void
*/
protected function setupDummyRepo()
{
@ -63,13 +65,20 @@ class PharArchiverTest extends ArchiverTest
chdir($currentWorkDir);
}
/**
* @param string $path
* @param string $content
* @param string $currentWorkDir
*
* @return void
*/
protected function writeFile($path, $content, $currentWorkDir)
{
if (!file_exists(dirname($path))) {
mkdir(dirname($path), 0777, true);
}
$result = file_put_contents($path, 'a');
$result = file_put_contents($path, $content);
if (false === $result) {
chdir($currentWorkDir);
throw new \RuntimeException('Could not save file.');

View File

@ -39,6 +39,9 @@ class ZipArchiverTest extends ArchiverTest
);
}
/**
* @param array<string, string> $files
*/
public function testZipArchive(array $files = array())
{
if (!class_exists('ZipArchive')) {
@ -79,7 +82,10 @@ class ZipArchiverTest extends ArchiverTest
/**
* Create a local dummy repository to run tests against!
* @param array $files
*
* @param array<string, string|null> $files
*
* @return void
*/
protected function setupDummyRepo(array &$files)
{
@ -95,6 +101,13 @@ class ZipArchiverTest extends ArchiverTest
chdir($currentWorkDir);
}
/**
* @param string $path
* @param string $content
* @param string $currentWorkDir
*
* @return void
*/
protected function writeFile($path, $content, $currentWorkDir)
{
if (!file_exists(dirname($path))) {

View File

@ -44,14 +44,17 @@ class BasePackageTest extends TestCase
}
/**
* @dataProvider formattedVersions
* @dataProvider provideFormattedVersions
*
* @param bool $truncate
* @param string $expected
*/
public function testFormatVersionForDevPackage(BasePackage $package, $truncate, $expected)
{
$this->assertSame($expected, $package->getFullPrettyVersion($truncate));
}
public function formattedVersions()
public function provideFormattedVersions()
{
$data = array(
array(

View File

@ -35,8 +35,10 @@ class CompletePackageTest extends TestCase
}
/**
* Tests memory package naming semantics
* @dataProvider providerVersioningSchemes
*
* @param string $name
* @param string $version
*/
public function testPackageHasExpectedNamingSemantics($name, $version)
{
@ -47,8 +49,10 @@ class CompletePackageTest extends TestCase
}
/**
* Tests memory package versioning semantics
* @dataProvider providerVersioningSchemes
*
* @param string $name
* @param string $version
*/
public function testPackageHasExpectedVersioningSemantics($name, $version)
{
@ -60,8 +64,10 @@ class CompletePackageTest extends TestCase
}
/**
* Tests memory package marshalling/serialization semantics
* @dataProvider providerVersioningSchemes
*
* @param string $name
* @param string $version
*/
public function testPackageHasExpectedMarshallingSemantics($name, $version)
{

View File

@ -88,7 +88,12 @@ class ArrayDumperTest extends TestCase
}
/**
* @dataProvider getKeys
* @dataProvider provideKeys
*
* @param string $key
* @param mixed $value
* @param string $method
* @param mixed $expectedValue
*/
public function testKeys($key, $value, $method = null, $expectedValue = null)
{
@ -106,7 +111,7 @@ class ArrayDumperTest extends TestCase
$this->assertSame($expectedValue ?: $value, $config[$key]);
}
public function getKeys()
public function provideKeys()
{
return array(
array(
@ -239,6 +244,12 @@ class ArrayDumperTest extends TestCase
);
}
/**
* @param string $method
* @param mixed $value
*
* @return self
*/
private function packageExpects($method, $value)
{
$this->package

View File

@ -134,6 +134,11 @@ class ArrayLoaderTest extends TestCase
return array(array($validConfig));
}
/**
* @param array<string, mixed> $config
*
* @return array<string, mixed>
*/
protected function fixConfigWhenLoadConfigIsFalse($config)
{
$expectedConfig = $config;
@ -147,6 +152,8 @@ class ArrayLoaderTest extends TestCase
* allows require-dev libraries to have transport options included.
*
* @dataProvider parseDumpProvider
*
* @param array<string, mixed> $config
*/
public function testParseDumpDefaultLoadConfig($config)
{
@ -158,6 +165,8 @@ class ArrayLoaderTest extends TestCase
/**
* @dataProvider parseDumpProvider
*
* @param array<string, mixed> $config
*/
public function testParseDumpTrueLoadConfig($config)
{
@ -170,6 +179,8 @@ class ArrayLoaderTest extends TestCase
/**
* @dataProvider parseDumpProvider
*
* @param array<string, mixed> $config
*/
public function testParseDumpFalseLoadConfig($config)
{
@ -262,7 +273,7 @@ class ArrayLoaderTest extends TestCase
$this->assertFalse($package->isAbandoned());
}
public function pluginApiVersions()
public function providePluginApiVersions()
{
return array(
array('1.0'),
@ -284,7 +295,9 @@ class ArrayLoaderTest extends TestCase
}
/**
* @dataProvider pluginApiVersions
* @dataProvider providePluginApiVersions
*
* @param string $apiVersion
*/
public function testPluginApiVersionAreKeptAsDeclared($apiVersion)
{

View File

@ -15,6 +15,7 @@ namespace Composer\Test\Package\Loader;
use Composer\Config;
use Composer\Package\Loader\RootPackageLoader;
use Composer\Package\BasePackage;
use Composer\Package\RootAliasPackage;
use Composer\Package\RootPackage;
use Composer\Package\Version\VersionGuesser;
use Composer\Semver\VersionParser;
@ -24,6 +25,11 @@ use Prophecy\Argument;
class RootPackageLoaderTest extends TestCase
{
/**
* @param array<string, mixed> $data
*
* @return RootPackage|RootAliasPackage
*/
protected function loadPackage($data)
{
$manager = $this->getMockBuilder('Composer\\Repository\\RepositoryManager')

View File

@ -20,6 +20,8 @@ class ValidatingArrayLoaderTest extends TestCase
{
/**
* @dataProvider successProvider
*
* @param array<string, mixed> $config
*/
public function testLoadSuccess($config)
{
@ -206,6 +208,9 @@ class ValidatingArrayLoaderTest extends TestCase
/**
* @dataProvider errorProvider
*
* @param array<string, mixed> $config
* @param string[] $expectedErrors
*/
public function testLoadFailureThrowsException($config, $expectedErrors)
{
@ -224,6 +229,9 @@ class ValidatingArrayLoaderTest extends TestCase
/**
* @dataProvider warningProvider
*
* @param array<string, mixed> $config
* @param string[] $expectedWarnings
*/
public function testLoadWarnings($config, $expectedWarnings)
{
@ -239,6 +247,10 @@ class ValidatingArrayLoaderTest extends TestCase
/**
* @dataProvider warningProvider
*
* @param array<string, mixed> $config
* @param string[] $expectedWarnings
* @param bool $mustCheck
*/
public function testLoadSkipsWarningDataWhenIgnoringErrors($config, $expectedWarnings, $mustCheck = true)
{

View File

@ -255,6 +255,9 @@ class LockerTest extends TestCase
$this->assertFalse($locker->isFresh());
}
/**
* @return \PHPUnit\Framework\MockObject\MockObject&\Composer\Json\JsonFile
*/
private function createJsonFileMock()
{
return $this->getMockBuilder('Composer\Json\JsonFile')
@ -262,6 +265,9 @@ class LockerTest extends TestCase
->getMock();
}
/**
* @return \PHPUnit\Framework\MockObject\MockObject&\Composer\Installer\InstallationManager
*/
private function createInstallationManagerMock()
{
$mock = $this->getMockBuilder('Composer\Installer\InstallationManager')
@ -271,12 +277,20 @@ class LockerTest extends TestCase
return $mock;
}
/**
* @return \PHPUnit\Framework\MockObject\MockObject&\Composer\Package\PackageInterface
*/
private function createPackageMock()
{
return $this->getMockBuilder('Composer\Package\PackageInterface')
->getMock();
}
/**
* @param array<string, string> $customData
*
* @return false|string
*/
private function getJsonContent(array $customData = array())
{
$data = array_merge(array(

View File

@ -80,6 +80,9 @@ class RootAliasPackageTest extends TestCase
$this->assertNotEmpty($alias->getReplaces());
}
/**
* @return \Prophecy\Prophecy\ObjectProphecy
*/
protected function getMockRootPackageInterface()
{
$root = $this->prophesize('Composer\\Package\\RootPackage');

View File

@ -18,7 +18,10 @@ use Composer\Test\TestCase;
class VersionParserTest extends TestCase
{
/**
* @dataProvider getParseNameVersionPairsData
* @dataProvider provideParseNameVersionPairsData
*
* @param string[] $pairs
* @param array<array<string, string>> $result
*/
public function testParseNameVersionPairs($pairs, $result)
{
@ -27,7 +30,7 @@ class VersionParserTest extends TestCase
$this->assertSame($result, $versionParser->parseNameVersionPairs($pairs));
}
public function getParseNameVersionPairsData()
public function provideParseNameVersionPairsData()
{
return array(
array(array('php:^7.0'), array(array('name' => 'php', 'version' => '^7.0'))),
@ -39,14 +42,18 @@ class VersionParserTest extends TestCase
}
/**
* @dataProvider getIsUpgradeTests
* @dataProvider provideIsUpgradeTests
*
* @param string $from
* @param string $to
* @param bool $expected
*/
public function testIsUpgrade($from, $to, $expected)
{
$this->assertSame($expected, VersionParser::isUpgrade($from, $to));
}
public function getIsUpgradeTests()
public function provideIsUpgradeTests()
{
return array(
array('0.9.0.0', '1.0.0.0', true),

View File

@ -293,7 +293,12 @@ class VersionSelectorTest extends TestCase
}
/**
* @dataProvider getRecommendedRequireVersionPackages
* @dataProvider provideRecommendedRequireVersionPackages
*
* @param string $prettyVersion
* @param string $expectedVersion
* @param string|null $branchAlias
* @param string $packageName
*/
public function testFindRecommendedRequireVersion($prettyVersion, $expectedVersion, $branchAlias = null, $packageName = 'foo/bar')
{
@ -313,7 +318,7 @@ class VersionSelectorTest extends TestCase
$this->assertSame($expectedVersion, $recommended);
}
public function getRecommendedRequireVersionPackages()
public function provideRecommendedRequireVersionPackages()
{
return array(
// real version, expected recommendation, [branch-alias], [pkg name]
@ -353,6 +358,11 @@ class VersionSelectorTest extends TestCase
);
}
/**
* @param string $version
*
* @return Package
*/
private function createPackage($version)
{
$parser = new VersionParser();
@ -360,6 +370,9 @@ class VersionSelectorTest extends TestCase
return new Package('foo', $parser->normalize($version), $version);
}
/**
* @return \PHPUnit\Framework\MockObject\MockObject&\Composer\Repository\RepositorySet
*/
private function createMockRepositorySet()
{
return $this->getMockBuilder('Composer\Repository\RepositorySet')