1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-09 00:22:53 +00:00

Add IOMock and get rid of all withConsecutive calls in tests (#11497)

This commit is contained in:
Jordi Boggiano 2023-06-07 14:35:16 +02:00 committed by GitHub
parent ebd0a60411
commit 9f3e2105da
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 394 additions and 265 deletions

View file

@ -30,17 +30,10 @@ class GitHubTest extends TestCase
public function testUsernamePasswordAuthenticationFlow(): void
{
$io = $this->getIOMock();
$io
->expects($this->atLeastOnce())
->method('writeError')
->withConsecutive([$this->message])
;
$io
->expects($this->once())
->method('askAndHideAnswer')
->with('Token (hidden): ')
->willReturn($this->password)
;
$io->expects([
['text' => $this->message],
['ask' => 'Token (hidden): ', 'reply' => $this->password],
]);
$httpDownloader = $this->getHttpDownloaderMock();
$httpDownloader->expects(
@ -68,12 +61,9 @@ class GitHubTest extends TestCase
public function testUsernamePasswordFailure(): void
{
$io = $this->getIOMock();
$io
->expects($this->exactly(1))
->method('askAndHideAnswer')
->with('Token (hidden): ')
->willReturn($this->password)
;
$io->expects([
['ask' => 'Token (hidden): ', 'reply' => $this->password],
]);
$httpDownloader = $this->getHttpDownloaderMock();
$httpDownloader->expects(
@ -93,20 +83,6 @@ class GitHubTest extends TestCase
$this->assertFalse($github->authorizeOAuthInteractively($this->origin));
}
/**
* @return \PHPUnit\Framework\MockObject\MockObject&\Composer\IO\ConsoleIO
*/
private function getIOMock()
{
$io = $this
->getMockBuilder('Composer\IO\ConsoleIO')
->disableOriginalConstructor()
->getMock()
;
return $io;
}
/**
* @return \PHPUnit\Framework\MockObject\MockObject&\Composer\Config
*/