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

Get rid of all the ->at() mock invocations

This commit is contained in:
Jordi Boggiano 2021-12-09 17:09:07 +01:00
parent 095c36ecf8
commit ffd62795bc
No known key found for this signature in database
GPG key ID: 7BBD42C429EC80BC
56 changed files with 746 additions and 921 deletions

View file

@ -14,11 +14,12 @@ namespace Composer\Test;
use Composer\Console\Application;
use Composer\XdebugHandler\XdebugHandler;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Output\OutputInterface;
class ApplicationTest extends TestCase
{
public function tearDown(): void
protected function tearDown(): void
{
parent::tearDown();
@ -34,27 +35,26 @@ class ApplicationTest extends TestCase
putenv('COMPOSER_NO_INTERACTION=1');
$index = 0;
$inputMock->expects($this->at($index++))
$inputMock->expects($this->any())
->method('hasParameterOption')
->with($this->equalTo('--no-plugins'))
->will($this->returnValue(true));
->willReturnCallback(function ($opt): bool {
switch ($opt) {
case '--no-plugins':
return true;
case '--no-scripts':
return false;
case '--no-cache':
return false;
}
$inputMock->expects($this->at($index++))
->method('hasParameterOption')
->with($this->equalTo('--no-scripts'))
->will($this->returnValue(false));
return false;
});
$inputMock->expects($this->at($index++))
$inputMock->expects($this->once())
->method('setInteractive')
->with($this->equalTo(false));
$inputMock->expects($this->at($index++))
->method('hasParameterOption')
->with($this->equalTo('--no-cache'))
->will($this->returnValue(false));
$inputMock->expects($this->at($index++))
$inputMock->expects($this->once())
->method('getParameterOption')
->with($this->equalTo(array('--working-dir', '-d')))
->will($this->returnValue(false));
@ -63,33 +63,22 @@ class ApplicationTest extends TestCase
->method('getFirstArgument')
->will($this->returnValue('show'));
$index = 0;
$outputMock->expects($this->at($index++))
->method("write");
$output = new BufferedOutput();
$expectedOutput = '';
if (XdebugHandler::isXdebugActive()) {
$outputMock->expects($this->at($index++))
->method("getVerbosity")
->willReturn(OutputInterface::VERBOSITY_NORMAL);
$outputMock->expects($this->at($index++))
->method("write")
->with($this->equalTo('<warning>Composer is operating slower than normal because you have Xdebug enabled. See https://getcomposer.org/xdebug</warning>'));
$expectedOutput .= '<warning>Composer is operating slower than normal because you have Xdebug enabled. See https://getcomposer.org/xdebug</warning>'.PHP_EOL;
}
$outputMock->expects($this->at($index++))
->method("getVerbosity")
->willReturn(OutputInterface::VERBOSITY_NORMAL);
$outputMock->expects($this->at($index++))
->method("write")
->with($this->equalTo(sprintf('<warning>Warning: This development build of Composer is over 60 days old. It is recommended to update it by running "%s self-update" to get the latest version.</warning>', $_SERVER['PHP_SELF'])));
$expectedOutput .= sprintf('<warning>Warning: This development build of Composer is over 60 days old. It is recommended to update it by running "%s self-update" to get the latest version.</warning>', $_SERVER['PHP_SELF']).PHP_EOL;
if (!defined('COMPOSER_DEV_WARNING_TIME')) {
define('COMPOSER_DEV_WARNING_TIME', time() - 1);
}
$application->doRun($inputMock, $outputMock);
$application->doRun($inputMock, $output);
$this->assertStringContainsString($expectedOutput, $output->fetch());
}
/**
@ -107,27 +96,26 @@ class ApplicationTest extends TestCase
putenv('COMPOSER_NO_INTERACTION=1');
$index = 0;
$inputMock->expects($this->at($index++))
$inputMock->expects($this->any())
->method('hasParameterOption')
->with($this->equalTo('--no-plugins'))
->will($this->returnValue(true));
->willReturnCallback(function ($opt): bool {
switch ($opt) {
case '--no-plugins':
return true;
case '--no-scripts':
return false;
case '--no-cache':
return false;
}
$inputMock->expects($this->at($index++))
->method('hasParameterOption')
->with($this->equalTo('--no-scripts'))
->will($this->returnValue(false));
return false;
});
$inputMock->expects($this->at($index++))
$inputMock->expects($this->once())
->method('setInteractive')
->with($this->equalTo(false));
$inputMock->expects($this->at($index++))
->method('hasParameterOption')
->with($this->equalTo('--no-cache'))
->will($this->returnValue(false));
$inputMock->expects($this->at($index++))
$inputMock->expects($this->once())
->method('getParameterOption')
->with($this->equalTo(array('--working-dir', '-d')))
->will($this->returnValue(false));