1
0
Fork 0

Fix all remaining php8.1 test suite deprecations

pull/10061/head
Jordi Boggiano 2021-08-19 13:00:30 +02:00
parent b77fce8a4f
commit a586a753df
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC
15 changed files with 184 additions and 268 deletions

View File

@ -24,7 +24,7 @@ class JsonValidationException extends Exception
public function __construct($message, $errors = array(), Exception $previous = null) public function __construct($message, $errors = array(), Exception $previous = null)
{ {
$this->errors = $errors; $this->errors = $errors;
parent::__construct($message, 0, $previous); parent::__construct((string) $message, 0, $previous);
} }
public function getErrors() public function getErrors()

View File

@ -151,7 +151,7 @@ class Bitbucket
$this->io->writeError(sprintf('to create a consumer. It will be stored in "%s" for future use by Composer.', $this->config->getAuthConfigSource()->getName())); $this->io->writeError(sprintf('to create a consumer. It will be stored in "%s" for future use by Composer.', $this->config->getAuthConfigSource()->getName()));
$this->io->writeError('Ensure you enter a "Callback URL" (http://example.com is fine) or it will not be possible to create an Access Token (this callback url will not be used by composer)'); $this->io->writeError('Ensure you enter a "Callback URL" (http://example.com is fine) or it will not be possible to create an Access Token (this callback url will not be used by composer)');
$consumerKey = trim($this->io->askAndHideAnswer('Consumer Key (hidden): ')); $consumerKey = trim((string) $this->io->askAndHideAnswer('Consumer Key (hidden): '));
if (!$consumerKey) { if (!$consumerKey) {
$this->io->writeError('<warning>No consumer key given, aborting.</warning>'); $this->io->writeError('<warning>No consumer key given, aborting.</warning>');
@ -160,7 +160,7 @@ class Bitbucket
return false; return false;
} }
$consumerSecret = trim($this->io->askAndHideAnswer('Consumer Secret (hidden): ')); $consumerSecret = trim((string) $this->io->askAndHideAnswer('Consumer Secret (hidden): '));
if (!$consumerSecret) { if (!$consumerSecret) {
$this->io->writeError('<warning>No consumer secret given, aborting.</warning>'); $this->io->writeError('<warning>No consumer secret given, aborting.</warning>');

View File

@ -160,7 +160,7 @@ class Perforce
public function isStream() public function isStream()
{ {
return (strcmp($this->p4DepotType, 'stream') === 0); return is_string($this->p4DepotType) && (strcmp($this->p4DepotType, 'stream') === 0);
} }
public function getStream() public function getStream()
@ -204,11 +204,11 @@ class Perforce
public function queryP4User() public function queryP4User()
{ {
$this->getUser(); $this->getUser();
if (strlen($this->p4User) > 0) { if (strlen((string) $this->p4User) > 0) {
return; return;
} }
$this->p4User = $this->getP4variable('P4USER'); $this->p4User = $this->getP4variable('P4USER');
if (strlen($this->p4User) > 0) { if (strlen((string) $this->p4User) > 0) {
return; return;
} }
$this->p4User = $this->io->ask('Enter P4 User:'); $this->p4User = $this->io->ask('Enter P4 User:');
@ -262,7 +262,7 @@ class Perforce
return $this->p4Password; return $this->p4Password;
} }
$password = $this->getP4variable('P4PASSWD'); $password = $this->getP4variable('P4PASSWD');
if (strlen($password) <= 0) { if (strlen((string) $password) <= 0) {
$password = $this->io->askAndHideAnswer('Enter password for Perforce user ' . $this->getUser() . ': '); $password = $this->io->askAndHideAnswer('Enter password for Perforce user ' . $this->getUser() . ': ');
} }
$this->p4Password = $password; $this->p4Password = $password;

View File

@ -356,9 +356,9 @@ class ProcessExecutor
*/ */
public function splitLines($output) public function splitLines($output)
{ {
$output = trim($output); $output = trim((string) $output);
return ((string) $output === '') ? array() : preg_split('{\r?\n}', $output); return $output === '' ? array() : preg_split('{\r?\n}', $output);
} }
/** /**

View File

@ -18,6 +18,7 @@ use Composer\EventDispatcher\EventDispatcher;
use Composer\Plugin\PluginEvents; use Composer\Plugin\PluginEvents;
use Composer\Plugin\PreFileDownloadEvent; use Composer\Plugin\PreFileDownloadEvent;
use Composer\Test\TestCase; use Composer\Test\TestCase;
use Composer\Test\Mock\ProcessExecutorMock;
use Composer\Util\Filesystem; use Composer\Util\Filesystem;
use Composer\Util\Http\Response; use Composer\Util\Http\Response;
use Composer\Util\Loop; use Composer\Util\Loop;
@ -194,7 +195,7 @@ class FileDownloaderTest extends TestCase
$dispatcher = new EventDispatcher( $dispatcher = new EventDispatcher(
$composerMock, $composerMock,
$this->getMockBuilder('Composer\IO\IOInterface')->getMock(), $this->getMockBuilder('Composer\IO\IOInterface')->getMock(),
$this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock() new ProcessExecutorMock
); );
$dispatcher->addListener(PluginEvents::PRE_FILE_DOWNLOAD, function (PreFileDownloadEvent $event) use ($expectedUrl) { $dispatcher->addListener(PluginEvents::PRE_FILE_DOWNLOAD, function (PreFileDownloadEvent $event) use ($expectedUrl) {
$event->setProcessedUrl($expectedUrl); $event->setProcessedUrl($expectedUrl);
@ -288,7 +289,7 @@ class FileDownloaderTest extends TestCase
$dispatcher = new EventDispatcher( $dispatcher = new EventDispatcher(
$composerMock, $composerMock,
$this->getMockBuilder('Composer\IO\IOInterface')->getMock(), $this->getMockBuilder('Composer\IO\IOInterface')->getMock(),
$this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock() new ProcessExecutorMock
); );
$dispatcher->addListener(PluginEvents::PRE_FILE_DOWNLOAD, function (PreFileDownloadEvent $event) use ($customCacheKey) { $dispatcher->addListener(PluginEvents::PRE_FILE_DOWNLOAD, function (PreFileDownloadEvent $event) use ($customCacheKey) {
$event->setCustomCacheKey($customCacheKey); $event->setCustomCacheKey($customCacheKey);

View File

@ -16,6 +16,7 @@ use Composer\Downloader\FossilDownloader;
use Composer\Test\TestCase; use Composer\Test\TestCase;
use Composer\Util\Filesystem; use Composer\Util\Filesystem;
use Composer\Util\Platform; use Composer\Util\Platform;
use Composer\Test\Mock\ProcessExecutorMock;
class FossilDownloaderTest extends TestCase class FossilDownloaderTest extends TestCase
{ {
@ -39,7 +40,7 @@ class FossilDownloaderTest extends TestCase
{ {
$io = $io ?: $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); $io = $io ?: $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
$config = $config ?: $this->getMockBuilder('Composer\Config')->getMock(); $config = $config ?: $this->getMockBuilder('Composer\Config')->getMock();
$executor = $executor ?: $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock(); $executor = $executor ?: new ProcessExecutorMock;
$filesystem = $filesystem ?: $this->getMockBuilder('Composer\Util\Filesystem')->getMock(); $filesystem = $filesystem ?: $this->getMockBuilder('Composer\Util\Filesystem')->getMock();
return new FossilDownloader($io, $config, $executor, $filesystem); return new FossilDownloader($io, $config, $executor, $filesystem);
@ -67,28 +68,18 @@ class FossilDownloaderTest extends TestCase
$packageMock->expects($this->once()) $packageMock->expects($this->once())
->method('getSourceUrls') ->method('getSourceUrls')
->will($this->returnValue(array('http://fossil.kd2.org/kd2fw/'))); ->will($this->returnValue(array('http://fossil.kd2.org/kd2fw/')));
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
$expectedFossilCommand = $this->getCmd('fossil clone -- \'http://fossil.kd2.org/kd2fw/\' \'repo.fossil\''); $process = new ProcessExecutorMock;
$processExecutor->expects($this->at(0)) $process->expects(array(
->method('execute') $this->getCmd('fossil clone -- \'http://fossil.kd2.org/kd2fw/\' \'repo.fossil\''),
->with($this->equalTo($expectedFossilCommand)) $this->getCmd('fossil open --nested -- \'repo.fossil\''),
->will($this->returnValue(0)); $this->getCmd('fossil update -- \'trunk\''),
), true);
$expectedFossilCommand = $this->getCmd('fossil open --nested -- \'repo.fossil\''); $downloader = $this->getDownloaderMock(null, null, $process);
$processExecutor->expects($this->at(1))
->method('execute')
->with($this->equalTo($expectedFossilCommand))
->will($this->returnValue(0));
$expectedFossilCommand = $this->getCmd('fossil update -- \'trunk\'');
$processExecutor->expects($this->at(2))
->method('execute')
->with($this->equalTo($expectedFossilCommand))
->will($this->returnValue(0));
$downloader = $this->getDownloaderMock(null, null, $processExecutor);
$downloader->install($packageMock, 'repo'); $downloader->install($packageMock, 'repo');
$process->assertComplete($this);
} }
public function testUpdateforPackageWithoutSourceReference() public function testUpdateforPackageWithoutSourceReference()
@ -126,46 +117,46 @@ class FossilDownloaderTest extends TestCase
$packageMock->expects($this->any()) $packageMock->expects($this->any())
->method('getVersion') ->method('getVersion')
->will($this->returnValue('1.0.0.0')); ->will($this->returnValue('1.0.0.0'));
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
$expectedFossilCommand = $this->getCmd("fossil changes"); $process = new ProcessExecutorMock;
$processExecutor->expects($this->at(0)) $process->expects(array(
->method('execute') $this->getCmd("fossil changes"),
->with($this->equalTo($expectedFossilCommand)) $this->getCmd("fossil pull && fossil up 'trunk'"),
->will($this->returnCallback(function ($cmd, &$output, $path) { ), true);
$output = '';
return 0; $downloader = $this->getDownloaderMock(null, null, $process);
}));
$expectedFossilCommand = $this->getCmd("fossil pull && fossil up 'trunk'");
$processExecutor->expects($this->at(1))
->method('execute')
->with($this->equalTo($expectedFossilCommand))
->will($this->returnValue(0));
$downloader = $this->getDownloaderMock(null, null, $processExecutor);
$downloader->prepare('update', $packageMock, $this->workingDir, $packageMock); $downloader->prepare('update', $packageMock, $this->workingDir, $packageMock);
$downloader->update($packageMock, $packageMock, $this->workingDir); $downloader->update($packageMock, $packageMock, $this->workingDir);
$downloader->cleanup('update', $packageMock, $this->workingDir, $packageMock); $downloader->cleanup('update', $packageMock, $this->workingDir, $packageMock);
$process->assertComplete($this);
} }
public function testRemove() public function testRemove()
{ {
$expectedResetCommand = $this->getCmd('cd \'composerPath\' && fossil status'); // Ensure file exists
$file = $this->workingDir . '/.fslckout';
touch($file);
$packageMock = $this->getMockBuilder('Composer\Package\PackageInterface')->getMock(); $packageMock = $this->getMockBuilder('Composer\Package\PackageInterface')->getMock();
$processExecutor = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
$processExecutor->expects($this->any()) $process = new ProcessExecutorMock;
->method('execute') $process->expects(array(
->with($this->equalTo($expectedResetCommand)); $this->getCmd('fossil changes'),
), true);
$filesystem = $this->getMockBuilder('Composer\Util\Filesystem')->getMock(); $filesystem = $this->getMockBuilder('Composer\Util\Filesystem')->getMock();
$filesystem->expects($this->once()) $filesystem->expects($this->once())
->method('removeDirectoryAsync') ->method('removeDirectoryAsync')
->with($this->equalTo('composerPath')) ->with($this->equalTo($this->workingDir))
->will($this->returnValue(\React\Promise\resolve(true))); ->will($this->returnValue(\React\Promise\resolve(true)));
$downloader = $this->getDownloaderMock(null, null, $processExecutor, $filesystem); $downloader = $this->getDownloaderMock(null, null, $process, $filesystem);
$downloader->remove($packageMock, 'composerPath'); $downloader->prepare('uninstall', $packageMock, $this->workingDir);
$downloader->remove($packageMock, $this->workingDir);
$downloader->cleanup('uninstall', $packageMock, $this->workingDir);
$process->assertComplete($this);
} }
public function testGetInstallationSource() public function testGetInstallationSource()

View File

@ -19,6 +19,7 @@ use Composer\IO\IOInterface;
use Composer\Test\TestCase; use Composer\Test\TestCase;
use Composer\Factory; use Composer\Factory;
use Composer\Util\Filesystem; use Composer\Util\Filesystem;
use Composer\Test\Mock\ProcessExecutorMock;
/** /**
* @author Matt Whittom <Matt.Whittom@veteransunited.com> * @author Matt Whittom <Matt.Whittom@veteransunited.com>
@ -41,7 +42,7 @@ class PerforceDownloaderTest extends TestCase
$this->repoConfig = $this->getRepoConfig(); $this->repoConfig = $this->getRepoConfig();
$this->config = $this->getConfig(); $this->config = $this->getConfig();
$this->io = $this->getMockIoInterface(); $this->io = $this->getMockIoInterface();
$this->processExecutor = $this->getMockProcessExecutor(); $this->processExecutor = new ProcessExecutorMock;
$this->repository = $this->getMockRepository($this->repoConfig, $this->io, $this->config); $this->repository = $this->getMockRepository($this->repoConfig, $this->io, $this->config);
$this->package = $this->getMockPackageInterface($this->repository); $this->package = $this->getMockPackageInterface($this->repository);
$this->downloader = new PerforceDownloader($this->io, $this->config, $this->processExecutor); $this->downloader = new PerforceDownloader($this->io, $this->config, $this->processExecutor);
@ -61,11 +62,6 @@ class PerforceDownloaderTest extends TestCase
} }
} }
protected function getMockProcessExecutor()
{
return $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
}
protected function getConfig() protected function getConfig()
{ {
$config = new Config(); $config = new Config();

View File

@ -22,6 +22,7 @@ use Composer\IO\BufferIO;
use Composer\Script\ScriptEvents; use Composer\Script\ScriptEvents;
use Composer\Script\Event as ScriptEvent; use Composer\Script\Event as ScriptEvent;
use Composer\Util\ProcessExecutor; use Composer\Util\ProcessExecutor;
use Composer\Test\Mock\ProcessExecutorMock;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
class EventDispatcherTest extends TestCase class EventDispatcherTest extends TestCase
@ -56,7 +57,11 @@ class EventDispatcherTest extends TestCase
*/ */
public function testDispatcherCanExecuteSingleCommandLineScript($command) public function testDispatcherCanExecuteSingleCommandLineScript($command)
{ {
$process = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock(); $process = new ProcessExecutorMock;
$process->expects(array(
$command,
), true);
$dispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher') $dispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')
->setConstructorArgs(array( ->setConstructorArgs(array(
$this->createComposerInstance(), $this->createComposerInstance(),
@ -71,12 +76,9 @@ class EventDispatcherTest extends TestCase
->method('getListeners') ->method('getListeners')
->will($this->returnValue($listener)); ->will($this->returnValue($listener));
$process->expects($this->once())
->method('execute')
->with($command)
->will($this->returnValue(0));
$dispatcher->dispatchScript(ScriptEvents::POST_INSTALL_CMD, false); $dispatcher->dispatchScript(ScriptEvents::POST_INSTALL_CMD, false);
$process->assertComplete($this);
} }
/** /**
@ -104,7 +106,7 @@ class EventDispatcherTest extends TestCase
$dispatcher = new EventDispatcher( $dispatcher = new EventDispatcher(
$composer, $composer,
$this->getMockBuilder('Composer\IO\IOInterface')->getMock(), $this->getMockBuilder('Composer\IO\IOInterface')->getMock(),
$this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock() new ProcessExecutorMock
); );
$event = $this->getMockBuilder('Composer\Script\Event') $event = $this->getMockBuilder('Composer\Script\Event')
@ -179,7 +181,7 @@ class EventDispatcherTest extends TestCase
$dispatcher = new EventDispatcher( $dispatcher = new EventDispatcher(
$composer, $composer,
$io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE), $io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE),
$this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock() new ProcessExecutorMock
); );
$listener = array($this, 'someMethod'); $listener = array($this, 'someMethod');
@ -214,7 +216,12 @@ class EventDispatcherTest extends TestCase
public function testDispatcherCanExecuteCliAndPhpInSameEventScriptStack() public function testDispatcherCanExecuteCliAndPhpInSameEventScriptStack()
{ {
$process = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock(); $process = new ProcessExecutorMock;
$process->expects(array(
'echo -n foo',
'echo -n bar',
), true);
$dispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher') $dispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')
->setConstructorArgs(array( ->setConstructorArgs(array(
$this->createComposerInstance(), $this->createComposerInstance(),
@ -226,10 +233,6 @@ class EventDispatcherTest extends TestCase
)) ))
->getMock(); ->getMock();
$process->expects($this->exactly(2))
->method('execute')
->will($this->returnValue(0));
$listeners = array( $listeners = array(
'echo -n foo', 'echo -n foo',
'Composer\\Test\\EventDispatcher\\EventDispatcherTest::someMethod', 'Composer\\Test\\EventDispatcher\\EventDispatcherTest::someMethod',
@ -246,16 +249,17 @@ class EventDispatcherTest extends TestCase
'> post-install-cmd: Composer\Test\EventDispatcher\EventDispatcherTest::someMethod'.PHP_EOL. '> post-install-cmd: Composer\Test\EventDispatcher\EventDispatcherTest::someMethod'.PHP_EOL.
'> post-install-cmd: echo -n bar'.PHP_EOL; '> post-install-cmd: echo -n bar'.PHP_EOL;
$this->assertEquals($expected, $io->getOutput()); $this->assertEquals($expected, $io->getOutput());
$process->assertComplete($this);
} }
public function testDispatcherCanPutEnv() public function testDispatcherCanPutEnv()
{ {
$process = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
$dispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher') $dispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')
->setConstructorArgs(array( ->setConstructorArgs(array(
$this->createComposerInstance(), $this->createComposerInstance(),
$io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE), $io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE),
$process, new ProcessExecutorMock,
)) ))
->setMethods(array( ->setMethods(array(
'getListeners', 'getListeners',
@ -285,11 +289,10 @@ class EventDispatcherTest extends TestCase
chdir(__DIR__); chdir(__DIR__);
putenv('COMPOSER_BIN_DIR=' . __DIR__ . sprintf('%svendor%sbin', DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR)); putenv('COMPOSER_BIN_DIR=' . __DIR__ . sprintf('%svendor%sbin', DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR));
$process = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
$dispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')->setConstructorArgs(array( $dispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')->setConstructorArgs(array(
$this->createComposerInstance(), $this->createComposerInstance(),
$io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE), $io = new BufferIO('', OutputInterface::VERBOSITY_VERBOSE),
$process, new ProcessExecutorMock,
))->setMethods(array( ))->setMethods(array(
'getListeners', 'getListeners',
))->getMock(); ))->getMock();
@ -342,7 +345,13 @@ class EventDispatcherTest extends TestCase
public function testDispatcherCanExecuteComposerScriptGroups() public function testDispatcherCanExecuteComposerScriptGroups()
{ {
$process = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock(); $process = new ProcessExecutorMock;
$process->expects(array(
'echo -n foo',
'echo -n baz',
'echo -n bar',
), true);
$dispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher') $dispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')
->setConstructorArgs(array( ->setConstructorArgs(array(
$composer = $this->createComposerInstance(), $composer = $this->createComposerInstance(),
@ -354,10 +363,6 @@ class EventDispatcherTest extends TestCase
)) ))
->getMock(); ->getMock();
$process->expects($this->exactly(3))
->method('execute')
->will($this->returnValue(0));
$dispatcher->expects($this->atLeastOnce()) $dispatcher->expects($this->atLeastOnce())
->method('getListeners') ->method('getListeners')
->will($this->returnCallback(function (Event $event) { ->will($this->returnCallback(function (Event $event) {
@ -383,11 +388,17 @@ class EventDispatcherTest extends TestCase
'> subgroup: echo -n baz'.PHP_EOL. '> subgroup: echo -n baz'.PHP_EOL.
'> group: echo -n bar'.PHP_EOL; '> group: echo -n bar'.PHP_EOL;
$this->assertEquals($expected, $io->getOutput()); $this->assertEquals($expected, $io->getOutput());
$process->assertComplete($this);
} }
public function testRecursionInScriptsNames() public function testRecursionInScriptsNames()
{ {
$process = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock(); $process = new ProcessExecutorMock;
$process->expects(array(
'echo Hello '.ProcessExecutor::escape('World'),
), true);
$dispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher') $dispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')
->setConstructorArgs(array( ->setConstructorArgs(array(
$composer = $this->createComposerInstance(), $composer = $this->createComposerInstance(),
@ -399,10 +410,6 @@ class EventDispatcherTest extends TestCase
)) ))
->getMock(); ->getMock();
$process->expects($this->exactly(1))
->method('execute')
->will($this->returnValue(0));
$dispatcher->expects($this->atLeastOnce()) $dispatcher->expects($this->atLeastOnce())
->method('getListeners') ->method('getListeners')
->will($this->returnCallback(function (Event $event) { ->will($this->returnCallback(function (Event $event) {
@ -422,18 +429,19 @@ class EventDispatcherTest extends TestCase
"> hello: echo Hello " .escapeshellarg('World').PHP_EOL; "> hello: echo Hello " .escapeshellarg('World').PHP_EOL;
$this->assertEquals($expected, $io->getOutput()); $this->assertEquals($expected, $io->getOutput());
$process->assertComplete($this);
} }
public function testDispatcherDetectInfiniteRecursion() public function testDispatcherDetectInfiniteRecursion()
{ {
$this->setExpectedException('RuntimeException'); $this->setExpectedException('RuntimeException');
$process = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
$dispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher') $dispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')
->setConstructorArgs(array( ->setConstructorArgs(array(
$composer = $this->createComposerInstance(), $composer = $this->createComposerInstance(),
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock(), $io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock(),
$process, new ProcessExecutorMock,
)) ))
->setMethods(array( ->setMethods(array(
'getListeners', 'getListeners',
@ -549,12 +557,11 @@ class EventDispatcherTest extends TestCase
public function testDispatcherInstallerEvents() public function testDispatcherInstallerEvents()
{ {
$process = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
$dispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher') $dispatcher = $this->getMockBuilder('Composer\EventDispatcher\EventDispatcher')
->setConstructorArgs(array( ->setConstructorArgs(array(
$this->createComposerInstance(), $this->createComposerInstance(),
$this->getMockBuilder('Composer\IO\IOInterface')->getMock(), $this->getMockBuilder('Composer\IO\IOInterface')->getMock(),
$process, new ProcessExecutorMock,
)) ))
->setMethods(array('getListeners')) ->setMethods(array('getListeners'))
->getMock(); ->getMock();

View File

@ -19,13 +19,14 @@ use Composer\Package\RootPackage;
use Composer\Package\Version\VersionGuesser; use Composer\Package\Version\VersionGuesser;
use Composer\Semver\VersionParser; use Composer\Semver\VersionParser;
use Composer\Test\TestCase; use Composer\Test\TestCase;
use Composer\Test\Mock\ProcessExecutorMock;
use Prophecy\Argument; use Prophecy\Argument;
class RootPackageLoaderTest extends TestCase class RootPackageLoaderTest extends TestCase
{ {
protected function loadPackage($data) protected function loadPackage($data)
{ {
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager') $manager = $this->getMockBuilder('Composer\\Repository\\RepositoryManager')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock(); ->getMock();
@ -67,38 +68,28 @@ class RootPackageLoaderTest extends TestCase
public function testNoVersionIsVisibleInPrettyVersion() public function testNoVersionIsVisibleInPrettyVersion()
{ {
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager') $manager = $this->getMockBuilder('Composer\\Repository\\RepositoryManager')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock() ->getMock()
; ;
$executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor')
->setMethods(array('execute'))
->disableArgumentCloning()
->disableOriginalConstructor()
->getMock()
;
$executor
->expects($this->any())
->method('execute')
->willReturn(null)
;
$config = new Config; $config = new Config;
$config->merge(array('repositories' => array('packagist' => false))); $config->merge(array('repositories' => array('packagist' => false)));
$loader = new RootPackageLoader($manager, $config, null, new VersionGuesser($config, $executor, new VersionParser())); $loader = new RootPackageLoader($manager, $config, null, new VersionGuesser($config, $process = new ProcessExecutorMock, new VersionParser()));
$process->expects(array(), false, array('return' => 1));
$package = $loader->load(array()); $package = $loader->load(array());
$this->assertEquals("1.0.0.0", $package->getVersion()); $this->assertEquals("1.0.0.0", $package->getVersion());
$this->assertEquals(RootPackage::DEFAULT_PRETTY_VERSION, $package->getPrettyVersion()); $this->assertEquals(RootPackage::DEFAULT_PRETTY_VERSION, $package->getPrettyVersion());
} }
public function testPrettyVersionForRootPackageInVersionBranch() public function testPrettyVersionForRootPackageInVersionBranch()
{ {
// see #6845 // see #6845
$manager = $this->prophesize('\\Composer\\Repository\\RepositoryManager'); $manager = $this->prophesize('Composer\\Repository\\RepositoryManager');
$versionGuesser = $this->prophesize('\\Composer\\Package\\Version\\VersionGuesser'); $versionGuesser = $this->prophesize('Composer\\Package\\Version\\VersionGuesser');
$versionGuesser->guessVersion(Argument::cetera()) $versionGuesser->guessVersion(Argument::cetera())
->willReturn(array( ->willReturn(array(
'name' => 'A', 'name' => 'A',
@ -120,48 +111,28 @@ class RootPackageLoaderTest extends TestCase
$this->markTestSkipped('proc_open() is not available'); $this->markTestSkipped('proc_open() is not available');
} }
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager') $manager = $this->getMockBuilder('Composer\\Repository\\RepositoryManager')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock() ->getMock()
; ;
$executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor') $process = new ProcessExecutorMock;
->setMethods(array('execute')) $process->expects(array(
->disableArgumentCloning() array(
->disableOriginalConstructor() 'cmd' => 'git branch -a --no-color --no-abbrev -v',
->getMock() 'stdout' => "* latest-production 38137d2f6c70e775e137b2d8a7a7d3eaebf7c7e5 Commit message\n master 4f6ed96b0bc363d2aa4404c3412de1c011f67c66 Commit message\n",
; ),
'git rev-list master..latest-production',
$self = $this; ), true);
$executor
->expects($this->at(0))
->method('execute')
->willReturnCallback(function ($command, &$output) use ($self) {
$self->assertEquals('git branch -a --no-color --no-abbrev -v', $command);
$output = "* latest-production 38137d2f6c70e775e137b2d8a7a7d3eaebf7c7e5 Commit message\n master 4f6ed96b0bc363d2aa4404c3412de1c011f67c66 Commit message\n";
return 0;
})
;
$executor
->expects($this->at(1))
->method('execute')
->willReturnCallback(function ($command, &$output) use ($self) {
$self->assertEquals('git rev-list master..latest-production', $command);
$output = "";
return 0;
})
;
$config = new Config; $config = new Config;
$config->merge(array('repositories' => array('packagist' => false))); $config->merge(array('repositories' => array('packagist' => false)));
$loader = new RootPackageLoader($manager, $config, null, new VersionGuesser($config, $executor, new VersionParser())); $loader = new RootPackageLoader($manager, $config, null, new VersionGuesser($config, $process, new VersionParser()));
$package = $loader->load(array('require' => array('foo/bar' => 'self.version'))); $package = $loader->load(array('require' => array('foo/bar' => 'self.version')));
$this->assertEquals("dev-master", $package->getPrettyVersion()); $this->assertEquals("dev-master", $package->getPrettyVersion());
$process->assertComplete($this);
} }
public function testNonFeatureBranchPrettyVersion() public function testNonFeatureBranchPrettyVersion()
@ -170,36 +141,26 @@ class RootPackageLoaderTest extends TestCase
$this->markTestSkipped('proc_open() is not available'); $this->markTestSkipped('proc_open() is not available');
} }
$manager = $this->getMockBuilder('\\Composer\\Repository\\RepositoryManager') $manager = $this->getMockBuilder('Composer\\Repository\\RepositoryManager')
->disableOriginalConstructor() ->disableOriginalConstructor()
->getMock() ->getMock()
; ;
$executor = $this->getMockBuilder('\\Composer\\Util\\ProcessExecutor') $process = new ProcessExecutorMock;
->setMethods(array('execute')) $process->expects(array(
->disableArgumentCloning() array(
->disableOriginalConstructor() 'cmd' => 'git branch -a --no-color --no-abbrev -v',
->getMock() 'stdout' => "* latest-production 38137d2f6c70e775e137b2d8a7a7d3eaebf7c7e5 Commit message\n master 4f6ed96b0bc363d2aa4404c3412de1c011f67c66 Commit message\n"
; ),
), true);
$self = $this;
$executor
->expects($this->at(0))
->method('execute')
->willReturnCallback(function ($command, &$output) use ($self) {
$self->assertEquals('git branch -a --no-color --no-abbrev -v', $command);
$output = "* latest-production 38137d2f6c70e775e137b2d8a7a7d3eaebf7c7e5 Commit message\n master 4f6ed96b0bc363d2aa4404c3412de1c011f67c66 Commit message\n";
return 0;
})
;
$config = new Config; $config = new Config;
$config->merge(array('repositories' => array('packagist' => false))); $config->merge(array('repositories' => array('packagist' => false)));
$loader = new RootPackageLoader($manager, $config, null, new VersionGuesser($config, $executor, new VersionParser())); $loader = new RootPackageLoader($manager, $config, null, new VersionGuesser($config, $process, new VersionParser()));
$package = $loader->load(array('require' => array('foo/bar' => 'self.version'), "non-feature-branches" => array("latest-.*"))); $package = $loader->load(array('require' => array('foo/bar' => 'self.version'), "non-feature-branches" => array("latest-.*")));
$this->assertEquals("dev-latest-production", $package->getPrettyVersion()); $this->assertEquals("dev-latest-production", $package->getPrettyVersion());
$process->assertComplete($this);
} }
} }

View File

@ -17,7 +17,10 @@ use Composer\Repository\Vcs\GitHubDriver;
use Composer\Test\TestCase; use Composer\Test\TestCase;
use Composer\Util\Filesystem; use Composer\Util\Filesystem;
use Composer\Util\Http\Response; use Composer\Util\Http\Response;
use Composer\Test\Mock\ProcessExecutorMock;
use Composer\Config; use Composer\Config;
use Composer\Util\ProcessExecutor;
use Symfony\Component\Process\Process;
class GitHubDriverTest extends TestCase class GitHubDriverTest extends TestCase
{ {
@ -58,10 +61,8 @@ class GitHubDriverTest extends TestCase
->setConstructorArgs(array($io, $this->config)) ->setConstructorArgs(array($io, $this->config))
->getMock(); ->getMock();
$process = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock(); $process = new ProcessExecutorMock;
$process->expects($this->any()) $process->expects(array(), false, array('return' => 1));
->method('execute')
->will($this->returnValue(1));
$httpDownloader->expects($this->at(0)) $httpDownloader->expects($this->at(0))
->method('get') ->method('get')
@ -139,11 +140,7 @@ class GitHubDriverTest extends TestCase
); );
$repoUrl = 'https://github.com/composer/packagist.git'; $repoUrl = 'https://github.com/composer/packagist.git';
$process = $this->getMockBuilder('Composer\Util\ProcessExecutor') $gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, $httpDownloader, new ProcessExecutorMock);
->disableOriginalConstructor()
->getMock();
$gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, $httpDownloader, $process);
$gitHubDriver->initialize(); $gitHubDriver->initialize();
$this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha)); $this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha));
@ -201,11 +198,7 @@ class GitHubDriverTest extends TestCase
); );
$repoUrl = 'https://github.com/composer/packagist.git'; $repoUrl = 'https://github.com/composer/packagist.git';
$process = $this->getMockBuilder('Composer\Util\ProcessExecutor') $gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, $httpDownloader, new ProcessExecutorMock);
->disableOriginalConstructor()
->getMock();
$gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, $httpDownloader, $process);
$gitHubDriver->initialize(); $gitHubDriver->initialize();
$this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha)); $this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha));
@ -239,10 +232,6 @@ class GitHubDriverTest extends TestCase
->method('isInteractive') ->method('isInteractive')
->will($this->returnValue(true)); ->will($this->returnValue(true));
$process = $this->getMockBuilder('Composer\Util\ProcessExecutor')
->disableOriginalConstructor()
->getMock();
$httpDownloader = $this->getMockBuilder('Composer\Util\HttpDownloader') $httpDownloader = $this->getMockBuilder('Composer\Util\HttpDownloader')
->setConstructorArgs(array($io, $this->config)) ->setConstructorArgs(array($io, $this->config))
->getMock(); ->getMock();
@ -271,7 +260,7 @@ class GitHubDriverTest extends TestCase
'url' => $repoUrl, 'url' => $repoUrl,
); );
$gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, $httpDownloader, $process); $gitHubDriver = new GitHubDriver($repoConfig, $io, $this->config, $httpDownloader, new ProcessExecutorMock);
$gitHubDriver->initialize(); $gitHubDriver->initialize();
$this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha)); $this->setAttribute($gitHubDriver, 'tags', array($identifier => $sha));
@ -288,10 +277,6 @@ class GitHubDriverTest extends TestCase
$identifier = 'v0.0.0'; $identifier = 'v0.0.0';
$sha = 'SOMESHA'; $sha = 'SOMESHA';
$process = $this->getMockBuilder('Composer\Util\ProcessExecutor')
->disableOriginalConstructor()
->getMock();
$io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); $io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
$io->expects($this->any()) $io->expects($this->any())
->method('isInteractive') ->method('isInteractive')
@ -310,39 +295,23 @@ class GitHubDriverTest extends TestCase
$fs = new Filesystem(); $fs = new Filesystem();
$fs->removeDirectory(sys_get_temp_dir() . '/composer-test'); $fs->removeDirectory(sys_get_temp_dir() . '/composer-test');
$process->expects($this->at(0)) $process = new ProcessExecutorMock;
->method('execute') $process->expects(array(
->with($this->equalTo('git config github.accesstoken')) array('cmd' => 'git config github.accesstoken', 'return' => 1),
->will($this->returnValue(1)); 'git clone --mirror -- '.ProcessExecutor::escape($repoSshUrl).' '.ProcessExecutor::escape($this->config->get('cache-vcs-dir').'/git-github.com-composer-packagist.git/'),
array(
$process->expects($this->at(1)) 'cmd' => 'git show-ref --tags --dereference',
->method('execute') 'stdout' => $sha.' refs/tags/'.$identifier,
->with($this->stringContains($repoSshUrl)) ),
->will($this->returnValue(0)); array(
'cmd' => 'git branch --no-color --no-abbrev -v',
$process->expects($this->at(2)) 'stdout' => ' test_master edf93f1fccaebd8764383dc12016d0a1a9672d89 Fix test & behavior',
->method('execute') ),
->with($this->stringContains('git show-ref --tags')); array(
'cmd' => 'git branch --no-color',
$process->expects($this->at(3)) 'stdout' => '* test_master',
->method('splitLines') ),
->will($this->returnValue(array($sha.' refs/tags/'.$identifier))); ), true);
$process->expects($this->at(4))
->method('execute')
->with($this->stringContains('git branch --no-color --no-abbrev -v'));
$process->expects($this->at(5))
->method('splitLines')
->will($this->returnValue(array(' test_master edf93f1fccaebd8764383dc12016d0a1a9672d89 Fix test & behavior')));
$process->expects($this->at(6))
->method('execute')
->with($this->stringContains('git branch --no-color'));
$process->expects($this->at(7))
->method('splitLines')
->will($this->returnValue(array('* test_master')));
$repoConfig = array( $repoConfig = array(
'url' => $repoUrl, 'url' => $repoUrl,
@ -367,6 +336,8 @@ class GitHubDriverTest extends TestCase
$this->assertEquals('git', $source['type']); $this->assertEquals('git', $source['type']);
$this->assertEquals($repoSshUrl, $source['url']); $this->assertEquals($repoSshUrl, $source['url']);
$this->assertEquals($sha, $source['reference']); $this->assertEquals($sha, $source['reference']);
$process->assertComplete($this);
} }
protected function setAttribute($object, $attribute, $value) protected function setAttribute($object, $attribute, $value)

View File

@ -17,6 +17,7 @@ use Composer\Test\TestCase;
use Composer\Util\Filesystem; use Composer\Util\Filesystem;
use Composer\Config; use Composer\Config;
use Composer\Util\Perforce; use Composer\Util\Perforce;
use Composer\Test\Mock\ProcessExecutorMock;
/** /**
* @author Matt Whittom <Matt.Whittom@veteransunited.com> * @author Matt Whittom <Matt.Whittom@veteransunited.com>
@ -42,7 +43,7 @@ class PerforceDriverTest extends TestCase
$this->config = $this->getTestConfig($this->testPath); $this->config = $this->getTestConfig($this->testPath);
$this->repoConfig = $this->getTestRepoConfig(); $this->repoConfig = $this->getTestRepoConfig();
$this->io = $this->getMockIOInterface(); $this->io = $this->getMockIOInterface();
$this->process = $this->getMockProcessExecutor(); $this->process = new ProcessExecutorMock;
$this->httpDownloader = $this->getMockHttpDownloader(); $this->httpDownloader = $this->getMockHttpDownloader();
$this->perforce = $this->getMockPerforce(); $this->perforce = $this->getMockPerforce();
$this->driver = new PerforceDriver($this->repoConfig, $this->io, $this->config, $this->httpDownloader, $this->process); $this->driver = new PerforceDriver($this->repoConfig, $this->io, $this->config, $this->httpDownloader, $this->process);
@ -94,11 +95,6 @@ class PerforceDriverTest extends TestCase
return $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); return $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
} }
protected function getMockProcessExecutor()
{
return $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock();
}
protected function getMockHttpDownloader() protected function getMockHttpDownloader()
{ {
return $this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock(); return $this->getMockBuilder('Composer\Util\HttpDownloader')->disableOriginalConstructor()->getMock();

View File

@ -16,6 +16,7 @@ use Composer\Repository\Vcs\SvnDriver;
use Composer\Config; use Composer\Config;
use Composer\Test\TestCase; use Composer\Test\TestCase;
use Composer\Util\Filesystem; use Composer\Util\Filesystem;
use Composer\Test\Mock\ProcessExecutorMock;
class SvnDriverTest extends TestCase class SvnDriverTest extends TestCase
{ {
@ -50,16 +51,11 @@ class SvnDriverTest extends TestCase
$output .= " authorization failed: Could not authenticate to server:"; $output .= " authorization failed: Could not authenticate to server:";
$output .= " rejected Basic challenge (https://corp.svn.local/)"; $output .= " rejected Basic challenge (https://corp.svn.local/)";
$process = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock(); $process = new ProcessExecutorMock;
$process->expects($this->at(1)) $process->expects(array(
->method('execute') 'svn --version',
->will($this->returnValue(1)); array('cmd' => '', 'return' => 1, 'stderr' => $output),
$process->expects($this->exactly(7)) ), true);
->method('getErrorOutput')
->will($this->returnValue($output));
$process->expects($this->at(2))
->method('execute')
->will($this->returnValue(0));
$repoConfig = array( $repoConfig = array(
'url' => 'https://till:secret@corp.svn.local/repo', 'url' => 'https://till:secret@corp.svn.local/repo',
@ -67,6 +63,8 @@ class SvnDriverTest extends TestCase
$svn = new SvnDriver($repoConfig, $console, $this->config, $httpDownloader, $process); $svn = new SvnDriver($repoConfig, $console, $this->config, $httpDownloader, $process);
$svn->initialize(); $svn->initialize();
$process->assertComplete($this);
} }
public static function supportProvider() public static function supportProvider()

View File

@ -15,6 +15,7 @@ namespace Composer\Test\Util;
use Composer\Util\Bitbucket; use Composer\Util\Bitbucket;
use Composer\Util\Http\Response; use Composer\Util\Http\Response;
use Composer\Test\TestCase; use Composer\Test\TestCase;
use Composer\Test\Mock\ProcessExecutorMock;
/** /**
* @author Paul Wenke <wenke.paul@gmail.com> * @author Paul Wenke <wenke.paul@gmail.com>
@ -456,10 +457,8 @@ class BitbucketTest extends TestCase
public function testAuthorizeOAuthWithoutAvailableGitConfigToken() public function testAuthorizeOAuthWithoutAvailableGitConfigToken()
{ {
$process = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock(); $process = new ProcessExecutorMock;
$process->expects($this->once()) $process->expects(array(), false, array('return' => -1));
->method('execute')
->willReturn(-1);
$bitbucket = new Bitbucket($this->io, $this->config, $process, $this->httpDownloader, $this->time); $bitbucket = new Bitbucket($this->io, $this->config, $process, $this->httpDownloader, $this->time);
@ -468,10 +467,7 @@ class BitbucketTest extends TestCase
public function testAuthorizeOAuthWithAvailableGitConfigToken() public function testAuthorizeOAuthWithAvailableGitConfigToken()
{ {
$process = $this->getMockBuilder('Composer\Util\ProcessExecutor')->getMock(); $process = new ProcessExecutorMock;
$process->expects($this->once())
->method('execute')
->willReturn(0);
$bitbucket = new Bitbucket($this->io, $this->config, $process, $this->httpDownloader, $this->time); $bitbucket = new Bitbucket($this->io, $this->config, $process, $this->httpDownloader, $this->time);

View File

@ -93,8 +93,9 @@ class GitLabTest extends TestCase
$httpDownloader $httpDownloader
->expects($this->exactly(5)) ->expects($this->exactly(5))
->method('get') ->method('get')
->will($this->throwException(new TransportException('', 401))) ->will($this->throwException($e = new TransportException('', 401)))
; ;
$e->setResponse('{}');
$config = $this->getConfigMock(); $config = $this->getConfigMock();
$config $config

View File

@ -16,7 +16,7 @@ use Composer\Config;
use Composer\IO\IOInterface; use Composer\IO\IOInterface;
use Composer\Util\Filesystem; use Composer\Util\Filesystem;
use Composer\Util\Git; use Composer\Util\Git;
use Composer\Util\ProcessExecutor; use Composer\Test\Mock\ProcessExecutorMock;
use Composer\Test\TestCase; use Composer\Test\TestCase;
class GitTest extends TestCase class GitTest extends TestCase
@ -27,7 +27,7 @@ class GitTest extends TestCase
private $io; private $io;
/** @var Config&\PHPUnit\Framework\MockObject\MockObject */ /** @var Config&\PHPUnit\Framework\MockObject\MockObject */
private $config; private $config;
/** @var ProcessExecutor&\PHPUnit\Framework\MockObject\MockObject */ /** @var ProcessExecutorMock */
private $process; private $process;
/** @var Filesystem&\PHPUnit\Framework\MockObject\MockObject */ /** @var Filesystem&\PHPUnit\Framework\MockObject\MockObject */
private $fs; private $fs;
@ -36,7 +36,7 @@ class GitTest extends TestCase
{ {
$this->io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock(); $this->io = $this->getMockBuilder('Composer\IO\IOInterface')->getMock();
$this->config = $this->getMockBuilder('Composer\Config')->disableOriginalConstructor()->getMock(); $this->config = $this->getMockBuilder('Composer\Config')->disableOriginalConstructor()->getMock();
$this->process = $this->getMockBuilder('Composer\Util\ProcessExecutor')->disableOriginalConstructor()->getMock(); $this->process = new ProcessExecutorMock;
$this->fs = $this->getMockBuilder('Composer\Util\Filesystem')->disableOriginalConstructor()->getMock(); $this->fs = $this->getMockBuilder('Composer\Util\Filesystem')->disableOriginalConstructor()->getMock();
$this->git = new Git($this->io, $this->config, $this->process, $this->fs); $this->git = new Git($this->io, $this->config, $this->process, $this->fs);
} }
@ -55,13 +55,11 @@ class GitTest extends TestCase
$this->mockConfig($protocol); $this->mockConfig($protocol);
$this->process $this->process->expects(array('git command'), true);
->expects($this->once())
->method('execute')
->with($this->equalTo('git command'))
->willReturn(0);
$this->git->runCommand($commandCallable, 'https://github.com/acme/repo', null, true); $this->git->runCommand($commandCallable, 'https://github.com/acme/repo', null, true);
$this->process->assertComplete($this);
} }
public function publicGithubNoCredentialsProvider() public function publicGithubNoCredentialsProvider()
@ -85,20 +83,21 @@ class GitTest extends TestCase
$this->mockConfig('https'); $this->mockConfig('https');
$this->process
->method('execute') $this->process->expects(array(
->willReturnMap(array( array('cmd' => 'git command', 'return' => 1),
array('git command', null, null, 1), array('cmd' => 'git --version', 'return' => 0),
array('git --version', null, null, 0), ), true);
));
$this->git->runCommand($commandCallable, 'https://github.com/acme/repo', null, true); $this->git->runCommand($commandCallable, 'https://github.com/acme/repo', null, true);
$this->process->assertComplete($this);
} }
/** /**
* @dataProvider privateGithubWithCredentialsProvider * @dataProvider privateGithubWithCredentialsProvider
*/ */
public function testRunCommandPrivateGitHubRepositoryNotInitialCloneNotInteractiveWithAuthentication($gitUrl, $protocol, $gitHubToken, $expectedUrl) public function testRunCommandPrivateGitHubRepositoryNotInitialCloneNotInteractiveWithAuthentication($gitUrl, $protocol, $gitHubToken, $expectedUrl, $expectedFailuresBeforeSuccess)
{ {
$commandCallable = function ($url) use ($expectedUrl) { $commandCallable = function ($url) use ($expectedUrl) {
if ($url !== $expectedUrl) { if ($url !== $expectedUrl) {
@ -110,13 +109,10 @@ class GitTest extends TestCase
$this->mockConfig($protocol); $this->mockConfig($protocol);
$this->process $expectedCalls = array_fill(0, $expectedFailuresBeforeSuccess, array('cmd' => 'git command failing', 'return' => 1));
->expects($this->atLeast(2)) $expectedCalls[] = array('cmd' => 'git command ok', 'return' => 0);
->method('execute')
->willReturnMap(array( $this->process->expects($expectedCalls, true);
array('git command failing', null, null, 1),
array('git command ok', null, null, 0),
));
$this->io $this->io
->method('isInteractive') ->method('isInteractive')
@ -135,13 +131,15 @@ class GitTest extends TestCase
->willReturn(array('username' => 'token', 'password' => $gitHubToken)); ->willReturn(array('username' => 'token', 'password' => $gitHubToken));
$this->git->runCommand($commandCallable, $gitUrl, null, true); $this->git->runCommand($commandCallable, $gitUrl, null, true);
$this->process->assertComplete($this);
} }
public function privateGithubWithCredentialsProvider() public function privateGithubWithCredentialsProvider()
{ {
return array( return array(
array('git@github.com:acme/repo.git', 'ssh', 'MY_GITHUB_TOKEN', 'https://token:MY_GITHUB_TOKEN@github.com/acme/repo.git'), array('git@github.com:acme/repo.git', 'ssh', 'MY_GITHUB_TOKEN', 'https://token:MY_GITHUB_TOKEN@github.com/acme/repo.git', 1),
array('https://github.com/acme/repo', 'https', 'MY_GITHUB_TOKEN', 'https://token:MY_GITHUB_TOKEN@github.com/acme/repo.git'), array('https://github.com/acme/repo', 'https', 'MY_GITHUB_TOKEN', 'https://token:MY_GITHUB_TOKEN@github.com/acme/repo.git', 2),
); );
} }