From b486056066599a9a0d36f4bfdcf723effb6c7a2c Mon Sep 17 00:00:00 2001 From: Helmut Januschka Date: Mon, 7 Aug 2017 21:46:43 +0200 Subject: [PATCH] add tests for gitlab paging --- .../Test/Repository/Vcs/GitLabDriverTest.php | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php b/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php index c663f929d..dbc3cc512 100644 --- a/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php +++ b/tests/Composer/Test/Repository/Vcs/GitLabDriverTest.php @@ -216,6 +216,9 @@ JSON; ->willReturn($tagData) ->shouldBeCalledTimes(1) ; + $this->remoteFilesystem->getLastHeaders() + ->willReturn([]); + $driver->setRemoteFilesystem($this->remoteFilesystem->reveal()); $expected = array( @@ -227,6 +230,58 @@ JSON; $this->assertEquals($expected, $driver->getTags(), 'Tags are cached'); } + public function testGetTagsPaginated() { + $driver = $this->testInitialize('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject'); + + $apiUrl = 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject/repository/branches'; + + // @link http://doc.gitlab.com/ce/api/repositories.html#list-project-repository-branches + $branchData = <<remoteFilesystem + ->getContents('gitlab.com', $apiUrl, false, array()) + ->willReturn($branchData) + ->shouldBeCalledTimes(1) + ; + + $this->remoteFilesystem + ->getContents('gitlab.com', "http://gitlab.com/api/v4/projects/mygroup%2Fmyproject/repository/tags?id=mygroup%2Fmyproject&page=2&per_page=20", false, array()) + ->willReturn($branchData) + ->shouldBeCalledTimes(1) + ; + + $this->remoteFilesystem->getLastHeaders() + ->willReturn(['Link: ; rel="next", ; rel="first", ; rel="last"'], ['Link: ; rel="prev", ; rel="first", ; rel="last"']) + ->shouldBeCalledTimes(2); + + $driver->setRemoteFilesystem($this->remoteFilesystem->reveal()); + + $expected = array( + 'mymaster' => '97eda36b5c1dd953a3792865c222d4e85e5f302e', + 'staging' => '502cffe49f136443f2059803f2e7192d1ac066cd', + ); + + $this->assertEquals($expected, $driver->getBranches()); + $this->assertEquals($expected, $driver->getBranches(), 'Branches are cached'); + + } public function testGetBranches() { $driver = $this->testInitialize('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject'); @@ -258,6 +313,9 @@ JSON; ->willReturn($branchData) ->shouldBeCalledTimes(1) ; + $this->remoteFilesystem->getLastHeaders() + ->willReturn([]); + $driver->setRemoteFilesystem($this->remoteFilesystem->reveal()); $expected = array(