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:
parent
ebd0a60411
commit
9f3e2105da
15 changed files with 394 additions and 265 deletions
|
@ -36,23 +36,11 @@ class GitLabTest extends TestCase
|
|||
public function testUsernamePasswordAuthenticationFlow(): void
|
||||
{
|
||||
$io = $this->getIOMock();
|
||||
$io
|
||||
->expects($this->atLeastOnce())
|
||||
->method('writeError')
|
||||
->withConsecutive([$this->message])
|
||||
;
|
||||
$io
|
||||
->expects($this->once())
|
||||
->method('ask')
|
||||
->with('Username: ')
|
||||
->willReturn($this->username)
|
||||
;
|
||||
$io
|
||||
->expects($this->once())
|
||||
->method('askAndHideAnswer')
|
||||
->with('Password: ')
|
||||
->willReturn($this->password)
|
||||
;
|
||||
$io->expects([
|
||||
['text' => $this->message],
|
||||
['ask' => 'Username: ', 'reply' => $this->username],
|
||||
['ask' => 'Password: ', 'reply' => $this->password],
|
||||
]);
|
||||
|
||||
$httpDownloader = $this->getHttpDownloaderMock();
|
||||
$httpDownloader->expects(
|
||||
|
@ -77,18 +65,18 @@ class GitLabTest extends TestCase
|
|||
self::expectException('RuntimeException');
|
||||
self::expectExceptionMessage('Invalid GitLab credentials 5 times in a row, aborting.');
|
||||
$io = $this->getIOMock();
|
||||
$io
|
||||
->expects($this->exactly(5))
|
||||
->method('ask')
|
||||
->with('Username: ')
|
||||
->willReturn($this->username)
|
||||
;
|
||||
$io
|
||||
->expects($this->exactly(5))
|
||||
->method('askAndHideAnswer')
|
||||
->with('Password: ')
|
||||
->willReturn($this->password)
|
||||
;
|
||||
$io->expects([
|
||||
['ask' => 'Username: ', 'reply' => $this->username],
|
||||
['ask' => 'Password: ', 'reply' => $this->password],
|
||||
['ask' => 'Username: ', 'reply' => $this->username],
|
||||
['ask' => 'Password: ', 'reply' => $this->password],
|
||||
['ask' => 'Username: ', 'reply' => $this->username],
|
||||
['ask' => 'Password: ', 'reply' => $this->password],
|
||||
['ask' => 'Username: ', 'reply' => $this->username],
|
||||
['ask' => 'Password: ', 'reply' => $this->password],
|
||||
['ask' => 'Username: ', 'reply' => $this->username],
|
||||
['ask' => 'Password: ', 'reply' => $this->password],
|
||||
]);
|
||||
|
||||
$httpDownloader = $this->getHttpDownloaderMock();
|
||||
$httpDownloader->expects(
|
||||
|
@ -114,20 +102,6 @@ class GitLabTest extends TestCase
|
|||
$gitLab->authorizeOAuthInteractively('https', $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
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue