1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-09 16:42:57 +00:00

Add types to Util tests (#10228)

This commit is contained in:
Martin Herndl 2021-10-27 16:18:46 +02:00 committed by GitHub
parent d51c7685da
commit 2992e8651a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 268 additions and 49 deletions

View file

@ -296,7 +296,7 @@ class Perforce
} }
/** /**
* @param string $user * @param string|null $user
* *
* @return void * @return void
*/ */

View file

@ -446,7 +446,7 @@ class ProcessExecutor
/** /**
* Escapes a string to be used as a shell argument. * Escapes a string to be used as a shell argument.
* *
* @param ?string $argument The argument that will be escaped * @param string|false|null $argument The argument that will be escaped
* *
* @return string The escaped argument * @return string The escaped argument
*/ */
@ -466,7 +466,7 @@ class ProcessExecutor
* Modified from https://github.com/johnstevenson/winbox-args * Modified from https://github.com/johnstevenson/winbox-args
* MIT Licensed (c) John Stevenson <john-stevenson@blueyonder.co.uk> * MIT Licensed (c) John Stevenson <john-stevenson@blueyonder.co.uk>
* *
* @param ?string $argument * @param string|false|null $argument
* *
* @return string * @return string
*/ */

View file

@ -22,13 +22,13 @@ use Composer\Util\Bitbucket;
*/ */
class AuthHelperTest extends TestCase class AuthHelperTest extends TestCase
{ {
/** @type \Composer\IO\IOInterface|\PHPUnit_Framework_MockObject_MockObject */ /** @var \Composer\IO\IOInterface&\PHPUnit\Framework\MockObject\MockObject */
private $io; private $io;
/** @type \Composer\Config|\PHPUnit_Framework_MockObject_MockObject */ /** @var \Composer\Config&\PHPUnit\Framework\MockObject\MockObject */
private $config; private $config;
/** @type AuthHelper */ /** @var AuthHelper */
private $authHelper; private $authHelper;
protected function setUp() protected function setUp()
@ -295,7 +295,9 @@ class AuthHelperTest extends TestCase
* *
* @param string $url * @param string $url
* @param string $origin * @param string $origin
* @param array $auth * @param array<string, string|null> $auth
*
* @phpstan-param array{username: string|null, password: string|null} $auth
*/ */
public function testAddAuthenticationHeaderWithBasicHttpAuthentication($url, $origin, $auth) public function testAddAuthenticationHeaderWithBasicHttpAuthentication($url, $origin, $auth)
{ {
@ -358,7 +360,7 @@ class AuthHelperTest extends TestCase
'password' => 'my_password', 'password' => 'my_password',
); );
/** @var \Composer\Config\ConfigSourceInterface|\PHPUnit_Framework_MockObject_MockObject $configSource */ /** @var \Composer\Config\ConfigSourceInterface&\PHPUnit\Framework\MockObject\MockObject $configSource */
$configSource = $this $configSource = $this
->getMockBuilder('Composer\Config\ConfigSourceInterface') ->getMockBuilder('Composer\Config\ConfigSourceInterface')
->disableOriginalConstructor() ->disableOriginalConstructor()
@ -392,7 +394,7 @@ class AuthHelperTest extends TestCase
$answer = 'y'; $answer = 'y';
$configSourceName = 'https://api.gitlab.com/source'; $configSourceName = 'https://api.gitlab.com/source';
/** @var \Composer\Config\ConfigSourceInterface|\PHPUnit_Framework_MockObject_MockObject $configSource */ /** @var \Composer\Config\ConfigSourceInterface&\PHPUnit\Framework\MockObject\MockObject $configSource */
$configSource = $this $configSource = $this
->getMockBuilder('Composer\Config\ConfigSourceInterface') ->getMockBuilder('Composer\Config\ConfigSourceInterface')
->disableOriginalConstructor() ->disableOriginalConstructor()
@ -440,7 +442,7 @@ class AuthHelperTest extends TestCase
$answer = 'n'; $answer = 'n';
$configSourceName = 'https://api.gitlab.com/source'; $configSourceName = 'https://api.gitlab.com/source';
/** @var \Composer\Config\ConfigSourceInterface|\PHPUnit_Framework_MockObject_MockObject $configSource */ /** @var \Composer\Config\ConfigSourceInterface&\PHPUnit\Framework\MockObject\MockObject $configSource */
$configSource = $this $configSource = $this
->getMockBuilder('Composer\Config\ConfigSourceInterface') ->getMockBuilder('Composer\Config\ConfigSourceInterface')
->disableOriginalConstructor() ->disableOriginalConstructor()
@ -480,7 +482,7 @@ class AuthHelperTest extends TestCase
$answer = 'invalid'; $answer = 'invalid';
$configSourceName = 'https://api.gitlab.com/source'; $configSourceName = 'https://api.gitlab.com/source';
/** @var \Composer\Config\ConfigSourceInterface|\PHPUnit_Framework_MockObject_MockObject $configSource */ /** @var \Composer\Config\ConfigSourceInterface&\PHPUnit\Framework\MockObject\MockObject $configSource */
$configSource = $this $configSource = $this
->getMockBuilder('Composer\Config\ConfigSourceInterface') ->getMockBuilder('Composer\Config\ConfigSourceInterface')
->disableOriginalConstructor() ->disableOriginalConstructor()
@ -513,7 +515,11 @@ class AuthHelperTest extends TestCase
/** /**
* @param string $origin * @param string $origin
* @param array $auth * @param array<string, string|null> $auth
*
* @return void
*
* @phpstan-param array{username: string|null, password: string|null} $auth
*/ */
private function expectsAuthentication($origin, $auth) private function expectsAuthentication($origin, $auth)
{ {

View file

@ -22,21 +22,28 @@ use Composer\Test\Mock\ProcessExecutorMock;
*/ */
class BitbucketTest extends TestCase class BitbucketTest extends TestCase
{ {
/** @var string */
private $username = 'username'; private $username = 'username';
/** @var string */
private $password = 'password'; private $password = 'password';
/** @var string */
private $consumer_key = 'consumer_key'; private $consumer_key = 'consumer_key';
/** @var string */
private $consumer_secret = 'consumer_secret'; private $consumer_secret = 'consumer_secret';
/** @var string */
private $message = 'mymessage'; private $message = 'mymessage';
/** @var string */
private $origin = 'bitbucket.org'; private $origin = 'bitbucket.org';
/** @var string */
private $token = 'bitbuckettoken'; private $token = 'bitbuckettoken';
/** @type \Composer\IO\ConsoleIO|\PHPUnit_Framework_MockObject_MockObject */ /** @var \Composer\IO\ConsoleIO&\PHPUnit\Framework\MockObject\MockObject */
private $io; private $io;
/** @type \Composer\Util\HttpDownloader|\PHPUnit_Framework_MockObject_MockObject */ /** @var \Composer\Util\HttpDownloader&\PHPUnit\Framework\MockObject\MockObject */
private $httpDownloader; private $httpDownloader;
/** @type \Composer\Config|\PHPUnit_Framework_MockObject_MockObject */ /** @var \Composer\Config&\PHPUnit\Framework\MockObject\MockObject */
private $config; private $config;
/** @type Bitbucket */ /** @var Bitbucket */
private $bitbucket; private $bitbucket;
/** @var int */ /** @var int */
private $time; private $time;
@ -400,6 +407,11 @@ class BitbucketTest extends TestCase
$this->assertFalse($this->bitbucket->authorizeOAuthInteractively($this->origin, $this->message)); $this->assertFalse($this->bitbucket->authorizeOAuthInteractively($this->origin, $this->message));
} }
/**
* @param bool $removeBasicAuth
*
* @return void
*/
private function setExpectationsForStoringAccessToken($removeBasicAuth = false) private function setExpectationsForStoringAccessToken($removeBasicAuth = false)
{ {
$configSourceMock = $this->getMockBuilder('Composer\Config\ConfigSourceInterface')->getMock(); $configSourceMock = $this->getMockBuilder('Composer\Config\ConfigSourceInterface')->getMock();

View file

@ -51,6 +51,12 @@ class FilesystemTest extends TestCase
/** /**
* @dataProvider providePathCouplesAsCode * @dataProvider providePathCouplesAsCode
*
* @param string $a
* @param string $b
* @param bool $directory
* @param string $expected
* @param bool $static
*/ */
public function testFindShortestPathCode($a, $b, $directory, $expected, $static = false) public function testFindShortestPathCode($a, $b, $directory, $expected, $static = false)
{ {
@ -109,6 +115,11 @@ class FilesystemTest extends TestCase
/** /**
* @dataProvider providePathCouples * @dataProvider providePathCouples
*
* @param string $a
* @param string $b
* @param string $expected
* @param bool $directory
*/ */
public function testFindShortestPath($a, $b, $expected, $directory = false) public function testFindShortestPath($a, $b, $expected, $directory = false)
{ {
@ -191,6 +202,9 @@ class FilesystemTest extends TestCase
/** /**
* @dataProvider provideNormalizedPaths * @dataProvider provideNormalizedPaths
*
* @param string $expected
* @param string $actual
*/ */
public function testNormalizePath($expected, $actual) public function testNormalizePath($expected, $actual)
{ {

View file

@ -24,8 +24,11 @@ use RecursiveIteratorIterator;
*/ */
class GitHubTest extends TestCase class GitHubTest extends TestCase
{ {
/** @var string */
private $password = 'password'; private $password = 'password';
/** @var string */
private $message = 'mymessage'; private $message = 'mymessage';
/** @var string */
private $origin = 'github.com'; private $origin = 'github.com';
public function testUsernamePasswordAuthenticationFlow() public function testUsernamePasswordAuthenticationFlow()
@ -100,6 +103,9 @@ class GitHubTest extends TestCase
$this->assertFalse($github->authorizeOAuthInteractively($this->origin)); $this->assertFalse($github->authorizeOAuthInteractively($this->origin));
} }
/**
* @return \PHPUnit\Framework\MockObject\MockObject&\Composer\IO\ConsoleIO
*/
private function getIOMock() private function getIOMock()
{ {
$io = $this $io = $this
@ -111,11 +117,17 @@ class GitHubTest extends TestCase
return $io; return $io;
} }
/**
* @return \PHPUnit\Framework\MockObject\MockObject&\Composer\Config
*/
private function getConfigMock() private function getConfigMock()
{ {
return $this->getMockBuilder('Composer\Config')->getMock(); return $this->getMockBuilder('Composer\Config')->getMock();
} }
/**
* @return \PHPUnit\Framework\MockObject\MockObject&\Composer\Util\HttpDownloader
*/
private function getHttpDownloaderMock() private function getHttpDownloaderMock()
{ {
$httpDownloader = $this $httpDownloader = $this
@ -127,6 +139,9 @@ class GitHubTest extends TestCase
return $httpDownloader; return $httpDownloader;
} }
/**
* @return \PHPUnit\Framework\MockObject\MockObject&\Composer\Config\JsonConfigSource
*/
private function getAuthJsonMock() private function getAuthJsonMock()
{ {
$authjson = $this $authjson = $this
@ -143,6 +158,9 @@ class GitHubTest extends TestCase
return $authjson; return $authjson;
} }
/**
* @return \PHPUnit\Framework\MockObject\MockObject&\Composer\Config\JsonConfigSource
*/
private function getConfJsonMock() private function getConfJsonMock()
{ {
$confjson = $this $confjson = $this
@ -158,16 +176,4 @@ class GitHubTest extends TestCase
return $confjson; return $confjson;
} }
public static function recursiveFind($array, $needle)
{
$iterator = new RecursiveArrayIterator($array);
$recursive = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST);
foreach ($recursive as $key => $value) {
if ($key === $needle) {
return $value;
}
}
}
} }

View file

@ -22,10 +22,15 @@ use Composer\Test\TestCase;
*/ */
class GitLabTest extends TestCase class GitLabTest extends TestCase
{ {
/** @var string */
private $username = 'username'; private $username = 'username';
/** @var string */
private $password = 'password'; private $password = 'password';
/** @var string */
private $message = 'mymessage'; private $message = 'mymessage';
/** @var string */
private $origin = 'gitlab.com'; private $origin = 'gitlab.com';
/** @var string */
private $token = 'gitlabtoken'; private $token = 'gitlabtoken';
public function testUsernamePasswordAuthenticationFlow() public function testUsernamePasswordAuthenticationFlow()
@ -109,6 +114,9 @@ class GitLabTest extends TestCase
$gitLab->authorizeOAuthInteractively('https', $this->origin); $gitLab->authorizeOAuthInteractively('https', $this->origin);
} }
/**
* @return \PHPUnit\Framework\MockObject\MockObject&\Composer\IO\ConsoleIO
*/
private function getIOMock() private function getIOMock()
{ {
$io = $this $io = $this
@ -120,11 +128,17 @@ class GitLabTest extends TestCase
return $io; return $io;
} }
/**
* @return \PHPUnit\Framework\MockObject\MockObject&\Composer\Config
*/
private function getConfigMock() private function getConfigMock()
{ {
return $this->getMockBuilder('Composer\Config')->getMock(); return $this->getMockBuilder('Composer\Config')->getMock();
} }
/**
* @return \PHPUnit\Framework\MockObject\MockObject&\Composer\Util\HttpDownloader
*/
private function getHttpDownloaderMock() private function getHttpDownloaderMock()
{ {
$httpDownloader = $this $httpDownloader = $this
@ -136,6 +150,9 @@ class GitLabTest extends TestCase
return $httpDownloader; return $httpDownloader;
} }
/**
* @return \PHPUnit\Framework\MockObject\MockObject&\Composer\Config\JsonConfigSource
*/
private function getAuthJsonMock() private function getAuthJsonMock()
{ {
$authjson = $this $authjson = $this

View file

@ -43,6 +43,9 @@ class GitTest extends TestCase
/** /**
* @dataProvider publicGithubNoCredentialsProvider * @dataProvider publicGithubNoCredentialsProvider
*
* @param string $protocol
* @param string $expectedUrl
*/ */
public function testRunCommandPublicGitHubRepositoryNotInitialClone($protocol, $expectedUrl) public function testRunCommandPublicGitHubRepositoryNotInitialClone($protocol, $expectedUrl)
{ {
@ -96,6 +99,12 @@ class GitTest extends TestCase
/** /**
* @dataProvider privateGithubWithCredentialsProvider * @dataProvider privateGithubWithCredentialsProvider
*
* @param string $gitUrl
* @param string $protocol
* @param string $gitHubToken
* @param string $expectedUrl
* @param int $expectedFailuresBeforeSuccess
*/ */
public function testRunCommandPrivateGitHubRepositoryNotInitialCloneNotInteractiveWithAuthentication($gitUrl, $protocol, $gitHubToken, $expectedUrl, $expectedFailuresBeforeSuccess) public function testRunCommandPrivateGitHubRepositoryNotInitialCloneNotInteractiveWithAuthentication($gitUrl, $protocol, $gitHubToken, $expectedUrl, $expectedFailuresBeforeSuccess)
{ {
@ -143,6 +152,11 @@ class GitTest extends TestCase
); );
} }
/**
* @param string $protocol
*
* @return void
*/
private function mockConfig($protocol) private function mockConfig($protocol)
{ {
$this->config $this->config

View file

@ -45,6 +45,8 @@ class ProxyHelperTest extends TestCase
/** /**
* @dataProvider dataMalformed * @dataProvider dataMalformed
*
* @param string $url
*/ */
public function testThrowsOnMalformedUrl($url) public function testThrowsOnMalformedUrl($url)
{ {
@ -64,6 +66,9 @@ class ProxyHelperTest extends TestCase
/** /**
* @dataProvider dataFormatting * @dataProvider dataFormatting
*
* @param string $url
* @param string $expected
*/ */
public function testUrlFormatting($url, $expected) public function testUrlFormatting($url, $expected)
{ {
@ -85,6 +90,10 @@ class ProxyHelperTest extends TestCase
/** /**
* @dataProvider dataCaseOverrides * @dataProvider dataCaseOverrides
*
* @param array<string, mixed> $server
* @param string $expected
* @param int $index
*/ */
public function testLowercaseOverridesUppercase(array $server, $expected, $index) public function testLowercaseOverridesUppercase(array $server, $expected, $index)
{ {
@ -106,6 +115,10 @@ class ProxyHelperTest extends TestCase
/** /**
* @dataProvider dataCGIOverrides * @dataProvider dataCGIOverrides
*
* @param array<string, mixed> $server
* @param string $expected
* @param int $index
*/ */
public function testCGIUpperCaseOverridesHttp(array $server, $expected, $index) public function testCGIUpperCaseOverridesHttp(array $server, $expected, $index)
{ {
@ -142,6 +155,11 @@ class ProxyHelperTest extends TestCase
/** /**
* @dataProvider dataContextOptions * @dataProvider dataContextOptions
*
* @param string $url
* @param array<string, string> $expected
*
* @phpstan-param array{http: array{proxy: string, header?: string}} $expected
*/ */
public function testGetContextOptions($url, $expected) public function testGetContextOptions($url, $expected)
{ {
@ -167,6 +185,9 @@ class ProxyHelperTest extends TestCase
/** /**
* @dataProvider dataRequestFullUri * @dataProvider dataRequestFullUri
*
* @param string $requestUrl
* @param mixed[] $expected
*/ */
public function testSetRequestFullUri($requestUrl, $expected) public function testSetRequestFullUri($requestUrl, $expected)
{ {

View file

@ -68,6 +68,13 @@ class ProxyManagerTest extends TestCase
/** /**
* @dataProvider dataRequest * @dataProvider dataRequest
*
* @param array<string, mixed> $server
* @param string $url
* @param string $expectedUrl
* @param mixed[] $expectedOptions
* @param bool $expectedSecure
* @param string $expectedMessage
*/ */
public function testGetProxyForRequest($server, $url, $expectedUrl, $expectedOptions, $expectedSecure, $expectedMessage) public function testGetProxyForRequest($server, $url, $expectedUrl, $expectedOptions, $expectedSecure, $expectedMessage)
{ {
@ -126,6 +133,10 @@ class ProxyManagerTest extends TestCase
/** /**
* @dataProvider dataStatus * @dataProvider dataStatus
*
* @param array<string, mixed> $server
* @param bool $expectedStatus
* @param string $expectedMessage
*/ */
public function testGetStatus($server, $expectedStatus, $expectedMessage) public function testGetStatus($server, $expectedStatus, $expectedMessage)
{ {

View file

@ -19,6 +19,9 @@ class RequestProxyTest extends TestCase
{ {
/** /**
* @dataProvider dataSecure * @dataProvider dataSecure
*
* @param string $url
* @param bool $expectedSecure
*/ */
public function testIsSecure($url, $expectedSecure) public function testIsSecure($url, $expectedSecure)
{ {
@ -39,6 +42,10 @@ class RequestProxyTest extends TestCase
/** /**
* @dataProvider dataProxyUrl * @dataProvider dataProxyUrl
*
* @param string $url
* @param string $format
* @param string $expected
*/ */
public function testGetFormattedUrlFormat($url, $format, $expected) public function testGetFormattedUrlFormat($url, $format, $expected)
{ {

View file

@ -17,6 +17,9 @@ use PHPUnit\Framework\TestCase;
class HttpDownloaderTest extends TestCase class HttpDownloaderTest extends TestCase
{ {
/**
* @return \PHPUnit\Framework\MockObject\MockObject&\Composer\Config
*/
private function getConfigMock() private function getConfigMock()
{ {
$config = $this->getMockBuilder('Composer\Config')->getMock(); $config = $this->getMockBuilder('Composer\Config')->getMock();

View file

@ -91,6 +91,11 @@ class IniHelperTest extends TestCase
} }
} }
/**
* @param string[] $paths
*
* @return void
*/
protected function setEnv(array $paths) protected function setEnv(array $paths)
{ {
putenv('COMPOSER_ORIGINAL_INIS='.implode(PATH_SEPARATOR, $paths)); putenv('COMPOSER_ORIGINAL_INIS='.implode(PATH_SEPARATOR, $paths));

View file

@ -19,6 +19,10 @@ class NoProxyPatternTest extends TestCase
{ {
/** /**
* @dataProvider dataHostName * @dataProvider dataHostName
*
* @param string $noproxy
* @param string $url
* @param bool $expected
*/ */
public function testHostName($noproxy, $url, $expected) public function testHostName($noproxy, $url, $expected)
{ {
@ -46,6 +50,10 @@ class NoProxyPatternTest extends TestCase
/** /**
* @dataProvider dataIpAddress * @dataProvider dataIpAddress
*
* @param string $noproxy
* @param string $url
* @param bool $expected
*/ */
public function testIpAddress($noproxy, $url, $expected) public function testIpAddress($noproxy, $url, $expected)
{ {
@ -71,6 +79,10 @@ class NoProxyPatternTest extends TestCase
/** /**
* @dataProvider dataIpRange * @dataProvider dataIpRange
*
* @param string $noproxy
* @param string $url
* @param bool $expected
*/ */
public function testIpRange($noproxy, $url, $expected) public function testIpRange($noproxy, $url, $expected)
{ {
@ -96,6 +108,10 @@ class NoProxyPatternTest extends TestCase
/** /**
* @dataProvider dataPort * @dataProvider dataPort
*
* @param string $noproxy
* @param string $url
* @param bool $expected
*/ */
public function testPort($noproxy, $url, $expected) public function testPort($noproxy, $url, $expected)
{ {
@ -121,6 +137,8 @@ class NoProxyPatternTest extends TestCase
* Appends a scheme to the test url if it is missing * Appends a scheme to the test url if it is missing
* *
* @param string $url * @param string $url
*
* @return string
*/ */
private function getUrl($url) private function getUrl($url)
{ {

View file

@ -104,8 +104,9 @@ class PackageSorterTest extends TestCase
/** /**
* @dataProvider sortingOrdersDependenciesHigherThanPackageDataProvider * @dataProvider sortingOrdersDependenciesHigherThanPackageDataProvider
* @param array $packages *
* @param array $expectedOrderedList * @param Package[] $packages
* @param string[] $expectedOrderedList
*/ */
public function testSortingOrdersDependenciesHigherThanPackage($packages, $expectedOrderedList) public function testSortingOrdersDependenciesHigherThanPackage($packages, $expectedOrderedList)
{ {
@ -117,6 +118,12 @@ class PackageSorterTest extends TestCase
self::assertSame($expectedOrderedList, $sortedPackageNames); self::assertSame($expectedOrderedList, $sortedPackageNames);
} }
/**
* @param string $name
* @param string[] $requires
*
* @return Package
*/
private function createPackage($name, $requires) private function createPackage($name, $requires)
{ {
$package = new Package($name, '1.0.0.0', '1.0.0'); $package = new Package($name, '1.0.0.0', '1.0.0');

View file

@ -21,9 +21,13 @@ use Composer\Util\ProcessExecutor;
*/ */
class PerforceTest extends TestCase class PerforceTest extends TestCase
{ {
/** @var Perforce */
protected $perforce; protected $perforce;
/** @var \PHPUnit\Framework\MockObject\MockObject&\Composer\Util\ProcessExecutor */
protected $processExecutor; protected $processExecutor;
/** @var array<string, string> */
protected $repoConfig; protected $repoConfig;
/** @var \PHPUnit\Framework\MockObject\MockObject&\Composer\IO\IOInterface */
protected $io; protected $io;
const TEST_DEPOT = 'depot'; const TEST_DEPOT = 'depot';
@ -41,14 +45,9 @@ class PerforceTest extends TestCase
$this->createNewPerforceWithWindowsFlag(true); $this->createNewPerforceWithWindowsFlag(true);
} }
protected function tearDown() /**
{ * @return array<string, string>
$this->perforce = null; */
$this->io = null;
$this->repoConfig = null;
$this->processExecutor = null;
}
public function getTestRepoConfig() public function getTestRepoConfig()
{ {
return array( return array(
@ -59,11 +58,19 @@ class PerforceTest extends TestCase
); );
} }
/**
* @return \PHPUnit\Framework\MockObject\MockObject&\Composer\IO\IOInterface
*/
public function getMockIOInterface() public function getMockIOInterface()
{ {
return $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); return $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
} }
/**
* @param bool $flag
*
* @return void
*/
protected function createNewPerforceWithWindowsFlag($flag) protected function createNewPerforceWithWindowsFlag($flag)
{ {
$this->perforce = new Perforce($this->repoConfig, self::TEST_PORT, self::TEST_PATH, $this->processExecutor, $flag, $this->io); $this->perforce = new Perforce($this->repoConfig, self::TEST_PORT, self::TEST_PATH, $this->processExecutor, $flag, $this->io);
@ -435,7 +442,7 @@ class PerforceTest extends TestCase
public function testCheckStreamWithoutStream() public function testCheckStreamWithoutStream()
{ {
$result = $this->perforce->checkStream('depot'); $result = $this->perforce->checkStream();
$this->assertFalse($result); $this->assertFalse($result);
$this->assertFalse($this->perforce->isStream()); $this->assertFalse($this->perforce->isStream());
} }
@ -452,7 +459,7 @@ class PerforceTest extends TestCase
} }
) )
); );
$result = $this->perforce->checkStream('depot'); $result = $this->perforce->checkStream();
$this->assertTrue($result); $this->assertTrue($result);
$this->assertTrue($this->perforce->isStream()); $this->assertTrue($this->perforce->isStream());
} }
@ -653,6 +660,9 @@ class PerforceTest extends TestCase
$this->assertFalse($result); $this->assertFalse($result);
} }
/**
* @return string
*/
public static function getComposerJson() public static function getComposerJson()
{ {
$composer_json = array( $composer_json = array(
@ -670,6 +680,11 @@ class PerforceTest extends TestCase
return implode($composer_json); return implode($composer_json);
} }
/**
* @param bool $withStream
*
* @return string[]
*/
private function getExpectedClientSpec($withStream) private function getExpectedClientSpec($withStream)
{ {
$expectedArray = array( $expectedArray = array(
@ -702,6 +717,9 @@ class PerforceTest extends TestCase
return $expectedArray; return $expectedArray;
} }
/**
* @return void
*/
private function setPerforceToStream() private function setPerforceToStream()
{ {
$this->perforce->setStream('//depot/branch'); $this->perforce->setStream('//depot/branch');

View file

@ -69,6 +69,9 @@ class ProcessExecutorTest extends TestCase
/** /**
* @dataProvider hidePasswordProvider * @dataProvider hidePasswordProvider
*
* @param string $command
* @param string $expectedCommandOutput
*/ */
public function testHidePasswords($command, $expectedCommandOutput) public function testHidePasswords($command, $expectedCommandOutput)
{ {
@ -133,6 +136,10 @@ class ProcessExecutorTest extends TestCase
* Test various arguments are escaped as expected * Test various arguments are escaped as expected
* *
* @dataProvider dataEscapeArguments * @dataProvider dataEscapeArguments
*
* @param string|false|null $argument
* @param string $win
* @param string $unix
*/ */
public function testEscapeArgument($argument, $win, $unix) public function testEscapeArgument($argument, $win, $unix)
{ {

View file

@ -148,7 +148,8 @@ class RemoteFilesystemTest extends TestCase
{ {
$fs = new RemoteFilesystem($this->getIOInterfaceMock(), $this->getConfigMock()); $fs = new RemoteFilesystem($this->getIOInterfaceMock(), $this->getConfigMock());
$this->assertNull($this->callCallbackGet($fs, STREAM_NOTIFY_FAILURE, 0, 'HTTP/1.1 404 Not Found', 404, 0, 0)); $this->callCallbackGet($fs, STREAM_NOTIFY_FAILURE, 0, 'HTTP/1.1 404 Not Found', 404, 0, 0);
$this->assertTrue(true, 'callbackGet must pass through 404');
} }
public function testGetContents() public function testGetContents()
@ -341,7 +342,14 @@ class RemoteFilesystemTest extends TestCase
$this->assertEquals(array('bitbucket.org', 'bbuseruploads.s3.amazonaws.com'), $domains); $this->assertEquals(array('bitbucket.org', 'bbuseruploads.s3.amazonaws.com'), $domains);
} }
private function callGetOptionsForUrl($io, array $args = array(), array $options = array(), $fileUrl = '') /**
* @param mixed[] $args
* @param mixed[] $options
* @param string $fileUrl
*
* @return mixed[]
*/
private function callGetOptionsForUrl(IOInterface $io, array $args = array(), array $options = array(), $fileUrl = '')
{ {
$fs = new RemoteFilesystem($io, $this->getConfigMock(), $options); $fs = new RemoteFilesystem($io, $this->getConfigMock(), $options);
$ref = new ReflectionMethod($fs, 'getOptionsForUrl'); $ref = new ReflectionMethod($fs, 'getOptionsForUrl');
@ -373,6 +381,16 @@ class RemoteFilesystemTest extends TestCase
return $config; return $config;
} }
/**
* @param int $notificationCode
* @param int $severity
* @param string $message
* @param int $messageCode
* @param int $bytesTransferred
* @param int $bytesMax
*
* @return void
*/
private function callCallbackGet(RemoteFilesystem $fs, $notificationCode, $severity, $message, $messageCode, $bytesTransferred, $bytesMax) private function callCallbackGet(RemoteFilesystem $fs, $notificationCode, $severity, $message, $messageCode, $bytesTransferred, $bytesMax)
{ {
$ref = new ReflectionMethod($fs, 'callbackGet'); $ref = new ReflectionMethod($fs, 'callbackGet');
@ -380,6 +398,13 @@ class RemoteFilesystemTest extends TestCase
$ref->invoke($fs, $notificationCode, $severity, $message, $messageCode, $bytesTransferred, $bytesMax); $ref->invoke($fs, $notificationCode, $severity, $message, $messageCode, $bytesTransferred, $bytesMax);
} }
/**
* @param object|string $object
* @param string $attribute
* @param mixed $value
*
* @return void
*/
private function setAttribute($object, $attribute, $value) private function setAttribute($object, $attribute, $value)
{ {
$attr = new ReflectionProperty($object, $attribute); $attr = new ReflectionProperty($object, $attribute);
@ -387,6 +412,13 @@ class RemoteFilesystemTest extends TestCase
$attr->setValue($object, $value); $attr->setValue($object, $value);
} }
/**
* @param mixed $value
* @param string $attribute
* @param object|string $object
*
* @return void
*/
private function assertAttributeEqualsCustom($value, $attribute, $object) private function assertAttributeEqualsCustom($value, $attribute, $object)
{ {
$attr = new ReflectionProperty($object, $attribute); $attr = new ReflectionProperty($object, $attribute);
@ -403,8 +435,7 @@ class RemoteFilesystemTest extends TestCase
} }
/** /**
* @param array $mockedMethods * @param string[] $mockedMethods
* @param AuthHelper $authHelper
* *
* @return RemoteFilesystem|MockObject * @return RemoteFilesystem|MockObject
*/ */
@ -423,7 +454,7 @@ class RemoteFilesystemTest extends TestCase
} }
/** /**
* @param array $mockedMethods * @param string[] $mockedMethods
* *
* @return AuthHelper|MockObject * @return AuthHelper|MockObject
*/ */

View file

@ -32,6 +32,11 @@ class StreamContextFactoryTest extends TestCase
/** /**
* @dataProvider dataGetContext * @dataProvider dataGetContext
*
* @param mixed[] $expectedOptions
* @param mixed[] $defaultOptions
* @param mixed[] $expectedParams
* @param mixed[] $defaultParams
*/ */
public function testGetContext($expectedOptions, $defaultOptions, $expectedParams, $defaultParams) public function testGetContext($expectedOptions, $defaultOptions, $expectedParams, $defaultParams)
{ {
@ -157,6 +162,9 @@ class StreamContextFactoryTest extends TestCase
/** /**
* @dataProvider dataSSLProxy * @dataProvider dataSSLProxy
*
* @param string $expected
* @param string $proxy
*/ */
public function testSSLProxy($expected, $proxy) public function testSSLProxy($expected, $proxy)
{ {

View file

@ -17,7 +17,13 @@ use Composer\Test\TestCase;
class TlsHelperTest extends TestCase class TlsHelperTest extends TestCase
{ {
/** @dataProvider dataCheckCertificateHost */ /**
* @dataProvider dataCheckCertificateHost
*
* @param bool $expectedResult
* @param string $hostname
* @param string[] $certNames
*/
public function testCheckCertificateHost($expectedResult, $hostname, $certNames) public function testCheckCertificateHost($expectedResult, $hostname, $certNames)
{ {
$certificate['subject']['commonName'] = $expectedCn = array_shift($certNames); $certificate['subject']['commonName'] = $expectedCn = array_shift($certNames);

View file

@ -20,6 +20,11 @@ class UrlTest extends TestCase
{ {
/** /**
* @dataProvider distRefsProvider * @dataProvider distRefsProvider
*
* @param string $url
* @param string $expectedUrl
* @param array<string, mixed> $conf
* @param string $ref
*/ */
public function testUpdateDistReference($url, $expectedUrl, $conf = array(), $ref = 'newref') public function testUpdateDistReference($url, $expectedUrl, $conf = array(), $ref = 'newref')
{ {
@ -61,6 +66,9 @@ class UrlTest extends TestCase
/** /**
* @dataProvider sanitizeProvider * @dataProvider sanitizeProvider
*
* @param string $expected
* @param string $url
*/ */
public function testSanitize($expected, $url) public function testSanitize($expected, $url)
{ {