1
0
Fork 0

Fix deprecation warnings with strpos receiving null

pull/10061/head
Jordi Boggiano 2021-08-18 15:51:58 +02:00
parent 0b09e08f4b
commit 5062619046
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
2 changed files with 43 additions and 68 deletions

View File

@ -69,7 +69,7 @@ class GitDownloaderTest extends TestCase
protected function getDownloaderMock($io = null, $config = null, $executor = null, $filesystem = null)
{
$io = $io ?: $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
$executor = $executor ?: $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
$executor = $executor ?: $this->getMockBuilder('Composer\Util\ProcessExecutor')->setMethods(array('execute'))->getMock();
$filesystem = $filesystem ?: $this->getMockBuilder('Composer\Util\Filesystem')->getMock();
$config = $this->setupConfig($config);
@ -107,7 +107,7 @@ class GitDownloaderTest extends TestCase
$packageMock->expects($this->any())
->method('getPrettyVersion')
->will($this->returnValue('dev-master'));
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->setMethods(array('execute'))->getMock();
$expectedGitCommand = $this->winCompat("git clone --no-checkout -- 'https://example.com/composer/composer' 'composerPath' && cd 'composerPath' && git remote add composer -- 'https://example.com/composer/composer' && git fetch composer && git remote set-url origin -- 'https://example.com/composer/composer' && git remote set-url composer -- 'https://example.com/composer/composer'");
$processExecutor->expects($this->at(0))
@ -147,7 +147,7 @@ class GitDownloaderTest extends TestCase
$packageMock->expects($this->any())
->method('getPrettyVersion')
->will($this->returnValue('dev-master'));
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->setMethods(array('execute'))->getMock();
$this->initGitVersion('2.17.0');
@ -219,7 +219,7 @@ class GitDownloaderTest extends TestCase
$packageMock->expects($this->any())
->method('getPrettyVersion')
->will($this->returnValue('1.0.0'));
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->setMethods(array('execute', 'getErrorOutput'))->getMock();
$expectedGitCommand = $this->winCompat("git clone --no-checkout -- 'https://github.com/mirrors/composer' 'composerPath' && cd 'composerPath' && git remote add composer -- 'https://github.com/mirrors/composer' && git fetch composer && git remote set-url origin -- 'https://github.com/mirrors/composer' && git remote set-url composer -- 'https://github.com/mirrors/composer'");
$processExecutor->expects($this->at(0))
@ -297,7 +297,7 @@ class GitDownloaderTest extends TestCase
$packageMock->expects($this->any())
->method('getPrettyVersion')
->will($this->returnValue('1.0.0'));
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->setMethods(array('execute'))->getMock();
$expectedGitCommand = $this->winCompat("git clone --no-checkout -- '{$url}' 'composerPath' && cd 'composerPath' && git remote add composer -- '{$url}' && git fetch composer && git remote set-url origin -- '{$url}' && git remote set-url composer -- '{$url}'");
$processExecutor->expects($this->at(0))
@ -335,7 +335,7 @@ class GitDownloaderTest extends TestCase
$packageMock->expects($this->any())
->method('getSourceUrls')
->will($this->returnValue(array('https://example.com/composer/composer')));
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->setMethods(array('execute'))->getMock();
$processExecutor->expects($this->at(0))
->method('execute')
->with($this->equalTo($expectedGitCommand))
@ -423,7 +423,7 @@ class GitDownloaderTest extends TestCase
->method('getVersion')
->will($this->returnValue('1.0.0.0'));
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->setMethods(array('execute'))->getMock();
$processExecutor->expects($this->at(0))
->method('execute')
->with($this->equalTo($this->winCompat("git show-ref --head -d")))
@ -589,7 +589,7 @@ composer https://github.com/old/url (push)
->method('getFullPrettyVersion')
->will($this->returnValue('1.0.0'));
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->setMethods(array('execute'))->getMock();
$processExecutor->expects($this->any())
->method('execute')
->will($this->returnValue(0));
@ -631,7 +631,7 @@ composer https://github.com/old/url (push)
->method('getVersion')
->will($this->returnValue('dev-ref2'));
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->setMethods(array('execute'))->getMock();
$processExecutor->expects($this->any())
->method('execute')
->will($this->returnValue(0));
@ -654,7 +654,7 @@ composer https://github.com/old/url (push)
$expectedGitResetCommand = $this->winCompat("cd 'composerPath' && git status --porcelain --untracked-files=no");
$packageMock = $this->getMockBuilder('Composer\Package\PackageInterface')->getMock();
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->setMethods(array('execute'))->getMock();
$processExecutor->expects($this->any())
->method('execute')
->with($this->equalTo($expectedGitResetCommand))

View File

@ -270,42 +270,17 @@ class VersionSelectorTest extends TestCase
/**
* @dataProvider getRecommendedRequireVersionPackages
*/
public function testFindRecommendedRequireVersion($prettyVersion, $isDev, $stability, $expectedVersion, $branchAlias = null, $packageName = null)
public function testFindRecommendedRequireVersion($prettyVersion, $expectedVersion, $branchAlias = null, $packageName = 'foo/bar')
{
$repositorySet = $this->createMockRepositorySet();
$versionSelector = new VersionSelector($repositorySet);
$versionParser = new VersionParser();
$package = $this->getMockBuilder('\Composer\Package\PackageInterface')->getMock();
$package
->expects($this->any())
->method('getPrettyVersion')
->will($this->returnValue($prettyVersion));
$package
->expects($this->any())
->method('getName')
->will($this->returnValue($packageName));
$package
->expects($this->any())
->method('getVersion')
->will($this->returnValue($versionParser->normalize($prettyVersion)));
$package
->expects($this->any())
->method('isDev')
->will($this->returnValue($isDev));
$package
->expects($this->any())
->method('getStability')
->will($this->returnValue($stability));
$package
->expects($this->any())
->method('getTransportOptions')
->will($this->returnValue(array()));
$package = new Package($packageName, $versionParser->normalize($prettyVersion), $prettyVersion);
$branchAlias = $branchAlias === null ? array() : array('branch-alias' => array($prettyVersion => $branchAlias));
$package->expects($this->any())
->method('getExtra')
->will($this->returnValue($branchAlias));
if ($branchAlias) {
$package->setExtra(array('branch-alias' => array($prettyVersion => $branchAlias)));
}
$recommended = $versionSelector->findRecommendedRequireVersion($package);
@ -316,40 +291,40 @@ class VersionSelectorTest extends TestCase
public function getRecommendedRequireVersionPackages()
{
return array(
// real version, is dev package, stability, expected recommendation, [branch-alias], [pkg name]
array('1.2.1', false, 'stable', '^1.2'),
array('1.2', false, 'stable', '^1.2'),
array('v1.2.1', false, 'stable', '^1.2'),
array('3.1.2-pl2', false, 'stable', '^3.1'),
array('3.1.2-patch', false, 'stable', '^3.1'),
array('2.0-beta.1', false, 'beta', '^2.0@beta'),
array('3.1.2-alpha5', false, 'alpha', '^3.1@alpha'),
array('3.0-RC2', false, 'RC', '^3.0@RC'),
array('0.1.0', false, 'stable', '^0.1.0'),
array('0.1.3', false, 'stable', '^0.1.3'),
array('0.0.3', false, 'stable', '^0.0.3'),
array('0.0.3-alpha', false, 'alpha', '^0.0.3@alpha'),
// real version, expected recommendation, [branch-alias], [pkg name]
array('1.2.1', '^1.2'),
array('1.2', '^1.2'),
array('v1.2.1', '^1.2'),
array('3.1.2-pl2', '^3.1'),
array('3.1.2-patch', '^3.1'),
array('2.0-beta.1', '^2.0@beta'),
array('3.1.2-alpha5', '^3.1@alpha'),
array('3.0-RC2', '^3.0@RC'),
array('0.1.0', '^0.1.0'),
array('0.1.3', '^0.1.3'),
array('0.0.3', '^0.0.3'),
array('0.0.3-alpha', '^0.0.3@alpha'),
// date-based versions are not touched at all
array('v20121020', false, 'stable', 'v20121020'),
array('v20121020.2', false, 'stable', 'v20121020.2'),
array('v20121020', 'v20121020'),
array('v20121020.2', 'v20121020.2'),
// dev packages without alias are not touched at all
array('dev-master', true, 'dev', 'dev-master'),
array('3.1.2-dev', true, 'dev', '3.1.2-dev'),
array('dev-master', 'dev-master'),
array('3.1.2-dev', '3.1.2-dev'),
// dev packages with alias inherit the alias
array('dev-master', true, 'dev', '^2.1@dev', '2.1.x-dev'),
array('dev-master', true, 'dev', '^2.1@dev', '2.1-dev'),
array('dev-master', true, 'dev', '^2.1@dev', '2.1.3.x-dev'),
array('dev-master', true, 'dev', '^2.0@dev', '2.x-dev'),
array('dev-master', true, 'dev', '^0.3.0@dev', '0.3.x-dev'),
array('dev-master', true, 'dev', '^0.0.3@dev', '0.0.3.x-dev'),
array('dev-master', true, 'dev', 'dev-master', VersionParser::DEFAULT_BRANCH_ALIAS),
array('dev-master', '^2.1@dev', '2.1.x-dev'),
array('dev-master', '^2.1@dev', '2.1-dev'),
array('dev-master', '^2.1@dev', '2.1.3.x-dev'),
array('dev-master', '^2.0@dev', '2.x-dev'),
array('dev-master', '^0.3.0@dev', '0.3.x-dev'),
array('dev-master', '^0.0.3@dev', '0.0.3.x-dev'),
array('dev-master', 'dev-master', VersionParser::DEFAULT_BRANCH_ALIAS),
// numeric alias
array('3.x-dev', true, 'dev', '^3.0@dev', '3.0.x-dev'),
array('3.x-dev', true, 'dev', '^3.0@dev', '3.0-dev'),
array('3.x-dev', '^3.0@dev', '3.0.x-dev'),
array('3.x-dev', '^3.0@dev', '3.0-dev'),
// ext in sync with php
array(PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION, false, 'stable', '*', null, 'ext-filter'),
array(PHP_MAJOR_VERSION . '.' . PHP_MINOR_VERSION . '.' . PHP_RELEASE_VERSION, '*', null, 'ext-filter'),
// ext versioned individually
array('3.0.5', false, 'stable', '^3.0', null, 'ext-xdebug'),
array('3.0.5', '^3.0', null, 'ext-xdebug'),
);
}