1
0
Fork 0
mirror of https://github.com/composer/composer synced 2025-05-09 00:22:53 +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

@ -13,6 +13,7 @@
namespace Composer\Test\Util;
use Composer\Downloader\TransportException;
use Composer\Test\Mock\HttpDownloaderMock;
use Composer\Util\GitLab;
use Composer\Util\Http\Response;
use Composer\Test\TestCase;
@ -37,9 +38,9 @@ class GitLabTest extends TestCase
{
$io = $this->getIOMock();
$io
->expects($this->at(0))
->expects($this->atLeastOnce())
->method('writeError')
->with($this->message)
->withConsecutive([$this->message])
;
$io
->expects($this->once())
@ -55,15 +56,10 @@ class GitLabTest extends TestCase
;
$httpDownloader = $this->getHttpDownloaderMock();
$httpDownloader
->expects($this->once())
->method('get')
->with(
$this->equalTo($url = sprintf('http://%s/oauth/token', $this->origin)),
$this->anything()
)
->willReturn(new Response(array('url' => $url), 200, array(), sprintf('{"access_token": "%s", "token_type": "bearer", "expires_in": 7200}', $this->token)))
;
$httpDownloader->expects(
[['url' => sprintf('http://%s/oauth/token', $this->origin), 'body' => sprintf('{"access_token": "%s", "token_type": "bearer", "expires_in": 7200}', $this->token)]],
true
);
$config = $this->getConfigMock();
$config
@ -95,12 +91,16 @@ class GitLabTest extends TestCase
;
$httpDownloader = $this->getHttpDownloaderMock();
$httpDownloader
->expects($this->exactly(5))
->method('get')
->will($this->throwException($e = new TransportException('', 401)))
;
$e->setResponse('{}');
$httpDownloader->expects(
[
['url' => 'https://gitlab.com/oauth/token', 'status' => 401, 'body' => '{}'],
['url' => 'https://gitlab.com/oauth/token', 'status' => 401, 'body' => '{}'],
['url' => 'https://gitlab.com/oauth/token', 'status' => 401, 'body' => '{}'],
['url' => 'https://gitlab.com/oauth/token', 'status' => 401, 'body' => '{}'],
['url' => 'https://gitlab.com/oauth/token', 'status' => 401, 'body' => '{}'],
],
true
);
$config = $this->getConfigMock();
$config
@ -136,20 +136,6 @@ class GitLabTest extends TestCase
return $this->getMockBuilder('Composer\Config')->getMock();
}
/**
* @return \PHPUnit\Framework\MockObject\MockObject&\Composer\Util\HttpDownloader
*/
private function getHttpDownloaderMock()
{
$httpDownloader = $this
->getMockBuilder('Composer\Util\HttpDownloader')
->disableOriginalConstructor()
->getMock()
;
return $httpDownloader;
}
/**
* @return \PHPUnit\Framework\MockObject\MockObject&\Composer\Config\JsonConfigSource
*/