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];
foreach (array_merge($package->getReplaces(), $package->getProvides()) as $link) {
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;
}
if ('php' === $link->getTarget() && ($constraint = $link->getConstraint())) {
if ('php' === $link->getTarget()) {
$constraint = $link->getConstraint();
if ($constraint->getLowerBound()->compareTo($lowestPhpVersion, '>')) {
$lowestPhpVersion = $constraint->getLowerBound();
}
@ -746,7 +747,7 @@ EOF;
// skip extension checks if they have a valid provider/replacer
if (isset($extensionProviders[$match[1]])) {
foreach ($extensionProviders[$match[1]] as $provided) {
if (!$link->getConstraint() || $provided->matches($link->getConstraint())) {
if ($provided->matches($link->getConstraint())) {
continue 2;
}
}

View File

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

View File

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

View File

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

View File

@ -18,10 +18,13 @@ use Composer\Downloader\TransportException;
class HttpDownloaderMock extends HttpDownloader
{
/**
* @var array<string, string>
*/
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)
{

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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