1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-10 09:02:59 +00:00

Fix many PHPStan issues and update baseline

This commit is contained in:
Jordi Boggiano 2021-12-09 22:14:04 +01:00
parent 6ed3aeb343
commit 96486d81cb
No known key found for this signature in database
GPG key ID: 7BBD42C429EC80BC
21 changed files with 252 additions and 361 deletions

View file

@ -950,11 +950,6 @@ parameters:
count: 1 count: 1
path: ../src/Composer/Command/GlobalCommand.php path: ../src/Composer/Command/GlobalCommand.php
-
message: "#^Return type \\(int\\|void\\) of method Composer\\\\Command\\\\GlobalCommand\\:\\:run\\(\\) should be covariant with return type \\(int\\) of method Symfony\\\\Component\\\\Console\\\\Command\\\\Command\\:\\:run\\(\\)$#"
count: 1
path: ../src/Composer/Command/GlobalCommand.php
- -
message: "#^Cannot call method getPackage\\(\\) on Composer\\\\Composer\\|null\\.$#" message: "#^Cannot call method getPackage\\(\\) on Composer\\\\Composer\\|null\\.$#"
count: 1 count: 1
@ -2440,16 +2435,6 @@ parameters:
count: 3 count: 3
path: ../src/Composer/Compiler.php path: ../src/Composer/Compiler.php
-
message: "#^Only booleans are allowed in an if condition, array\\<int, bool\\|string\\> given\\.$#"
count: 1
path: ../src/Composer/Compiler.php
-
message: "#^Only booleans are allowed in an if condition, array\\<int, string\\> given\\.$#"
count: 1
path: ../src/Composer/Compiler.php
- -
message: "#^Parameter \\#1 \\$haystack of function strpos expects string, string\\|false given\\.$#" message: "#^Parameter \\#1 \\$haystack of function strpos expects string, string\\|false given\\.$#"
count: 1 count: 1
@ -4235,6 +4220,11 @@ parameters:
count: 2 count: 2
path: ../src/Composer/Installer/InstallationManager.php path: ../src/Composer/Installer/InstallationManager.php
-
message: "#^Constant PHP_WINDOWS_EVENT_CTRL_C not found\\.$#"
count: 1
path: ../src/Composer/Installer/InstallationManager.php
- -
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 1 count: 1
@ -4245,6 +4235,11 @@ parameters:
count: 2 count: 2
path: ../src/Composer/Installer/InstallationManager.php path: ../src/Composer/Installer/InstallationManager.php
-
message: "#^Function sapi_windows_set_ctrl_handler not found\\.$#"
count: 3
path: ../src/Composer/Installer/InstallationManager.php
- -
message: "#^Only booleans are allowed in &&, Composer\\\\EventDispatcher\\\\EventDispatcher\\|null given on the right side\\.$#" message: "#^Only booleans are allowed in &&, Composer\\\\EventDispatcher\\\\EventDispatcher\\|null given on the right side\\.$#"
count: 2 count: 2
@ -6745,6 +6740,16 @@ parameters:
count: 2 count: 2
path: ../src/Composer/Util/Http/CurlDownloader.php path: ../src/Composer/Util/Http/CurlDownloader.php
-
message: "#^Constant CURLOPT_PROXY_CAINFO not found\\.$#"
count: 1
path: ../src/Composer/Util/Http/CurlDownloader.php
-
message: "#^Constant CURLOPT_PROXY_CAPATH not found\\.$#"
count: 1
path: ../src/Composer/Util/Http/CurlDownloader.php
- -
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
count: 3 count: 3
@ -8450,12 +8455,12 @@ parameters:
path: ../tests/Composer/Test/Json/JsonValidationExceptionTest.php path: ../tests/Composer/Test/Json/JsonValidationExceptionTest.php
- -
message: "#^Composer\\\\Test\\\\Mock\\\\HttpDownloaderMock\\:\\:__construct\\(\\) does not call parent constructor from Composer\\\\Util\\\\HttpDownloader\\.$#" message: "#^Property Composer\\\\Test\\\\Mock\\\\HttpDownloaderMock\\:\\:\\$defaultHandler \\(array\\{status\\: int, body\\: string, headers\\: array\\<string\\>\\}\\) does not accept non\\-empty\\-array\\<literal\\-string&non\\-empty\\-string, array\\<string\\>\\|int\\|string\\>\\.$#"
count: 1 count: 1
path: ../tests/Composer/Test/Mock/HttpDownloaderMock.php path: ../tests/Composer/Test/Mock/HttpDownloaderMock.php
- -
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#" message: "#^Property Composer\\\\Test\\\\Mock\\\\HttpDownloaderMock\\:\\:\\$expectations \\(array\\<array\\{url\\: string, options\\: array\\|null, status\\: int, body\\: string, headers\\: array\\<int, string\\>\\}\\>\\|null\\) does not accept array\\<non\\-empty\\-array\\<literal\\-string&non\\-empty\\-string, array\\|int\\|string\\|null\\>\\>\\.$#"
count: 1 count: 1
path: ../tests/Composer/Test/Mock/HttpDownloaderMock.php path: ../tests/Composer/Test/Mock/HttpDownloaderMock.php
@ -8469,31 +8474,11 @@ parameters:
count: 1 count: 1
path: ../tests/Composer/Test/Mock/InstallationManagerMock.php path: ../tests/Composer/Test/Mock/InstallationManagerMock.php
-
message: "#^Call to method PHPUnit\\\\Framework\\\\Assert\\:\\:assertTrue\\(\\) with true will always evaluate to true\\.$#"
count: 1
path: ../tests/Composer/Test/Mock/ProcessExecutorMock.php
-
message: "#^Only booleans are allowed in &&, array\\<array\\<string, \\(callable\\)\\|int\\|string\\|null\\>\\> given on the left side\\.$#"
count: 1
path: ../tests/Composer/Test/Mock/ProcessExecutorMock.php
-
message: "#^Only booleans are allowed in a ternary operator condition, array\\<array\\<string, \\(callable\\)\\|int\\|string\\|null\\>\\> given\\.$#"
count: 1
path: ../tests/Composer/Test/Mock/ProcessExecutorMock.php
- -
message: "#^Only booleans are allowed in an elseif condition, array\\<string, \\(callable\\)\\|int\\|string\\|null\\> given\\.$#" message: "#^Only booleans are allowed in an elseif condition, array\\<string, \\(callable\\)\\|int\\|string\\|null\\> given\\.$#"
count: 1 count: 1
path: ../tests/Composer/Test/Mock/ProcessExecutorMock.php path: ../tests/Composer/Test/Mock/ProcessExecutorMock.php
-
message: "#^Only booleans are allowed in an if condition, array\\<array\\<string, \\(callable\\)\\|int\\|string\\|null\\>\\> given\\.$#"
count: 1
path: ../tests/Composer/Test/Mock/ProcessExecutorMock.php
- -
message: "#^Only booleans are allowed in an if condition, string given\\.$#" message: "#^Only booleans are allowed in an if condition, string given\\.$#"
count: 2 count: 2
@ -8510,7 +8495,7 @@ parameters:
path: ../tests/Composer/Test/Mock/ProcessExecutorMock.php path: ../tests/Composer/Test/Mock/ProcessExecutorMock.php
- -
message: "#^Property Composer\\\\Test\\\\Mock\\\\ProcessExecutorMock\\:\\:\\$expectations \\(array\\<array\\{cmd\\: string, return\\: int, stdout\\: string, stderr\\: string, callback\\: \\(callable\\(\\)\\: mixed\\)\\|null\\}\\>\\) does not accept array\\<non\\-empty\\-array\\<literal\\-string&non\\-empty\\-string, \\(callable\\(\\)\\: mixed\\)\\|int\\|string\\|null\\>\\>\\.$#" message: "#^Property Composer\\\\Test\\\\Mock\\\\ProcessExecutorMock\\:\\:\\$expectations \\(array\\<array\\{cmd\\: string, return\\: int, stdout\\: string, stderr\\: string, callback\\: \\(callable\\(\\)\\: mixed\\)\\|null\\}\\>\\|null\\) does not accept array\\<non\\-empty\\-array\\<literal\\-string&non\\-empty\\-string, \\(callable\\(\\)\\: mixed\\)\\|int\\|string\\|null\\>\\>\\.$#"
count: 1 count: 1
path: ../tests/Composer/Test/Mock/ProcessExecutorMock.php path: ../tests/Composer/Test/Mock/ProcessExecutorMock.php
@ -8824,11 +8809,6 @@ parameters:
count: 1 count: 1
path: ../tests/Composer/Test/Repository/RepositoryManagerTest.php path: ../tests/Composer/Test/Repository/RepositoryManagerTest.php
-
message: "#^Only booleans are allowed in an if condition, string\\|null given\\.$#"
count: 1
path: ../tests/Composer/Test/Repository/RepositoryManagerTest.php
- -
message: "#^Dynamic call to static method Composer\\\\Test\\\\TestCase\\:\\:getUniqueTmpDirectory\\(\\)\\.$#" message: "#^Dynamic call to static method Composer\\\\Test\\\\TestCase\\:\\:getUniqueTmpDirectory\\(\\)\\.$#"
count: 1 count: 1
@ -8869,31 +8849,6 @@ parameters:
count: 1 count: 1
path: ../tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php path: ../tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php
-
message: "#^Parameter \\#1 \\$io of static method Composer\\\\Repository\\\\Vcs\\\\GitLabDriver\\:\\:supports\\(\\) expects Composer\\\\IO\\\\IOInterface, object given\\.$#"
count: 1
path: ../tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php
-
message: "#^Parameter \\#2 \\$io of class Composer\\\\Repository\\\\Vcs\\\\GitLabDriver constructor expects Composer\\\\IO\\\\IOInterface, object given\\.$#"
count: 9
path: ../tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php
-
message: "#^Parameter \\#4 \\$body of class Composer\\\\Util\\\\Http\\\\Response constructor expects string\\|null, string\\|false given\\.$#"
count: 2
path: ../tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php
-
message: "#^Parameter \\#4 \\$httpDownloader of class Composer\\\\Repository\\\\Vcs\\\\GitLabDriver constructor expects Composer\\\\Util\\\\HttpDownloader, object given\\.$#"
count: 9
path: ../tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php
-
message: "#^Parameter \\#5 \\$process of class Composer\\\\Repository\\\\Vcs\\\\GitLabDriver constructor expects Composer\\\\Util\\\\ProcessExecutor, object given\\.$#"
count: 9
path: ../tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php
- -
message: "#^Dynamic call to static method Composer\\\\Test\\\\TestCase\\:\\:getUniqueTmpDirectory\\(\\)\\.$#" message: "#^Dynamic call to static method Composer\\\\Test\\\\TestCase\\:\\:getUniqueTmpDirectory\\(\\)\\.$#"
count: 1 count: 1
@ -8944,11 +8899,6 @@ parameters:
count: 1 count: 1
path: ../tests/Composer/Test/Repository/VcsRepositoryTest.php path: ../tests/Composer/Test/Repository/VcsRepositoryTest.php
-
message: "#^Call to function method_exists\\(\\) with \\$this\\(Composer\\\\Test\\\\TestCase\\) and 'expectException' will always evaluate to true\\.$#"
count: 1
path: ../tests/Composer/Test/TestCase.php
- -
message: "#^Method Composer\\\\Test\\\\TestCase\\:\\:getPackage\\(\\) should return Composer\\\\Package\\\\CompleteAliasPackage\\|Composer\\\\Package\\\\CompletePackage but returns PackageClass of Composer\\\\Package\\\\PackageInterface\\.$#" message: "#^Method Composer\\\\Test\\\\TestCase\\:\\:getPackage\\(\\) should return Composer\\\\Package\\\\CompleteAliasPackage\\|Composer\\\\Package\\\\CompletePackage but returns PackageClass of Composer\\\\Package\\\\PackageInterface\\.$#"
count: 1 count: 1

View file

@ -49,7 +49,7 @@ parameters:
# PHPUnit assertions as instance methods # PHPUnit assertions as instance methods
- '~Dynamic call to static method PHPUnit\\Framework\\Assert::\w+\(\)~' - '~Dynamic call to static method PHPUnit\\Framework\\Assert::\w+\(\)~'
- '~Dynamic call to static method PHPUnit\\Framework\\TestCase::(once|at|exactly|will|exactly|returnValue|returnCallback|any|atLeastOnce|throwException|onConsecutiveCalls|never|returnValueMap)\(\)~' - '~Dynamic call to static method PHPUnit\\Framework\\TestCase::(once|atLeast|exactly|will|exactly|returnValue|returnCallback|any|atLeastOnce|throwException|onConsecutiveCalls|never|returnValueMap)\(\)~'
bootstrapFiles: bootstrapFiles:
- ./locate-phpunit-autoloader.php - ./locate-phpunit-autoloader.php

View file

@ -178,10 +178,10 @@ class Compiler
} }
} }
if ($extraFiles) { if (count($extraFiles) > 0) {
throw new \RuntimeException('These files were expected but not added to the phar, they might be excluded or gone from the source package:'.PHP_EOL.var_export($extraFiles, true)); throw new \RuntimeException('These files were expected but not added to the phar, they might be excluded or gone from the source package:'.PHP_EOL.var_export($extraFiles, true));
} }
if ($unexpectedFiles) { if (count($unexpectedFiles) > 0) {
throw new \RuntimeException('These files were unexpectedly added to the phar, make sure they are excluded or listed in $extraFiles:'.PHP_EOL.var_export($unexpectedFiles, true)); throw new \RuntimeException('These files were unexpectedly added to the phar, make sure they are excluded or listed in $extraFiles:'.PHP_EOL.var_export($unexpectedFiles, true));
} }

View file

@ -98,9 +98,7 @@ class Perforce
*/ */
public static function checkServerExists($url, ProcessExecutor $processExecutor) public static function checkServerExists($url, ProcessExecutor $processExecutor)
{ {
$output = null; return 0 === $processExecutor->execute('p4 -p ' . ProcessExecutor::escape($url) . ' info -s', $ignoredOutput);
return 0 === $processExecutor->execute('p4 -p ' . ProcessExecutor::escape($url) . ' info -s', $output);
} }
/** /**

View file

@ -44,7 +44,7 @@ class CacheTest extends TestCase
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); $io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
$this->cache = $this->getMockBuilder('Composer\Cache') $this->cache = $this->getMockBuilder('Composer\Cache')
->setMethods(array('getFinder')) ->onlyMethods(array('getFinder'))
->setConstructorArgs(array($io, $this->root)) ->setConstructorArgs(array($io, $this->root))
->getMock(); ->getMock();
$this->cache $this->cache

View file

@ -49,17 +49,14 @@ class ArchiveCommandTest extends TestCase
$composer->setPackage($package); $composer->setPackage($package);
$command = $this->getMockBuilder('Composer\Command\ArchiveCommand') $command = $this->getMockBuilder('Composer\Command\ArchiveCommand')
->setMethods(array( ->onlyMethods(array(
'mergeApplicationDefinition', 'mergeApplicationDefinition',
'bind',
'getSynopsis', 'getSynopsis',
'initialize', 'initialize',
'isInteractive',
'getComposer', 'getComposer',
))->getMock(); ))->getMock();
$command->expects($this->atLeastOnce())->method('getComposer') $command->expects($this->atLeastOnce())->method('getComposer')
->willReturn($composer); ->willReturn($composer);
$command->method('isInteractive')->willReturn(false);
$command->run($input, $output); $command->run($input, $output);
} }
@ -73,12 +70,10 @@ class ArchiveCommandTest extends TestCase
$config = Factory::createConfig(); $config = Factory::createConfig();
$command = $this->getMockBuilder('Composer\Command\ArchiveCommand') $command = $this->getMockBuilder('Composer\Command\ArchiveCommand')
->setMethods(array( ->onlyMethods(array(
'mergeApplicationDefinition', 'mergeApplicationDefinition',
'bind',
'getSynopsis', 'getSynopsis',
'initialize', 'initialize',
'isInteractive',
'getComposer', 'getComposer',
'archive', 'archive',
))->getMock(); ))->getMock();
@ -96,7 +91,6 @@ class ArchiveCommandTest extends TestCase
false, false,
null null
)->willReturn(0); )->willReturn(0);
$command->method('isInteractive')->willReturn(false);
$this->assertEquals(0, $command->run($input, $output)); $this->assertEquals(0, $command->run($input, $output));
} }

View file

@ -47,6 +47,9 @@ class RunScriptCommandTest extends TestCase
->method('hasArgument') ->method('hasArgument')
->with('command') ->with('command')
->willReturn(false); ->willReturn(false);
$input
->method('isInteractive')
->willReturn(false);
$output = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')->getMock(); $output = $this->getMockBuilder('Symfony\Component\Console\Output\OutputInterface')->getMock();
@ -73,17 +76,14 @@ class RunScriptCommandTest extends TestCase
$composer->setEventDispatcher($ed); $composer->setEventDispatcher($ed);
$command = $this->getMockBuilder('Composer\Command\RunScriptCommand') $command = $this->getMockBuilder('Composer\Command\RunScriptCommand')
->setMethods(array( ->onlyMethods(array(
'mergeApplicationDefinition', 'mergeApplicationDefinition',
'bind',
'getSynopsis', 'getSynopsis',
'initialize', 'initialize',
'isInteractive',
'getComposer', 'getComposer',
)) ))
->getMock(); ->getMock();
$command->expects($this->any())->method('getComposer')->willReturn($composer); $command->expects($this->any())->method('getComposer')->willReturn($composer);
$command->method('isInteractive')->willReturn(false);
$command->run($input, $output); $command->run($input, $output);
} }

View file

@ -76,7 +76,7 @@ class DownloadManagerTest extends TestCase
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
->setMethods(array('getDownloader')) ->onlyMethods(array('getDownloader'))
->getMock(); ->getMock();
$manager $manager
@ -108,7 +108,7 @@ class DownloadManagerTest extends TestCase
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
->setMethods(array('getDownloader')) ->onlyMethods(array('getDownloader'))
->getMock(); ->getMock();
$manager $manager
@ -142,7 +142,7 @@ class DownloadManagerTest extends TestCase
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
->setMethods(array('getDownloader')) ->onlyMethods(array('getDownloader'))
->getMock(); ->getMock();
$manager $manager
@ -174,7 +174,7 @@ class DownloadManagerTest extends TestCase
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
->setMethods(array('getDownloader')) ->onlyMethods(array('getDownloader'))
->getMock(); ->getMock();
$manager $manager
@ -226,7 +226,7 @@ class DownloadManagerTest extends TestCase
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
->setMethods(array('getDownloaderForPackage')) ->onlyMethods(array('getDownloaderForPackage'))
->getMock(); ->getMock();
$manager $manager
->expects($this->once()) ->expects($this->once())
@ -276,7 +276,7 @@ class DownloadManagerTest extends TestCase
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
->setMethods(array('getDownloaderForPackage')) ->onlyMethods(array('getDownloaderForPackage'))
->getMock(); ->getMock();
$manager $manager
->expects($this->exactly(2)) ->expects($this->exactly(2))
@ -333,7 +333,7 @@ class DownloadManagerTest extends TestCase
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
->setMethods(array('getDownloaderForPackage')) ->onlyMethods(array('getDownloaderForPackage'))
->getMock(); ->getMock();
$manager $manager
->expects($this->once()) ->expects($this->once())
@ -369,7 +369,7 @@ class DownloadManagerTest extends TestCase
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
->setMethods(array('getDownloaderForPackage')) ->onlyMethods(array('getDownloaderForPackage'))
->getMock(); ->getMock();
$manager $manager
->expects($this->once()) ->expects($this->once())
@ -399,7 +399,7 @@ class DownloadManagerTest extends TestCase
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
->setMethods(array('getDownloaderForPackage')) ->onlyMethods(array('getDownloaderForPackage'))
->getMock(); ->getMock();
$manager $manager
->expects($this->once()) ->expects($this->once())
@ -435,7 +435,7 @@ class DownloadManagerTest extends TestCase
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
->setMethods(array('getDownloaderForPackage')) ->onlyMethods(array('getDownloaderForPackage'))
->getMock(); ->getMock();
$manager $manager
->expects($this->once()) ->expects($this->once())
@ -472,7 +472,7 @@ class DownloadManagerTest extends TestCase
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
->setMethods(array('getDownloaderForPackage')) ->onlyMethods(array('getDownloaderForPackage'))
->getMock(); ->getMock();
$manager $manager
->expects($this->once()) ->expects($this->once())
@ -509,7 +509,7 @@ class DownloadManagerTest extends TestCase
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
->setMethods(array('getDownloaderForPackage')) ->onlyMethods(array('getDownloaderForPackage'))
->getMock(); ->getMock();
$manager $manager
->expects($this->once()) ->expects($this->once())
@ -685,7 +685,7 @@ class DownloadManagerTest extends TestCase
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
->setMethods(array('getDownloaderForPackage')) ->onlyMethods(array('getDownloaderForPackage'))
->getMock(); ->getMock();
$manager $manager
->expects($this->exactly(2)) ->expects($this->exactly(2))
@ -708,7 +708,7 @@ class DownloadManagerTest extends TestCase
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
->setMethods(array('getDownloaderForPackage')) ->onlyMethods(array('getDownloaderForPackage'))
->getMock(); ->getMock();
$manager $manager
->expects($this->once()) ->expects($this->once())
@ -725,7 +725,7 @@ class DownloadManagerTest extends TestCase
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
->setMethods(array('getDownloaderForPackage')) ->onlyMethods(array('getDownloaderForPackage'))
->getMock(); ->getMock();
$manager $manager
->expects($this->once()) ->expects($this->once())
@ -768,7 +768,7 @@ class DownloadManagerTest extends TestCase
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
->setMethods(array('getDownloaderForPackage')) ->onlyMethods(array('getDownloaderForPackage'))
->getMock(); ->getMock();
$manager $manager
->expects($this->once()) ->expects($this->once())
@ -811,7 +811,7 @@ class DownloadManagerTest extends TestCase
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
->setMethods(array('getDownloaderForPackage')) ->onlyMethods(array('getDownloaderForPackage'))
->getMock(); ->getMock();
$manager $manager
->expects($this->once()) ->expects($this->once())
@ -857,7 +857,7 @@ class DownloadManagerTest extends TestCase
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
->setMethods(array('getDownloaderForPackage')) ->onlyMethods(array('getDownloaderForPackage'))
->getMock(); ->getMock();
$manager $manager
->expects($this->once()) ->expects($this->once())
@ -904,7 +904,7 @@ class DownloadManagerTest extends TestCase
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
->setMethods(array('getDownloaderForPackage')) ->onlyMethods(array('getDownloaderForPackage'))
->getMock(); ->getMock();
$manager $manager
->expects($this->once()) ->expects($this->once())
@ -951,7 +951,7 @@ class DownloadManagerTest extends TestCase
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
->setMethods(array('getDownloaderForPackage')) ->onlyMethods(array('getDownloaderForPackage'))
->getMock(); ->getMock();
$manager $manager
->expects($this->once()) ->expects($this->once())
@ -998,7 +998,7 @@ class DownloadManagerTest extends TestCase
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
->setMethods(array('getDownloaderForPackage')) ->onlyMethods(array('getDownloaderForPackage'))
->getMock(); ->getMock();
$manager $manager
->expects($this->once()) ->expects($this->once())
@ -1041,7 +1041,7 @@ class DownloadManagerTest extends TestCase
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
->setMethods(array('getDownloaderForPackage')) ->onlyMethods(array('getDownloaderForPackage'))
->getMock(); ->getMock();
$manager $manager
->expects($this->once()) ->expects($this->once())
@ -1084,7 +1084,7 @@ class DownloadManagerTest extends TestCase
$manager = $this->getMockBuilder('Composer\Downloader\DownloadManager') $manager = $this->getMockBuilder('Composer\Downloader\DownloadManager')
->setConstructorArgs(array($this->io, false, $this->filesystem)) ->setConstructorArgs(array($this->io, false, $this->filesystem))
->setMethods(array('getDownloaderForPackage')) ->onlyMethods(array('getDownloaderForPackage'))
->getMock(); ->getMock();
$manager $manager
->expects($this->once()) ->expects($this->once())

View file

@ -103,7 +103,7 @@ class PerforceDownloaderTest extends TestCase
protected function getMockRepository(array $repoConfig, IOInterface $io, Config $config) protected function getMockRepository(array $repoConfig, IOInterface $io, Config $config)
{ {
$repository = $this->getMockBuilder('Composer\Repository\VcsRepository') $repository = $this->getMockBuilder('Composer\Repository\VcsRepository')
->setMethods(array('getRepoConfig')) ->onlyMethods(array('getRepoConfig'))
->setConstructorArgs(array($repoConfig, $io, $config, Factory::createHttpDownloader($io, $config))) ->setConstructorArgs(array($repoConfig, $io, $config, Factory::createHttpDownloader($io, $config)))
->getMock(); ->getMock();
$repository->expects($this->any())->method('getRepoConfig')->will($this->returnValue($repoConfig)); $repository->expects($this->any())->method('getRepoConfig')->will($this->returnValue($repoConfig));

View file

@ -70,7 +70,7 @@ class EventDispatcherTest extends TestCase
$this->getMockBuilder('Composer\IO\IOInterface')->getMock(), $this->getMockBuilder('Composer\IO\IOInterface')->getMock(),
$process, $process,
)) ))
->setMethods(array('getListeners')) ->onlyMethods(array('getListeners'))
->getMock(); ->getMock();
$listener = array($command); $listener = array($command);
@ -136,7 +136,7 @@ class EventDispatcherTest extends TestCase
{ {
$generator = $this->getMockBuilder('Composer\Autoload\AutoloadGenerator') $generator = $this->getMockBuilder('Composer\Autoload\AutoloadGenerator')
->disableOriginalConstructor() ->disableOriginalConstructor()
->setMethods(array( ->onlyMethods(array(
'buildPackageMap', 'buildPackageMap',
'parseAutoloads', 'parseAutoloads',
'createLoader', 'createLoader',
@ -163,7 +163,7 @@ class EventDispatcherTest extends TestCase
{ {
$rm = $this->getMockBuilder('Composer\Repository\RepositoryManager') $rm = $this->getMockBuilder('Composer\Repository\RepositoryManager')
->disableOriginalConstructor() ->disableOriginalConstructor()
->setMethods(array('getLocalRepository')) ->onlyMethods(array('getLocalRepository'))
->getMock(); ->getMock();
$repo = $this->getMockBuilder('Composer\Repository\InstalledRepositoryInterface')->getMock(); $repo = $this->getMockBuilder('Composer\Repository\InstalledRepositoryInterface')->getMock();
@ -235,7 +235,7 @@ class EventDispatcherTest extends TestCase
$io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE), $io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE),
$process, $process,
)) ))
->setMethods(array( ->onlyMethods(array(
'getListeners', 'getListeners',
)) ))
->getMock(); ->getMock();
@ -266,7 +266,7 @@ class EventDispatcherTest extends TestCase
$io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE), $io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE),
$this->getProcessExecutorMock(), $this->getProcessExecutorMock(),
)) ))
->setMethods(array( ->onlyMethods(array(
'getListeners', 'getListeners',
)) ))
->getMock(); ->getMock();
@ -298,7 +298,7 @@ class EventDispatcherTest extends TestCase
$this->createComposerInstance(), $this->createComposerInstance(),
$io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE), $io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE),
$this->getProcessExecutorMock(), $this->getProcessExecutorMock(),
))->setMethods(array( ))->onlyMethods(array(
'getListeners', 'getListeners',
))->getMock(); ))->getMock();
@ -376,7 +376,7 @@ class EventDispatcherTest extends TestCase
$io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE), $io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE),
$process, $process,
)) ))
->setMethods(array( ->onlyMethods(array(
'getListeners', 'getListeners',
)) ))
->getMock(); ->getMock();
@ -421,7 +421,7 @@ class EventDispatcherTest extends TestCase
$io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE), $io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE),
$process, $process,
)) ))
->setMethods(array( ->onlyMethods(array(
'getListeners', 'getListeners',
)) ))
->getMock(); ->getMock();
@ -457,7 +457,7 @@ class EventDispatcherTest extends TestCase
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock(), $io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock(),
$this->getProcessExecutorMock(), $this->getProcessExecutorMock(),
)) ))
->setMethods(array( ->onlyMethods(array(
'getListeners', 'getListeners',
)) ))
->getMock(); ->getMock();
@ -491,7 +491,7 @@ class EventDispatcherTest extends TestCase
$this->createComposerInstance(), $this->createComposerInstance(),
$io, $io,
)) ))
->setMethods(array('getListeners')) ->onlyMethods(array('getListeners'))
->getMock(); ->getMock();
$dispatcher->expects($this->atLeastOnce()) $dispatcher->expects($this->atLeastOnce())
@ -518,7 +518,7 @@ class EventDispatcherTest extends TestCase
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock(), $io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock(),
new ProcessExecutor($io), new ProcessExecutor($io),
)) ))
->setMethods(array('getListeners')) ->onlyMethods(array('getListeners'))
->getMock(); ->getMock();
$listener = array('echo foo'); $listener = array('echo foo');
@ -545,7 +545,7 @@ class EventDispatcherTest extends TestCase
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock(), $io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock(),
new ProcessExecutor, new ProcessExecutor,
)) ))
->setMethods(array('getListeners')) ->onlyMethods(array('getListeners'))
->getMock(); ->getMock();
$code = 'exit 1'; $code = 'exit 1';
@ -581,7 +581,7 @@ class EventDispatcherTest extends TestCase
$this->getMockBuilder('Composer\IO\IOInterface')->getMock(), $this->getMockBuilder('Composer\IO\IOInterface')->getMock(),
$this->getProcessExecutorMock(), $this->getProcessExecutorMock(),
)) ))
->setMethods(array('getListeners')) ->onlyMethods(array('getListeners'))
->getMock(); ->getMock();
$dispatcher->expects($this->atLeastOnce()) $dispatcher->expects($this->atLeastOnce())

View file

@ -97,7 +97,7 @@ class InstallationManagerTest extends TestCase
{ {
$manager = $this->getMockBuilder('Composer\Installer\InstallationManager') $manager = $this->getMockBuilder('Composer\Installer\InstallationManager')
->setConstructorArgs(array($this->loop, $this->io)) ->setConstructorArgs(array($this->loop, $this->io))
->setMethods(array('install', 'update', 'uninstall')) ->onlyMethods(array('install', 'update', 'uninstall'))
->getMock(); ->getMock();
$installOperation = new InstallOperation($package = $this->createPackageMock()); $installOperation = new InstallOperation($package = $this->createPackageMock());

View file

@ -235,7 +235,7 @@ class InstallerTest extends TestCase
* @param ?string $expectOutput * @param ?string $expectOutput
* @param ?string $expectOutputOptimized * @param ?string $expectOutputOptimized
* @param string $expect * @param string $expect
* @param int|string $expectResult * @param int|class-string<\Throwable> $expectResult
*/ */
public function testSlowIntegration($file, $message, $condition, $composerConfig, $lock, $installed, $run, $expectLock, $expectInstalled, $expectOutput, $expectOutputOptimized, $expect, $expectResult) public function testSlowIntegration($file, $message, $condition, $composerConfig, $lock, $installed, $run, $expectLock, $expectInstalled, $expectOutput, $expectOutputOptimized, $expect, $expectResult)
{ {
@ -258,7 +258,7 @@ class InstallerTest extends TestCase
* @param ?string $expectOutput * @param ?string $expectOutput
* @param ?string $expectOutputOptimized * @param ?string $expectOutputOptimized
* @param string $expect * @param string $expect
* @param int|string $expectResult * @param int|class-string<\Throwable> $expectResult
*/ */
public function testIntegrationWithPoolOptimizer($file, $message, $condition, $composerConfig, $lock, $installed, $run, $expectLock, $expectInstalled, $expectOutput, $expectOutputOptimized, $expect, $expectResult) public function testIntegrationWithPoolOptimizer($file, $message, $condition, $composerConfig, $lock, $installed, $run, $expectLock, $expectInstalled, $expectOutput, $expectOutputOptimized, $expect, $expectResult)
{ {
@ -281,7 +281,7 @@ class InstallerTest extends TestCase
* @param ?string $expectOutput * @param ?string $expectOutput
* @param ?string $expectOutputOptimized * @param ?string $expectOutputOptimized
* @param string $expect * @param string $expect
* @param int|string $expectResult * @param int|class-string<\Throwable> $expectResult
*/ */
public function testIntegrationWithRawPool($file, $message, $condition, $composerConfig, $lock, $installed, $run, $expectLock, $expectInstalled, $expectOutput, $expectOutputOptimized, $expect, $expectResult) public function testIntegrationWithRawPool($file, $message, $condition, $composerConfig, $lock, $installed, $run, $expectLock, $expectInstalled, $expectOutput, $expectOutputOptimized, $expect, $expectResult)
{ {

View file

@ -56,11 +56,11 @@ class HttpDownloaderMock extends HttpDownloader
* @param bool $strict set to true if you want to provide *all* expected http requests, and not just a subset you are interested in testing * @param bool $strict set to true if you want to provide *all* expected http requests, and not just a subset you are interested in testing
* @param array{status?: int, body?: string, headers?: array<string>} $defaultHandler default URL handler for undefined requests if not in strict mode * @param array{status?: int, body?: string, headers?: array<string>} $defaultHandler default URL handler for undefined requests if not in strict mode
*/ */
public function expects(array $expectations, bool $strict = false, array $defaultHandler = array('return' => 0, 'stdout' => '', 'stderr' => '')): void public function expects(array $expectations, bool $strict = false, array $defaultHandler = array('status' => 200, 'body' => '', 'headers' => [])): void
{ {
$default = ['url' => '', 'options' => null, 'status' => 200, 'body' => '', 'headers' => ['']]; $default = ['url' => '', 'options' => null, 'status' => 200, 'body' => '', 'headers' => ['']];
$this->expectations = array_map(function (array $expect) use ($default): array { $this->expectations = array_map(function (array $expect) use ($default): array {
if ($diff = array_diff_key(array_merge($default, $expect), $default)) { if (count($diff = array_diff_key(array_merge($default, $expect), $default)) > 0) {
throw new \UnexpectedValueException('Unexpected keys in process execution step: '.implode(', ', array_keys($diff))); throw new \UnexpectedValueException('Unexpected keys in process execution step: '.implode(', ', array_keys($diff)));
} }
@ -89,7 +89,7 @@ class HttpDownloaderMock extends HttpDownloader
} }
// dummy assertion to ensure the test is not marked as having no assertions // dummy assertion to ensure the test is not marked as having no assertions
Assert::assertTrue(true); Assert::assertTrue(true); // @phpstan-ignore-line
} }
public function get($fileUrl, $options = array()): Response public function get($fileUrl, $options = array()): Response

View file

@ -26,7 +26,7 @@ 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}>|null * @var array<array{cmd: string, return: int, stdout: string, stderr: string, callback: callable|null}>|null
*/ */
private $expectations = null; private $expectations = null;
/** /**
@ -84,7 +84,7 @@ class ProcessExecutorMock extends ProcessExecutor
} }
// dummy assertion to ensure the test is not marked as having no assertions // dummy assertion to ensure the test is not marked as having no assertions
Assert::assertTrue(true); Assert::assertTrue(true); // @phpstan-ignore-line
} }
public function execute($command, &$output = null, $cwd = null) public function execute($command, &$output = null, $cwd = null)

View file

@ -283,7 +283,7 @@ class PluginInstallerTest extends TestCase
{ {
// reset the plugin manager's installed plugins // reset the plugin manager's installed plugins
$this->pm = $this->getMockBuilder('Composer\Plugin\PluginManager') $this->pm = $this->getMockBuilder('Composer\Plugin\PluginManager')
->setMethods(array('getPluginApiVersion')) ->onlyMethods(array('getPluginApiVersion'))
->setConstructorArgs(array($this->io, $this->composer)) ->setConstructorArgs(array($this->io, $this->composer))
->getMock(); ->getMock();

View file

@ -37,7 +37,7 @@ class ComposerRepositoryTest extends TestCase
); );
$repository = $this->getMockBuilder('Composer\Repository\ComposerRepository') $repository = $this->getMockBuilder('Composer\Repository\ComposerRepository')
->setMethods(array('loadRootServerFile', 'createPackages')) ->onlyMethods(array('loadRootServerFile', 'createPackages'))
->setConstructorArgs(array( ->setConstructorArgs(array(
$repoConfig, $repoConfig,
new NullIO, new NullIO,
@ -111,7 +111,7 @@ class ComposerRepositoryTest extends TestCase
$this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock(), $this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock(),
$this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')->disableOriginalConstructor()->getMock(), $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')->disableOriginalConstructor()->getMock(),
)) ))
->setMethods(array('fetchFile')) ->onlyMethods(array('fetchFile'))
->getMock(); ->getMock();
$cache = $this->getMockBuilder('Composer\Cache')->disableOriginalConstructor()->getMock(); $cache = $this->getMockBuilder('Composer\Cache')->disableOriginalConstructor()->getMock();

View file

@ -118,7 +118,7 @@ class PlatformRepositoryTest extends TestCase
* *
* @param array<string, mixed> $constants * @param array<string, mixed> $constants
* @param array<string, string> $packages * @param array<string, string> $packages
* @param array<string, mixed> $functions * @param list<array{string, list<string>, string|bool}> $functions
*/ */
public function testPhpVersion(array $constants, array $packages, array $functions = array()) public function testPhpVersion(array $constants, array $packages, array $functions = array())
{ {
@ -1086,10 +1086,11 @@ Linked Version => 1.2.11',
* @param string|string[] $extensions * @param string|string[] $extensions
* @param string|null $info * @param string|null $info
* @param array<string,string|false> $expectations * @param array<string,string|false> $expectations
* @param array<string,mixed> $functions * @param list<mixed> $functions
* @param array<string,mixed> $constants * @param list<mixed> $constants
* @param array<string,class-string> $classDefinitions * @param list<mixed> $classDefinitions
*/ */
public function testLibraryInformation( public function testLibraryInformation(
$extensions, $extensions,
$info, $info,

View file

@ -59,15 +59,15 @@ class RepositoryManagerTest extends TestCase
* @param array<string, mixed> $options * @param array<string, mixed> $options
* @param class-string<\Throwable>|null $exception * @param class-string<\Throwable>|null $exception
*/ */
public function testRepoCreation($type, $options, $exception = null) public function testRepoCreation($type, $options, ?string $exception = null)
{ {
if ($exception) { if ($exception !== null) {
self::expectException($exception); self::expectException($exception);
} }
$rm = new RepositoryManager( $rm = new RepositoryManager(
$this->getMockBuilder('Composer\IO\IOInterface')->getMock(), $this->getMockBuilder('Composer\IO\IOInterface')->getMock(),
$config = $this->getMockBuilder('Composer\Config')->setMethods(array('get'))->getMock(), $config = $this->getMockBuilder('Composer\Config')->onlyMethods(array('get'))->getMock(),
$this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock(), $this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock(),
$this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')->disableOriginalConstructor()->getMock() $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')->disableOriginalConstructor()->getMock()
); );
@ -119,7 +119,7 @@ class RepositoryManagerTest extends TestCase
{ {
$rm = new RepositoryManager( $rm = new RepositoryManager(
$this->getMockBuilder('Composer\IO\IOInterface')->getMock(), $this->getMockBuilder('Composer\IO\IOInterface')->getMock(),
$config = $this->getMockBuilder('Composer\Config')->setMethods(array('get'))->getMock(), $config = $this->getMockBuilder('Composer\Config')->onlyMethods(array('get'))->getMock(),
$this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock(), $this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock(),
$this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')->disableOriginalConstructor()->getMock() $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')->disableOriginalConstructor()->getMock()
); );

View file

@ -13,6 +13,7 @@
namespace Composer\Test\Repository\Vcs; namespace Composer\Test\Repository\Vcs;
use Composer\IO\IOInterface; use Composer\IO\IOInterface;
use Composer\Json\JsonFile;
use Composer\Repository\Vcs\GitLabDriver; use Composer\Repository\Vcs\GitLabDriver;
use Composer\Config; use Composer\Config;
use Composer\Test\Mock\HttpDownloaderMock; use Composer\Test\Mock\HttpDownloaderMock;
@ -365,7 +366,7 @@ JSON;
); );
} }
$branchData = json_encode($branchData); $branchData = JsonFile::encode($branchData);
$this->httpDownloader->expects( $this->httpDownloader->expects(
[ [

View file

@ -13,6 +13,7 @@
namespace Composer\Test\Util; namespace Composer\Test\Util;
use Composer\Json\JsonFile; use Composer\Json\JsonFile;
use Composer\Test\Mock\ProcessExecutorMock;
use Composer\Util\Perforce; use Composer\Util\Perforce;
use Composer\Test\TestCase; use Composer\Test\TestCase;
use Composer\Util\ProcessExecutor; use Composer\Util\ProcessExecutor;
@ -24,7 +25,7 @@ class PerforceTest extends TestCase
{ {
/** @var Perforce */ /** @var Perforce */
protected $perforce; protected $perforce;
/** @var \PHPUnit\Framework\MockObject\MockObject&\Composer\Util\ProcessExecutor */ /** @var ProcessExecutorMock */
protected $processExecutor; protected $processExecutor;
/** @var array<string, string> */ /** @var array<string, string> */
protected $repoConfig; protected $repoConfig;
@ -40,7 +41,7 @@ class PerforceTest extends TestCase
protected function setUp(): void protected function setUp(): void
{ {
$this->processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock(); $this->processExecutor = $this->getProcessExecutorMock();
$this->repoConfig = $this->getTestRepoConfig(); $this->repoConfig = $this->getTestRepoConfig();
$this->io = $this->getMockIOInterface(); $this->io = $this->getMockIOInterface();
$this->createNewPerforceWithWindowsFlag(true); $this->createNewPerforceWithWindowsFlag(true);
@ -80,8 +81,6 @@ class PerforceTest extends TestCase
public function testGetClientWithoutStream() public function testGetClientWithoutStream()
{ {
$client = $this->perforce->getClient(); $client = $this->perforce->getClient();
$hostname = gethostname();
$timestamp = time();
$expected = 'composer_perforce_TEST_depot'; $expected = 'composer_perforce_TEST_depot';
$this->assertEquals($expected, $client); $this->assertEquals($expected, $client);
@ -148,15 +147,11 @@ class PerforceTest extends TestCase
{ {
$this->createNewPerforceWithWindowsFlag(true); $this->createNewPerforceWithWindowsFlag(true);
$this->perforce->setUser(null); $this->perforce->setUser(null);
$expectedCommand = 'p4 set'; $this->processExecutor->expects(
$callback = function ($command, &$output) { [['cmd' => 'p4 set', 'stdout' => 'P4USER=TEST_P4VARIABLE_USER' . PHP_EOL, 'return' => 0]],
$output = 'P4USER=TEST_P4VARIABLE_USER' . PHP_EOL; true
);
return true;
};
$this->processExecutor->method('execute')
->with($this->equalTo($expectedCommand))
->willReturnCallback($callback);
$this->perforce->queryP4user(); $this->perforce->queryP4user();
$this->assertEquals('TEST_P4VARIABLE_USER', $this->perforce->getUser()); $this->assertEquals('TEST_P4VARIABLE_USER', $this->perforce->getUser());
} }
@ -165,15 +160,12 @@ class PerforceTest extends TestCase
{ {
$this->createNewPerforceWithWindowsFlag(false); $this->createNewPerforceWithWindowsFlag(false);
$this->perforce->setUser(null); $this->perforce->setUser(null);
$expectedCommand = 'echo $P4USER';
$callback = function ($command, &$output) {
$output = 'TEST_P4VARIABLE_USER' . PHP_EOL;
return true; $this->processExecutor->expects(
}; [['cmd' => 'echo $P4USER', 'stdout' => 'TEST_P4VARIABLE_USER' . PHP_EOL, 'return' => 0]],
$this->processExecutor->method('execute') true
->with($this->equalTo($expectedCommand)) );
->willReturnCallback($callback);
$this->perforce->queryP4user(); $this->perforce->queryP4user();
$this->assertEquals('TEST_P4VARIABLE_USER', $this->perforce->getUser()); $this->assertEquals('TEST_P4VARIABLE_USER', $this->perforce->getUser());
} }
@ -199,12 +191,15 @@ class PerforceTest extends TestCase
->method('ask') ->method('ask')
->with($this->equalTo($expectedQuestion)) ->with($this->equalTo($expectedQuestion))
->willReturn('TEST_QUERY_USER'); ->willReturn('TEST_QUERY_USER');
$this->processExecutor->expects($this->exactly(2))
->method('execute') $this->processExecutor->expects(
->willReturnMap([ [
['p4 set', 0], 'p4 set',
[$expectedCommand, 0], $expectedCommand
]); ],
true
);
$this->perforce->queryP4user(); $this->perforce->queryP4user();
} }
@ -218,12 +213,13 @@ class PerforceTest extends TestCase
->method('ask') ->method('ask')
->with($this->equalTo($expectedQuestion)) ->with($this->equalTo($expectedQuestion))
->willReturn('TEST_QUERY_USER'); ->willReturn('TEST_QUERY_USER');
$this->processExecutor->expects($this->exactly(2)) $this->processExecutor->expects(
->method('execute') [
->willReturnMap([ 'echo $P4USER',
['echo $P4USER', 0], $expectedCommand
$expectedCommand => 0, ],
]); true
);
$this->perforce->queryP4user(); $this->perforce->queryP4user();
} }
@ -243,15 +239,12 @@ class PerforceTest extends TestCase
public function testQueryP4PasswordWithPasswordSetInP4VariablesWithWindowsOS() public function testQueryP4PasswordWithPasswordSetInP4VariablesWithWindowsOS()
{ {
$this->createNewPerforceWithWindowsFlag(true); $this->createNewPerforceWithWindowsFlag(true);
$expectedCommand = 'p4 set';
$callback = function ($command, &$output) {
$output = 'P4PASSWD=TEST_P4VARIABLE_PASSWORD' . PHP_EOL;
return true; $this->processExecutor->expects(
}; [['cmd' => 'p4 set', 'stdout' => 'P4PASSWD=TEST_P4VARIABLE_PASSWORD' . PHP_EOL, 'return' => 0]],
$this->processExecutor->method('execute') true
->with($this->equalTo($expectedCommand)) );
->willReturnCallback($callback);
$password = $this->perforce->queryP4Password(); $password = $this->perforce->queryP4Password();
$this->assertEquals('TEST_P4VARIABLE_PASSWORD', $password); $this->assertEquals('TEST_P4VARIABLE_PASSWORD', $password);
} }
@ -259,15 +252,11 @@ class PerforceTest extends TestCase
public function testQueryP4PasswordWithPasswordSetInP4VariablesNotWindowsOS() public function testQueryP4PasswordWithPasswordSetInP4VariablesNotWindowsOS()
{ {
$this->createNewPerforceWithWindowsFlag(false); $this->createNewPerforceWithWindowsFlag(false);
$expectedCommand = 'echo $P4PASSWD';
$callback = function ($command, &$output) {
$output = 'TEST_P4VARIABLE_PASSWORD' . PHP_EOL;
return true; $this->processExecutor->expects(
}; [['cmd' => 'echo $P4PASSWD', 'stdout' => 'TEST_P4VARIABLE_PASSWORD' . PHP_EOL, 'return' => 0]],
$this->processExecutor->method('execute') true
->with($this->equalTo($expectedCommand)) );
->willReturnCallback($callback);
$password = $this->perforce->queryP4Password(); $password = $this->perforce->queryP4Password();
$this->assertEquals('TEST_P4VARIABLE_PASSWORD', $password); $this->assertEquals('TEST_P4VARIABLE_PASSWORD', $password);
@ -328,22 +317,19 @@ class PerforceTest extends TestCase
public function testIsLoggedIn() public function testIsLoggedIn()
{ {
$expectedCommand = 'p4 -u user -p port login -s'; $this->processExecutor->expects(
$this->processExecutor->expects($this->once()) [['cmd' => 'p4 -u user -p port login -s']],
->method('execute') true
->with($this->equalTo($expectedCommand), $this->equalTo(null)) );
->willReturn(0);
$this->perforce->isLoggedIn(); $this->perforce->isLoggedIn();
} }
public function testConnectClient() public function testConnectClient()
{ {
$expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot -p port client -i < path/composer_perforce_TEST_depot.p4.spec'; $this->processExecutor->expects(
$this->processExecutor->expects($this->once()) ['p4 -u user -c composer_perforce_TEST_depot -p port client -i < path/composer_perforce_TEST_depot.p4.spec'],
->method('execute') true
->with($this->equalTo($expectedCommand), $this->equalTo(null)) );
->willReturn(0);
$this->perforce->connectClient(); $this->perforce->connectClient();
} }
@ -352,26 +338,19 @@ class PerforceTest extends TestCase
{ {
$this->setPerforceToStream(); $this->setPerforceToStream();
$expectations = [ $this->processExecutor->expects(
['p4 -u user -c composer_perforce_TEST_depot_branch -p port streams '.ProcessExecutor::escape('//depot/...'), 'Stream //depot/branch mainline none \'branch\'' . PHP_EOL], [
['p4 -u user -p port changes '.ProcessExecutor::escape('//depot/branch/...'), 'Change 1234 on 2014/03/19 by Clark.Stuth@Clark.Stuth_test_client \'test changelist\''], [
]; 'cmd' => 'p4 -u user -c composer_perforce_TEST_depot_branch -p port streams '.ProcessExecutor::escape('//depot/...'),
$count = 0; 'stdout' => 'Stream //depot/branch mainline none \'branch\'' . PHP_EOL
$this->processExecutor->expects($this->exactly(2)) ],
->method('execute') [
->will( 'cmd' => 'p4 -u user -p port changes '.ProcessExecutor::escape('//depot/branch/...'),
$this->returnCallback( 'stdout' => 'Change 1234 on 2014/03/19 by Clark.Stuth@Clark.Stuth_test_client \'test changelist\''
function ($command, &$output) use ($expectations, &$count) { ],
$index = $count++; ],
if ($command !== $expectations[$index][0]) { true
throw new \InvalidArgumentException('Expected '.$expectations[$index][0].' and got '.$command); );
}
$output = $expectations[$index][1];
return 0;
}
)
);
$branches = $this->perforce->getBranches(); $branches = $this->perforce->getBranches();
$this->assertEquals('//depot/branch@1234', $branches['master']); $this->assertEquals('//depot/branch@1234', $branches['master']);
@ -379,35 +358,31 @@ class PerforceTest extends TestCase
public function testGetBranchesWithoutStream() public function testGetBranchesWithoutStream()
{ {
$expectedCommand = 'p4 -u user -p port changes '.ProcessExecutor::escape('//depot/...'); $this->processExecutor->expects(
$expectedCallback = function ($command, &$output) { [
$output = 'Change 5678 on 2014/03/19 by Clark.Stuth@Clark.Stuth_test_client \'test changelist\''; [
'cmd' => 'p4 -u user -p port changes '.ProcessExecutor::escape('//depot/...'),
'stdout' => 'Change 5678 on 2014/03/19 by Clark.Stuth@Clark.Stuth_test_client \'test changelist\''
],
],
true
);
return true;
};
$this->processExecutor->expects($this->once())
->method('execute')
->with($this->equalTo($expectedCommand))
->willReturnCallback($expectedCallback);
$branches = $this->perforce->getBranches(); $branches = $this->perforce->getBranches();
$this->assertEquals('//depot@5678', $branches['master']); $this->assertEquals('//depot@5678', $branches['master']);
} }
public function testGetTagsWithoutStream() public function testGetTagsWithoutStream()
{ {
$expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot -p port labels'; $this->processExecutor->expects(
$this->processExecutor->expects($this->once()) [
->method('execute') [
->with($this->equalTo($expectedCommand)) 'cmd' => 'p4 -u user -c composer_perforce_TEST_depot -p port labels',
->will( 'stdout' => 'Label 0.0.1 2013/07/31 \'First Label!\'' . PHP_EOL . 'Label 0.0.2 2013/08/01 \'Second Label!\'' . PHP_EOL
$this->returnCallback( ],
function ($command, &$output) { ],
$output = 'Label 0.0.1 2013/07/31 \'First Label!\'' . PHP_EOL . 'Label 0.0.2 2013/08/01 \'Second Label!\'' . PHP_EOL; true
);
return true;
}
)
);
$tags = $this->perforce->getTags(); $tags = $this->perforce->getTags();
$this->assertEquals('//depot@0.0.1', $tags['0.0.1']); $this->assertEquals('//depot@0.0.1', $tags['0.0.1']);
@ -418,19 +393,15 @@ class PerforceTest extends TestCase
{ {
$this->setPerforceToStream(); $this->setPerforceToStream();
$expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot_branch -p port labels'; $this->processExecutor->expects(
$this->processExecutor->expects($this->once()) [
->method('execute') [
->with($this->equalTo($expectedCommand)) 'cmd' => 'p4 -u user -c composer_perforce_TEST_depot_branch -p port labels',
->will( 'stdout' => 'Label 0.0.1 2013/07/31 \'First Label!\'' . PHP_EOL . 'Label 0.0.2 2013/08/01 \'Second Label!\'' . PHP_EOL
$this->returnCallback( ],
function ($command, &$output) { ],
$output = 'Label 0.0.1 2013/07/31 \'First Label!\'' . PHP_EOL . 'Label 0.0.2 2013/08/01 \'Second Label!\'' . PHP_EOL; true
);
return true;
}
)
);
$tags = $this->perforce->getTags(); $tags = $this->perforce->getTags();
$this->assertEquals('//depot/branch@0.0.1', $tags['0.0.1']); $this->assertEquals('//depot/branch@0.0.1', $tags['0.0.1']);
@ -446,16 +417,16 @@ class PerforceTest extends TestCase
public function testCheckStreamWithStream() public function testCheckStreamWithStream()
{ {
$this->processExecutor->expects($this->any())->method('execute') $this->processExecutor->expects(
->will( [
$this->returnCallback( [
function ($command, &$output) { 'cmd' => 'p4 -u user -p port depots',
$output = 'Depot depot 2013/06/25 stream /p4/1/depots/depot/... \'Created by Me\''; 'stdout' => 'Depot depot 2013/06/25 stream /p4/1/depots/depot/... \'Created by Me\''
],
],
true
);
return true;
}
)
);
$result = $this->perforce->checkStream(); $result = $this->perforce->checkStream();
$this->assertTrue($result); $this->assertTrue($result);
$this->assertTrue($this->perforce->isStream()); $this->assertTrue($this->perforce->isStream());
@ -463,19 +434,15 @@ class PerforceTest extends TestCase
public function testGetComposerInformationWithoutLabelWithoutStream() public function testGetComposerInformationWithoutLabelWithoutStream()
{ {
$expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot -p port print '.ProcessExecutor::escape('//depot/composer.json'); $this->processExecutor->expects(
$this->processExecutor->expects($this->once()) [
->method('execute') [
->with($this->equalTo($expectedCommand)) 'cmd' => 'p4 -u user -c composer_perforce_TEST_depot -p port print '.ProcessExecutor::escape('//depot/composer.json'),
->will( 'stdout' => PerforceTest::getComposerJson()
$this->returnCallback( ],
function ($command, &$output) { ],
$output = PerforceTest::getComposerJson(); true
);
return true;
}
)
);
$result = $this->perforce->getComposerInformation('//depot'); $result = $this->perforce->getComposerInformation('//depot');
$expected = array( $expected = array(
@ -489,26 +456,19 @@ class PerforceTest extends TestCase
public function testGetComposerInformationWithLabelWithoutStream() public function testGetComposerInformationWithLabelWithoutStream()
{ {
$expectations = [ $this->processExecutor->expects(
['p4 -u user -p port files '.ProcessExecutor::escape('//depot/composer.json@0.0.1'), '//depot/composer.json#1 - branch change 10001 (text)'], [
['p4 -u user -c composer_perforce_TEST_depot -p port print '.ProcessExecutor::escape('//depot/composer.json@10001'), PerforceTest::getComposerJson()], [
]; 'cmd' => 'p4 -u user -p port files '.ProcessExecutor::escape('//depot/composer.json@0.0.1'),
$count = 0; 'stdout' => '//depot/composer.json#1 - branch change 10001 (text)'
$this->processExecutor->expects($this->exactly(2)) ],
->method('execute') [
->will( 'cmd' => 'p4 -u user -c composer_perforce_TEST_depot -p port print '.ProcessExecutor::escape('//depot/composer.json@10001'),
$this->returnCallback( 'stdout' => PerforceTest::getComposerJson()
function ($command, &$output) use ($expectations, &$count) { ],
$index = $count++; ],
if ($command !== $expectations[$index][0]) { true
throw new \InvalidArgumentException('Expected '.$expectations[$index][0].' and got '.$command); );
}
$output = $expectations[$index][1];
return 0;
}
)
);
$result = $this->perforce->getComposerInformation('//depot@0.0.1'); $result = $this->perforce->getComposerInformation('//depot@0.0.1');
@ -525,19 +485,15 @@ class PerforceTest extends TestCase
{ {
$this->setPerforceToStream(); $this->setPerforceToStream();
$expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot_branch -p port print '.ProcessExecutor::escape('//depot/branch/composer.json'); $this->processExecutor->expects(
$this->processExecutor->expects($this->once()) [
->method('execute') [
->with($this->equalTo($expectedCommand)) 'cmd' => 'p4 -u user -c composer_perforce_TEST_depot_branch -p port print '.ProcessExecutor::escape('//depot/branch/composer.json'),
->will( 'stdout' => PerforceTest::getComposerJson()
$this->returnCallback( ],
function ($command, &$output) { ],
$output = PerforceTest::getComposerJson(); true
);
return true;
}
)
);
$result = $this->perforce->getComposerInformation('//depot/branch'); $result = $this->perforce->getComposerInformation('//depot/branch');
@ -552,26 +508,19 @@ class PerforceTest extends TestCase
public function testGetComposerInformationWithLabelWithStream() public function testGetComposerInformationWithLabelWithStream()
{ {
$expectations = [ $this->processExecutor->expects(
[ 'p4 -u user -p port files '.ProcessExecutor::escape('//depot/branch/composer.json@0.0.1'), '//depot/composer.json#1 - branch change 10001 (text)'], [
['p4 -u user -c composer_perforce_TEST_depot_branch -p port print '.ProcessExecutor::escape('//depot/branch/composer.json@10001'), PerforceTest::getComposerJson()], [
]; 'cmd' => 'p4 -u user -p port files '.ProcessExecutor::escape('//depot/branch/composer.json@0.0.1'),
$count = 0; 'stdout' => '//depot/composer.json#1 - branch change 10001 (text)',
$this->processExecutor->expects($this->exactly(2)) ],
->method('execute') [
->will( 'cmd' => 'p4 -u user -c composer_perforce_TEST_depot_branch -p port print '.ProcessExecutor::escape('//depot/branch/composer.json@10001'),
$this->returnCallback( 'stdout' => PerforceTest::getComposerJson(),
function ($command, &$output) use ($expectations, &$count) { ],
$index = $count++; ],
if ($command !== $expectations[$index][0]) { true
throw new \InvalidArgumentException('Expected '.$expectations[$index][0].' and got '.$command); );
}
$output = $expectations[$index][1];
return 0;
}
)
);
$this->setPerforceToStream(); $this->setPerforceToStream();
@ -588,11 +537,10 @@ class PerforceTest extends TestCase
public function testSyncCodeBaseWithoutStream() public function testSyncCodeBaseWithoutStream()
{ {
$expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot -p port sync -f @label'; $this->processExecutor->expects(
$this->processExecutor->expects($this->once()) ['p4 -u user -c composer_perforce_TEST_depot -p port sync -f @label'],
->method('execute') true
->with($this->equalTo($expectedCommand), $this->equalTo(null)) );
->willReturn(0);
$this->perforce->syncCodeBase('label'); $this->perforce->syncCodeBase('label');
} }
@ -600,26 +548,23 @@ class PerforceTest extends TestCase
public function testSyncCodeBaseWithStream() public function testSyncCodeBaseWithStream()
{ {
$this->setPerforceToStream(); $this->setPerforceToStream();
$expectedCommand = 'p4 -u user -c composer_perforce_TEST_depot_branch -p port sync -f @label';
$this->processExecutor->expects($this->once()) $this->processExecutor->expects(
->method('execute') ['p4 -u user -c composer_perforce_TEST_depot_branch -p port sync -f @label'],
->with($this->equalTo($expectedCommand)) true
->willReturn(0); );
$this->perforce->syncCodeBase('label'); $this->perforce->syncCodeBase('label');
} }
public function testCheckServerExists() public function testCheckServerExists()
{ {
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock(); $this->processExecutor->expects(
['p4 -p '.ProcessExecutor::escape('perforce.does.exist:port').' info -s'],
true
);
$expectedCommand = 'p4 -p '.ProcessExecutor::escape('perforce.does.exist:port').' info -s'; $result = $this->perforce->checkServerExists('perforce.does.exist:port', $this->processExecutor);
$processExecutor->expects($this->once())
->method('execute')
->with($this->equalTo($expectedCommand), $this->equalTo(null))
->willReturn(0);
$result = $this->perforce->checkServerExists('perforce.does.exist:port', $processExecutor);
$this->assertTrue($result); $this->assertTrue($result);
} }
@ -710,8 +655,10 @@ class PerforceTest extends TestCase
$this->perforce->setFilesystem($fs); $this->perforce->setFilesystem($fs);
$testClient = $this->perforce->getClient(); $testClient = $this->perforce->getClient();
$expectedCommand = 'p4 -u ' . self::TEST_P4USER . ' -p ' . self::TEST_PORT . ' client -d ' . ProcessExecutor::escape($testClient); $this->processExecutor->expects(
$this->processExecutor->expects($this->once())->method('execute')->with($this->equalTo($expectedCommand)); ['p4 -u ' . self::TEST_P4USER . ' -p ' . self::TEST_PORT . ' client -d ' . ProcessExecutor::escape($testClient)],
true
);
$fs->expects($this->once())->method('remove')->with($this->perforce->getP4ClientSpec()); $fs->expects($this->once())->method('remove')->with($this->perforce->getP4ClientSpec());

View file

@ -447,7 +447,7 @@ class RemoteFilesystemTest extends TestCase
false, false,
$authHelper, $authHelper,
)) ))
->setMethods($mockedMethods) ->onlyMethods($mockedMethods)
->getMock(); ->getMock();
} }
@ -463,7 +463,7 @@ class RemoteFilesystemTest extends TestCase
$this->getIOInterfaceMock(), $this->getIOInterfaceMock(),
$this->getConfigMock(), $this->getConfigMock(),
)) ))
->setMethods($mockedMethods) ->onlyMethods($mockedMethods)
->getMock(); ->getMock();
} }
} }