1
0
Fork 0

Type annotations

pull/10169/head
Jordi Boggiano 2021-10-16 10:16:06 +02:00
parent 626370d444
commit c3c6969cf5
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
21 changed files with 166 additions and 35 deletions

View File

@ -719,7 +719,7 @@ EOF;
$package = $item[0]; $package = $item[0];
foreach (array_merge($package->getReplaces(), $package->getProvides()) as $link) { foreach (array_merge($package->getReplaces(), $package->getProvides()) as $link) {
if (preg_match('{^ext-(.+)$}iD', $link->getTarget(), $match)) { if (preg_match('{^ext-(.+)$}iD', $link->getTarget(), $match)) {
$extensionProviders[$match[1]][] = $link->getConstraint() ?: new MatchAllConstraint(); $extensionProviders[$match[1]][] = $link->getConstraint();
} }
} }
} }
@ -736,7 +736,8 @@ EOF;
continue; continue;
} }
if ('php' === $link->getTarget() && ($constraint = $link->getConstraint())) { if ('php' === $link->getTarget()) {
$constraint = $link->getConstraint();
if ($constraint->getLowerBound()->compareTo($lowestPhpVersion, '>')) { if ($constraint->getLowerBound()->compareTo($lowestPhpVersion, '>')) {
$lowestPhpVersion = $constraint->getLowerBound(); $lowestPhpVersion = $constraint->getLowerBound();
} }
@ -746,7 +747,7 @@ EOF;
// skip extension checks if they have a valid provider/replacer // skip extension checks if they have a valid provider/replacer
if (isset($extensionProviders[$match[1]])) { if (isset($extensionProviders[$match[1]])) {
foreach ($extensionProviders[$match[1]] as $provided) { foreach ($extensionProviders[$match[1]] as $provided) {
if (!$link->getConstraint() || $provided->matches($link->getConstraint())) { if ($provided->matches($link->getConstraint())) {
continue 2; continue 2;
} }
} }

View File

@ -22,7 +22,9 @@ use Composer\Test\TestCase;
class RuleSetIteratorTest extends TestCase class RuleSetIteratorTest extends TestCase
{ {
/** @var array<RuleSet::TYPE_*, Rule[]> */
protected $rules; protected $rules;
/** @var Pool */
protected $pool; protected $pool;
protected function setUp() protected function setUp()

View File

@ -16,6 +16,11 @@ use Composer\IO\NullIO;
use Composer\Repository\ArrayRepository; use Composer\Repository\ArrayRepository;
use Composer\Repository\LockArrayRepository; use Composer\Repository\LockArrayRepository;
use Composer\DependencyResolver\DefaultPolicy; use Composer\DependencyResolver\DefaultPolicy;
use Composer\DependencyResolver\Operation\InstallOperation;
use Composer\DependencyResolver\Operation\MarkAliasInstalledOperation;
use Composer\DependencyResolver\Operation\MarkAliasUninstalledOperation;
use Composer\DependencyResolver\Operation\UninstallOperation;
use Composer\DependencyResolver\Operation\UpdateOperation;
use Composer\DependencyResolver\Request; use Composer\DependencyResolver\Request;
use Composer\DependencyResolver\Solver; use Composer\DependencyResolver\Solver;
use Composer\DependencyResolver\SolverProblemsException; use Composer\DependencyResolver\SolverProblemsException;
@ -24,15 +29,23 @@ use Composer\Repository\RepositorySet;
use Composer\Test\TestCase; use Composer\Test\TestCase;
use Composer\Semver\Constraint\MultiConstraint; use Composer\Semver\Constraint\MultiConstraint;
use Composer\Semver\Constraint\MatchAllConstraint; use Composer\Semver\Constraint\MatchAllConstraint;
use Composer\DependencyResolver\Pool;
class SolverTest extends TestCase class SolverTest extends TestCase
{ {
/** @var RepositorySet */
protected $repoSet; protected $repoSet;
/** @var ArrayRepository */
protected $repo; protected $repo;
/** @var LockArrayRepository */
protected $repoLocked; protected $repoLocked;
/** @var Request */
protected $request; protected $request;
/** @var DefaultPolicy */
protected $policy; protected $policy;
/** @var Solver|null */
protected $solver; protected $solver;
/** @var Pool */
protected $pool; protected $pool;
public function setUp() public function setUp()
@ -1046,23 +1059,25 @@ class SolverTest extends TestCase
$result = array(); $result = array();
foreach ($transaction->getOperations() as $operation) { foreach ($transaction->getOperations() as $operation) {
if ('update' === $operation->getOperationType()) { if ($operation instanceof UpdateOperation) {
$result[] = array( $result[] = array(
'job' => 'update', 'job' => 'update',
'from' => $operation->getInitialPackage(), 'from' => $operation->getInitialPackage(),
'to' => $operation->getTargetPackage(), 'to' => $operation->getTargetPackage(),
); );
} elseif (in_array($operation->getOperationType(), array('markAliasInstalled', 'markAliasUninstalled'))) { } elseif ($operation instanceof MarkAliasInstalledOperation || $operation instanceof MarkAliasUninstalledOperation) {
$result[] = array( $result[] = array(
'job' => $operation->getOperationType(), 'job' => $operation->getOperationType(),
'package' => $operation->getPackage(), 'package' => $operation->getPackage(),
); );
} else { } elseif ($operation instanceof UninstallOperation || $operation instanceof InstallOperation) {
$job = ('uninstall' === $operation->getOperationType() ? 'remove' : 'install'); $job = ('uninstall' === $operation->getOperationType() ? 'remove' : 'install');
$result[] = array( $result[] = array(
'job' => $job, 'job' => $job,
'package' => $operation->getPackage(), 'package' => $operation->getPackage(),
); );
} else {
throw new \LogicException('Unexpected operation: '.get_class($operation));
} }
} }

View File

@ -17,6 +17,9 @@ use Composer\Semver\VersionParser;
class InstalledVersionsTest extends TestCase class InstalledVersionsTest extends TestCase
{ {
/**
* @var string
*/
private $root; private $root;
public static function setUpBeforeClass() public static function setUpBeforeClass()

View File

@ -17,8 +17,17 @@ use Composer\Test\TestCase;
class MetapackageInstallerTest extends TestCase class MetapackageInstallerTest extends TestCase
{ {
/**
* @var \Composer\Repository\InstalledRepositoryInterface&\PHPUnit\Framework\MockObject\MockObject
*/
private $repository; private $repository;
/**
* @var MetapackageInstaller
*/
private $installer; private $installer;
/**
* @var \Composer\IO\IOInterface&\PHPUnit\Framework\MockObject\MockObject
*/
private $io; private $io;
protected function setUp() protected function setUp()

View File

@ -18,10 +18,13 @@ use Composer\Downloader\TransportException;
class HttpDownloaderMock extends HttpDownloader class HttpDownloaderMock extends HttpDownloader
{ {
/**
* @var array<string, string>
*/
protected $contentMap; protected $contentMap;
/** /**
* @param array $contentMap associative array of locations and content * @param array<string, string> $contentMap associative array of locations and content
*/ */
public function __construct(array $contentMap) public function __construct(array $contentMap)
{ {

View File

@ -24,9 +24,21 @@ use Composer\DependencyResolver\Operation\MarkAliasUninstalledOperation;
class InstallationManagerMock extends InstallationManager class InstallationManagerMock extends InstallationManager
{ {
/**
* @var PackageInterface[]
*/
private $installed = array(); private $installed = array();
/**
* @var PackageInterface[][]
*/
private $updated = array(); private $updated = array();
/**
* @var PackageInterface[]
*/
private $uninstalled = array(); private $uninstalled = array();
/**
* @var string[]
*/
private $trace = array(); private $trace = array();
public function __construct() public function __construct()

View File

@ -24,9 +24,21 @@ use React\Promise\Promise;
*/ */
class ProcessExecutorMock extends ProcessExecutor class ProcessExecutorMock extends ProcessExecutor
{ {
/**
* @var array<array{cmd: string, return: int, stdout: string, stderr: string, callback: ?callable}>
*/
private $expectations = array(); private $expectations = array();
/**
* @var bool
*/
private $strict = false; private $strict = false;
/**
* @var array{return: int, stdout: string, stderr: string}
*/
private $defaultHandler = array('return' => 0, 'stdout' => '', 'stderr' => ''); private $defaultHandler = array('return' => 0, 'stdout' => '', 'stderr' => '');
/**
* @var string[]
*/
private $log = array(); private $log = array();
/** /**
@ -47,7 +59,7 @@ class ProcessExecutorMock extends ProcessExecutor
return array_merge($default, $expect); return array_merge($default, $expect);
}, $expectations); }, $expectations);
$this->strict = $strict; $this->strict = $strict;
$this->defaultHandler = array_merge($default, $defaultHandler); $this->defaultHandler = array_merge($this->defaultHandler, $defaultHandler);
} }
public function assertComplete(TestCase $testCase) public function assertComplete(TestCase $testCase)

View File

@ -19,8 +19,17 @@ use Symfony\Component\Process\Process;
class ArchivableFilesFinderTest extends TestCase class ArchivableFilesFinderTest extends TestCase
{ {
/**
* @var string
*/
protected $sources; protected $sources;
/**
* @var ArchivableFilesFinder
*/
protected $finder; protected $finder;
/**
* @var Filesystem
*/
protected $fs; protected $fs;
protected function setUp() protected function setUp()

View File

@ -28,6 +28,9 @@ class ArchiveManagerTest extends ArchiverTest
*/ */
protected $manager; protected $manager;
/**
* @var string
*/
protected $targetDir; protected $targetDir;
public function setUp() public function setUp()

View File

@ -20,6 +20,9 @@ use Symfony\Component\Process\ExecutableFinder;
class HhvmDetectorTest extends TestCase class HhvmDetectorTest extends TestCase
{ {
/**
* @var HhvmDetector
*/
private $hhvmDetector; private $hhvmDetector;
protected function setUp() protected function setUp()

View File

@ -20,6 +20,9 @@ use Composer\Package\BasePackage;
class FilterRepositoryTest extends TestCase class FilterRepositoryTest extends TestCase
{ {
/**
* @var ArrayRepository
*/
private $arrayRepo; private $arrayRepo;
public function setUp() public function setUp()

View File

@ -19,7 +19,13 @@ use Composer\Util\Filesystem;
class FossilDriverTest extends TestCase class FossilDriverTest extends TestCase
{ {
/**
* @var string
*/
protected $home; protected $home;
/**
* @var Config
*/
protected $config; protected $config;
public function setUp() public function setUp()

View File

@ -24,15 +24,15 @@ use Composer\Util\Http\Response;
*/ */
class GitBitbucketDriverTest extends TestCase class GitBitbucketDriverTest 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 */ /** @var Config */
private $config; private $config;
/** @type \Composer\Util\HttpDownloader|\PHPUnit_Framework_MockObject_MockObject */ /** @var \Composer\Util\HttpDownloader&\PHPUnit\Framework\MockObject\MockObject */
private $httpDownloader; private $httpDownloader;
/** @type string */ /** @var string */
private $home; private $home;
/** @type string */ /** @var string */
private $originUrl = 'bitbucket.org'; private $originUrl = 'bitbucket.org';
protected function setUp() protected function setUp()

View File

@ -24,10 +24,25 @@ use Composer\Util\Http\Response;
*/ */
class GitLabDriverTest extends TestCase class GitLabDriverTest extends TestCase
{ {
/**
* @var string
*/
private $home; private $home;
/**
* @var Config
*/
private $config; private $config;
/**
* @var \Prophecy\Prophecy\ObjectProphecy
*/
private $io; private $io;
/**
* @var \Prophecy\Prophecy\ObjectProphecy
*/
private $process; private $process;
/**
* @var \Prophecy\Prophecy\ObjectProphecy
*/
private $httpDownloader; private $httpDownloader;
public function setUp() public function setUp()

View File

@ -19,11 +19,11 @@ use Composer\Config;
class HgDriverTest extends TestCase class HgDriverTest extends TestCase
{ {
/** @type \Composer\IO\IOInterface|\PHPUnit_Framework_MockObject_MockObject */ /** @var \Composer\IO\IOInterface&\PHPUnit\Framework\MockObject\MockObject */
private $io; private $io;
/** @type Config */ /** @var Config */
private $config; private $config;
/** @type string */ /** @var string */
private $home; private $home;
public function setUp() public function setUp()

View File

@ -24,13 +24,37 @@ use Composer\Test\Mock\ProcessExecutorMock;
*/ */
class PerforceDriverTest extends TestCase class PerforceDriverTest extends TestCase
{ {
/**
* @var Config
*/
protected $config; protected $config;
/**
* @var \Composer\IO\IOInterface&\PHPUnit\Framework\MockObject\MockObject
*/
protected $io; protected $io;
/**
* @var ProcessExecutorMock
*/
protected $process; protected $process;
/**
* @var \Composer\Util\HttpDownloader&\PHPUnit\Framework\MockObject\MockObject
*/
protected $httpDownloader; protected $httpDownloader;
/**
* @var string
*/
protected $testPath; protected $testPath;
/**
* @var PerforceDriver
*/
protected $driver; protected $driver;
/**
* @var array<string, string>
*/
protected $repoConfig; protected $repoConfig;
/**
* @var Perforce&\PHPUnit\Framework\MockObject\MockObject
*/
protected $perforce; protected $perforce;
const TEST_URL = 'TEST_PERFORCE_URL'; const TEST_URL = 'TEST_PERFORCE_URL';
@ -41,7 +65,11 @@ class PerforceDriverTest extends TestCase
{ {
$this->testPath = $this->getUniqueTmpDirectory(); $this->testPath = $this->getUniqueTmpDirectory();
$this->config = $this->getTestConfig($this->testPath); $this->config = $this->getTestConfig($this->testPath);
$this->repoConfig = $this->getTestRepoConfig(); $this->repoConfig = array(
'url' => self::TEST_URL,
'depot' => self::TEST_DEPOT,
'branch' => self::TEST_BRANCH,
);
$this->io = $this->getMockIOInterface(); $this->io = $this->getMockIOInterface();
$this->process = new ProcessExecutorMock; $this->process = new ProcessExecutorMock;
$this->httpDownloader = $this->getMockHttpDownloader(); $this->httpDownloader = $this->getMockHttpDownloader();
@ -55,14 +83,6 @@ class PerforceDriverTest extends TestCase
//cleanup directory under test path //cleanup directory under test path
$fs = new Filesystem; $fs = new Filesystem;
$fs->removeDirectory($this->testPath); $fs->removeDirectory($this->testPath);
$this->driver = null;
$this->perforce = null;
$this->httpDownloader = null;
$this->process = null;
$this->io = null;
$this->repoConfig = null;
$this->config = null;
$this->testPath = null;
} }
protected function overrideDriverInternalPerforce(Perforce $perforce) protected function overrideDriverInternalPerforce(Perforce $perforce)
@ -81,15 +101,6 @@ class PerforceDriverTest extends TestCase
return $config; return $config;
} }
protected function getTestRepoConfig()
{
return array(
'url' => self::TEST_URL,
'depot' => self::TEST_DEPOT,
'branch' => self::TEST_BRANCH,
);
}
protected function getMockIOInterface() protected function getMockIOInterface()
{ {
return $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); return $this->getMockBuilder('Composer\IO\IOInterface')->getMock();

View File

@ -20,7 +20,13 @@ use Composer\Test\Mock\ProcessExecutorMock;
class SvnDriverTest extends TestCase class SvnDriverTest extends TestCase
{ {
/**
* @var string
*/
protected $home; protected $home;
/**
* @var Config
*/
protected $config; protected $config;
public function setUp() public function setUp()

View File

@ -26,9 +26,18 @@ use Composer\Config;
*/ */
class VcsRepositoryTest extends TestCase class VcsRepositoryTest extends TestCase
{ {
/**
* @var string
*/
private static $composerHome; private static $composerHome;
/**
* @var string
*/
private static $gitRepo; private static $gitRepo;
private $skipped; /**
* @var ?string
*/
private $skipped = null;
protected function initialize() protected function initialize()
{ {

View File

@ -25,7 +25,13 @@ use Composer\Package\BasePackage;
abstract class TestCase extends PolyfillTestCase abstract class TestCase extends PolyfillTestCase
{ {
/**
* @var ?VersionParser
*/
private static $parser; private static $parser;
/**
* @var array<string, bool>
*/
private static $executableCache = array(); private static $executableCache = array();
/** /**

View File

@ -21,6 +21,9 @@ use Composer\Test\TestCase;
*/ */
class IniHelperTest extends TestCase class IniHelperTest extends TestCase
{ {
/**
* @var string|false
*/
public static $envOriginal; public static $envOriginal;
public function testWithNoIni() public function testWithNoIni()