Fix many PHPStan issues and update baseline

main
Jordi Boggiano 2 years ago
parent 6ed3aeb343
commit 96486d81cb
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC

@ -950,11 +950,6 @@ parameters:
count: 1
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\\.$#"
count: 1
@ -2440,16 +2435,6 @@ parameters:
count: 3
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\\.$#"
count: 1
@ -4235,6 +4220,11 @@ parameters:
count: 2
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\\.$#"
count: 1
@ -4245,6 +4235,11 @@ parameters:
count: 2
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\\.$#"
count: 2
@ -6745,6 +6740,16 @@ parameters:
count: 2
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\\.$#"
count: 3
@ -8450,12 +8455,12 @@ parameters:
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
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
path: ../tests/Composer/Test/Mock/HttpDownloaderMock.php
@ -8469,31 +8474,11 @@ parameters:
count: 1
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\\.$#"
count: 1
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\\.$#"
count: 2
@ -8510,7 +8495,7 @@ parameters:
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
path: ../tests/Composer/Test/Mock/ProcessExecutorMock.php
@ -8824,11 +8809,6 @@ parameters:
count: 1
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\\(\\)\\.$#"
count: 1
@ -8869,31 +8849,6 @@ parameters:
count: 1
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\\(\\)\\.$#"
count: 1
@ -8944,11 +8899,6 @@ parameters:
count: 1
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\\.$#"
count: 1

@ -49,7 +49,7 @@ parameters:
# PHPUnit assertions as instance methods
- '~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:
- ./locate-phpunit-autoloader.php

@ -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));
}
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));
}

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

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

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

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

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

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

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

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

@ -235,7 +235,7 @@ class InstallerTest extends TestCase
* @param ?string $expectOutput
* @param ?string $expectOutputOptimized
* @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)
{
@ -258,7 +258,7 @@ class InstallerTest extends TestCase
* @param ?string $expectOutput
* @param ?string $expectOutputOptimized
* @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)
{
@ -281,7 +281,7 @@ class InstallerTest extends TestCase
* @param ?string $expectOutput
* @param ?string $expectOutputOptimized
* @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)
{

@ -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 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' => ['']];
$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)));
}
@ -89,7 +89,7 @@ class HttpDownloaderMock extends HttpDownloader
}
// 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

@ -26,7 +26,7 @@ use React\Promise\Promise;
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;
/**
@ -84,7 +84,7 @@ class ProcessExecutorMock extends ProcessExecutor
}
// 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)

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

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

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

@ -59,15 +59,15 @@ class RepositoryManagerTest extends TestCase
* @param array<string, mixed> $options
* @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);
}
$rm = new RepositoryManager(
$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\EventDispatcher\EventDispatcher')->disableOriginalConstructor()->getMock()
);
@ -119,7 +119,7 @@ class RepositoryManagerTest extends TestCase
{
$rm = new RepositoryManager(
$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\EventDispatcher\EventDispatcher')->disableOriginalConstructor()->getMock()
);

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

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

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

Loading…
Cancel
Save