GitLabDriverTest.php 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570
  1. <?php
  2. /*
  3. * This file is part of Composer.
  4. *
  5. * (c) Nils Adermann <naderman@naderman.de>
  6. * Jordi Boggiano <j.boggiano@seld.be>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Composer\Test\Repository\Vcs;
  12. use Composer\Repository\Vcs\GitLabDriver;
  13. use Composer\Config;
  14. use Composer\Test\TestCase;
  15. use Composer\Util\Filesystem;
  16. use Prophecy\Argument;
  17. use Composer\Util\Http\Response;
  18. /**
  19. * @author Jérôme Tamarelle <jerome@tamarelle.net>
  20. */
  21. class GitLabDriverTest extends TestCase
  22. {
  23. private $home;
  24. private $config;
  25. private $io;
  26. private $process;
  27. private $httpDownloader;
  28. public function setUp()
  29. {
  30. $this->home = $this->getUniqueTmpDirectory();
  31. $this->config = new Config();
  32. $this->config->merge(array(
  33. 'config' => array(
  34. 'home' => $this->home,
  35. 'gitlab-domains' => array(
  36. 'mycompany.com/gitlab',
  37. 'gitlab.mycompany.com',
  38. 'othercompany.com/nested/gitlab',
  39. 'gitlab.com',
  40. ),
  41. ),
  42. ));
  43. $this->io = $this->prophesize('Composer\IO\IOInterface');
  44. $this->process = $this->prophesize('Composer\Util\ProcessExecutor');
  45. $this->httpDownloader = $this->prophesize('Composer\Util\HttpDownloader');
  46. }
  47. public function tearDown()
  48. {
  49. $fs = new Filesystem();
  50. $fs->removeDirectory($this->home);
  51. }
  52. public function getInitializeUrls()
  53. {
  54. return array(
  55. array('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject'),
  56. array('http://gitlab.com/mygroup/myproject', 'http://gitlab.com/api/v4/projects/mygroup%2Fmyproject'),
  57. array('git@gitlab.com:mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject'),
  58. );
  59. }
  60. /**
  61. * @dataProvider getInitializeUrls
  62. */
  63. public function testInitialize($url, $apiUrl)
  64. {
  65. // @link http://doc.gitlab.com/ce/api/projects.html#get-single-project
  66. $projectData = <<<JSON
  67. {
  68. "id": 17,
  69. "default_branch": "mymaster",
  70. "visibility": "private",
  71. "http_url_to_repo": "https://gitlab.com/mygroup/myproject.git",
  72. "ssh_url_to_repo": "git@gitlab.com:mygroup/myproject.git",
  73. "last_activity_at": "2014-12-01T09:17:51.000+01:00",
  74. "name": "My Project",
  75. "name_with_namespace": "My Group / My Project",
  76. "path": "myproject",
  77. "path_with_namespace": "mygroup/myproject",
  78. "web_url": "https://gitlab.com/mygroup/myproject"
  79. }
  80. JSON;
  81. $this->mockResponse($apiUrl, array(), $projectData)
  82. ->shouldBeCalledTimes(1)
  83. ;
  84. $driver = new GitLabDriver(array('url' => $url), $this->io->reveal(), $this->config, $this->httpDownloader->reveal(), $this->process->reveal());
  85. $driver->initialize();
  86. $this->assertEquals($apiUrl, $driver->getApiUrl(), 'API URL is derived from the repository URL');
  87. $this->assertEquals('mymaster', $driver->getRootIdentifier(), 'Root identifier is the default branch in GitLab');
  88. $this->assertEquals('git@gitlab.com:mygroup/myproject.git', $driver->getRepositoryUrl(), 'The repository URL is the SSH one by default');
  89. $this->assertEquals('https://gitlab.com/mygroup/myproject', $driver->getUrl());
  90. return $driver;
  91. }
  92. /**
  93. * @dataProvider getInitializeUrls
  94. */
  95. public function testInitializePublicProject($url, $apiUrl)
  96. {
  97. // @link http://doc.gitlab.com/ce/api/projects.html#get-single-project
  98. $projectData = <<<JSON
  99. {
  100. "id": 17,
  101. "default_branch": "mymaster",
  102. "visibility": "public",
  103. "http_url_to_repo": "https://gitlab.com/mygroup/myproject.git",
  104. "ssh_url_to_repo": "git@gitlab.com:mygroup/myproject.git",
  105. "last_activity_at": "2014-12-01T09:17:51.000+01:00",
  106. "name": "My Project",
  107. "name_with_namespace": "My Group / My Project",
  108. "path": "myproject",
  109. "path_with_namespace": "mygroup/myproject",
  110. "web_url": "https://gitlab.com/mygroup/myproject"
  111. }
  112. JSON;
  113. $this->mockResponse($apiUrl, array(), $projectData)
  114. ->shouldBeCalledTimes(1)
  115. ;
  116. $driver = new GitLabDriver(array('url' => $url), $this->io->reveal(), $this->config, $this->httpDownloader->reveal(), $this->process->reveal());
  117. $driver->initialize();
  118. $this->assertEquals($apiUrl, $driver->getApiUrl(), 'API URL is derived from the repository URL');
  119. $this->assertEquals('mymaster', $driver->getRootIdentifier(), 'Root identifier is the default branch in GitLab');
  120. $this->assertEquals('https://gitlab.com/mygroup/myproject.git', $driver->getRepositoryUrl(), 'The repository URL is the SSH one by default');
  121. $this->assertEquals('https://gitlab.com/mygroup/myproject', $driver->getUrl());
  122. return $driver;
  123. }
  124. /**
  125. * @dataProvider getInitializeUrls
  126. */
  127. public function testInitializePublicProjectAsAnonymous($url, $apiUrl)
  128. {
  129. // @link http://doc.gitlab.com/ce/api/projects.html#get-single-project
  130. $projectData = <<<JSON
  131. {
  132. "id": 17,
  133. "default_branch": "mymaster",
  134. "http_url_to_repo": "https://gitlab.com/mygroup/myproject.git",
  135. "ssh_url_to_repo": "git@gitlab.com:mygroup/myproject.git",
  136. "last_activity_at": "2014-12-01T09:17:51.000+01:00",
  137. "name": "My Project",
  138. "name_with_namespace": "My Group / My Project",
  139. "path": "myproject",
  140. "path_with_namespace": "mygroup/myproject",
  141. "web_url": "https://gitlab.com/mygroup/myproject"
  142. }
  143. JSON;
  144. $this->mockResponse($apiUrl, array(), $projectData)
  145. ->shouldBeCalledTimes(1)
  146. ;
  147. $driver = new GitLabDriver(array('url' => $url), $this->io->reveal(), $this->config, $this->httpDownloader->reveal(), $this->process->reveal());
  148. $driver->initialize();
  149. $this->assertEquals($apiUrl, $driver->getApiUrl(), 'API URL is derived from the repository URL');
  150. $this->assertEquals('mymaster', $driver->getRootIdentifier(), 'Root identifier is the default branch in GitLab');
  151. $this->assertEquals('https://gitlab.com/mygroup/myproject.git', $driver->getRepositoryUrl(), 'The repository URL is the SSH one by default');
  152. $this->assertEquals('https://gitlab.com/mygroup/myproject', $driver->getUrl());
  153. return $driver;
  154. }
  155. /**
  156. * Also support repositories over HTTP (TLS) and has a port number.
  157. *
  158. * @group gitlabHttpPort
  159. */
  160. public function testInitializeWithPortNumber()
  161. {
  162. $domain = 'gitlab.mycompany.com';
  163. $port = '5443';
  164. $namespace = 'mygroup/myproject';
  165. $url = sprintf('https://%1$s:%2$s/%3$s', $domain, $port, $namespace);
  166. $apiUrl = sprintf('https://%1$s:%2$s/api/v4/projects/%3$s', $domain, $port, urlencode($namespace));
  167. // An incomplete single project API response payload.
  168. // @link http://doc.gitlab.com/ce/api/projects.html#get-single-project
  169. $projectData = <<<'JSON'
  170. {
  171. "default_branch": "1.0.x",
  172. "http_url_to_repo": "https://%1$s:%2$s/%3$s.git",
  173. "path": "myproject",
  174. "path_with_namespace": "%3$s",
  175. "web_url": "https://%1$s:%2$s/%3$s"
  176. }
  177. JSON;
  178. $this->mockResponse($apiUrl, array(), sprintf($projectData, $domain, $port, $namespace))
  179. ->shouldBeCalledTimes(1);
  180. $driver = new GitLabDriver(array('url' => $url), $this->io->reveal(), $this->config, $this->httpDownloader->reveal(), $this->process->reveal());
  181. $driver->initialize();
  182. $this->assertEquals($apiUrl, $driver->getApiUrl(), 'API URL is derived from the repository URL');
  183. $this->assertEquals('1.0.x', $driver->getRootIdentifier(), 'Root identifier is the default branch in GitLab');
  184. $this->assertEquals($url.'.git', $driver->getRepositoryUrl(), 'The repository URL is the SSH one by default');
  185. $this->assertEquals($url, $driver->getUrl());
  186. }
  187. public function testGetDist()
  188. {
  189. $driver = $this->testInitialize('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject');
  190. $reference = 'c3ebdbf9cceddb82cd2089aaef8c7b992e536363';
  191. $expected = array(
  192. 'type' => 'zip',
  193. 'url' => 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject/repository/archive.zip?sha='.$reference,
  194. 'reference' => $reference,
  195. 'shasum' => '',
  196. );
  197. $this->assertEquals($expected, $driver->getDist($reference));
  198. }
  199. public function testGetSource()
  200. {
  201. $driver = $this->testInitialize('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject');
  202. $reference = 'c3ebdbf9cceddb82cd2089aaef8c7b992e536363';
  203. $expected = array(
  204. 'type' => 'git',
  205. 'url' => 'git@gitlab.com:mygroup/myproject.git',
  206. 'reference' => $reference,
  207. );
  208. $this->assertEquals($expected, $driver->getSource($reference));
  209. }
  210. public function testGetSource_GivenPublicProject()
  211. {
  212. $driver = $this->testInitializePublicProject('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject');
  213. $reference = 'c3ebdbf9cceddb82cd2089aaef8c7b992e536363';
  214. $expected = array(
  215. 'type' => 'git',
  216. 'url' => 'https://gitlab.com/mygroup/myproject.git',
  217. 'reference' => $reference,
  218. );
  219. $this->assertEquals($expected, $driver->getSource($reference));
  220. }
  221. public function testGetTags()
  222. {
  223. $driver = $this->testInitialize('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject');
  224. $apiUrl = 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject/repository/tags?per_page=100';
  225. // @link http://doc.gitlab.com/ce/api/repositories.html#list-project-repository-tags
  226. $tagData = <<<JSON
  227. [
  228. {
  229. "name": "v1.0.0",
  230. "commit": {
  231. "id": "092ed2c762bbae331e3f51d4a17f67310bf99a81",
  232. "committed_date": "2012-05-28T04:42:42-07:00"
  233. }
  234. },
  235. {
  236. "name": "v2.0.0",
  237. "commit": {
  238. "id": "8e8f60b3ec86d63733db3bd6371117a758027ec6",
  239. "committed_date": "2014-07-06T12:59:11.000+02:00"
  240. }
  241. }
  242. ]
  243. JSON;
  244. $this->mockResponse($apiUrl, array(), $tagData)
  245. ->shouldBeCalledTimes(1)
  246. ;
  247. $driver->setHttpDownloader($this->httpDownloader->reveal());
  248. $expected = array(
  249. 'v1.0.0' => '092ed2c762bbae331e3f51d4a17f67310bf99a81',
  250. 'v2.0.0' => '8e8f60b3ec86d63733db3bd6371117a758027ec6',
  251. );
  252. $this->assertEquals($expected, $driver->getTags());
  253. $this->assertEquals($expected, $driver->getTags(), 'Tags are cached');
  254. }
  255. public function testGetPaginatedRefs()
  256. {
  257. $driver = $this->testInitialize('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject');
  258. $apiUrl = 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject/repository/branches?per_page=100';
  259. // @link http://doc.gitlab.com/ce/api/repositories.html#list-project-repository-branches
  260. $branchData = array(
  261. array(
  262. "name" => "mymaster",
  263. "commit" => array(
  264. "id" => "97eda36b5c1dd953a3792865c222d4e85e5f302e",
  265. "committed_date" => "2013-01-03T21:04:07.000+01:00",
  266. ),
  267. ),
  268. array(
  269. "name" => "staging",
  270. "commit" => array(
  271. "id" => "502cffe49f136443f2059803f2e7192d1ac066cd",
  272. "committed_date" => "2013-03-09T16:35:23.000+01:00",
  273. ),
  274. ),
  275. );
  276. for ($i = 0; $i < 98; $i++) {
  277. $branchData[] = array(
  278. "name" => "stagingdupe",
  279. "commit" => array(
  280. "id" => "502cffe49f136443f2059803f2e7192d1ac066cd",
  281. "committed_date" => "2013-03-09T16:35:23.000+01:00",
  282. ),
  283. );
  284. }
  285. $branchData = json_encode($branchData);
  286. $headers = array('Link: <http://gitlab.com/api/v4/projects/mygroup%2Fmyproject/repository/tags?id=mygroup%2Fmyproject&page=2&per_page=20>; rel="next", <http://gitlab.com/api/v4/projects/mygroup%2Fmyproject/repository/tags?id=mygroup%2Fmyproject&page=1&per_page=20>; rel="first", <http://gitlab.com/api/v4/projects/mygroup%2Fmyproject/repository/tags?id=mygroup%2Fmyproject&page=3&per_page=20>; rel="last"');
  287. $this->httpDownloader
  288. ->get($apiUrl, array())
  289. ->willReturn(new Response(array('url' => $apiUrl), 200, $headers, $branchData))
  290. ->shouldBeCalledTimes(1);
  291. $apiUrl = "http://gitlab.com/api/v4/projects/mygroup%2Fmyproject/repository/tags?id=mygroup%2Fmyproject&page=2&per_page=20";
  292. $headers = array('Link: <http://gitlab.com/api/v4/projects/mygroup%2Fmyproject/repository/tags?id=mygroup%2Fmyproject&page=2&per_page=20>; rel="prev", <http://gitlab.com/api/v4/projects/mygroup%2Fmyproject/repository/tags?id=mygroup%2Fmyproject&page=1&per_page=20>; rel="first", <http://gitlab.com/api/v4/projects/mygroup%2Fmyproject/repository/tags?id=mygroup%2Fmyproject&page=3&per_page=20>; rel="last"');
  293. $this->httpDownloader
  294. ->get($apiUrl, array())
  295. ->willReturn(new Response(array('url' => $apiUrl), 200, $headers, $branchData))
  296. ->shouldBeCalledTimes(1);
  297. $driver->setHttpDownloader($this->httpDownloader->reveal());
  298. $expected = array(
  299. 'mymaster' => '97eda36b5c1dd953a3792865c222d4e85e5f302e',
  300. 'staging' => '502cffe49f136443f2059803f2e7192d1ac066cd',
  301. 'stagingdupe' => '502cffe49f136443f2059803f2e7192d1ac066cd',
  302. );
  303. $this->assertEquals($expected, $driver->getBranches());
  304. $this->assertEquals($expected, $driver->getBranches(), 'Branches are cached');
  305. }
  306. public function testGetBranches()
  307. {
  308. $driver = $this->testInitialize('https://gitlab.com/mygroup/myproject', 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject');
  309. $apiUrl = 'https://gitlab.com/api/v4/projects/mygroup%2Fmyproject/repository/branches?per_page=100';
  310. // @link http://doc.gitlab.com/ce/api/repositories.html#list-project-repository-branches
  311. $branchData = <<<JSON
  312. [
  313. {
  314. "name": "mymaster",
  315. "commit": {
  316. "id": "97eda36b5c1dd953a3792865c222d4e85e5f302e",
  317. "committed_date": "2013-01-03T21:04:07.000+01:00"
  318. }
  319. },
  320. {
  321. "name": "staging",
  322. "commit": {
  323. "id": "502cffe49f136443f2059803f2e7192d1ac066cd",
  324. "committed_date": "2013-03-09T16:35:23.000+01:00"
  325. }
  326. }
  327. ]
  328. JSON;
  329. $this->mockResponse($apiUrl, array(), $branchData)
  330. ->shouldBeCalledTimes(1)
  331. ;
  332. $driver->setHttpDownloader($this->httpDownloader->reveal());
  333. $expected = array(
  334. 'mymaster' => '97eda36b5c1dd953a3792865c222d4e85e5f302e',
  335. 'staging' => '502cffe49f136443f2059803f2e7192d1ac066cd',
  336. );
  337. $this->assertEquals($expected, $driver->getBranches());
  338. $this->assertEquals($expected, $driver->getBranches(), 'Branches are cached');
  339. }
  340. /**
  341. * @group gitlabHttpPort
  342. * @dataProvider dataForTestSupports
  343. */
  344. public function testSupports($url, $expected)
  345. {
  346. $this->assertSame($expected, GitLabDriver::supports($this->io->reveal(), $this->config, $url));
  347. }
  348. public function dataForTestSupports()
  349. {
  350. return array(
  351. array('http://gitlab.com/foo/bar', true),
  352. array('http://gitlab.mycompany.com:5443/foo/bar', true),
  353. array('http://gitlab.com/foo/bar/', true),
  354. array('http://gitlab.com/foo/bar/', true),
  355. array('http://gitlab.com/foo/bar.git', true),
  356. array('http://gitlab.com/foo/bar.git', true),
  357. array('http://gitlab.com/foo/bar.baz.git', true),
  358. array('https://gitlab.com/foo/bar', extension_loaded('openssl')), // Platform requirement
  359. array('https://gitlab.mycompany.com:5443/foo/bar', extension_loaded('openssl')), // Platform requirement
  360. array('git@gitlab.com:foo/bar.git', extension_loaded('openssl')),
  361. array('git@example.com:foo/bar.git', false),
  362. array('http://example.com/foo/bar', false),
  363. array('http://mycompany.com/gitlab/mygroup/myproject', true),
  364. array('https://mycompany.com/gitlab/mygroup/myproject', extension_loaded('openssl')),
  365. array('http://othercompany.com/nested/gitlab/mygroup/myproject', true),
  366. array('https://othercompany.com/nested/gitlab/mygroup/myproject', extension_loaded('openssl')),
  367. array('http://gitlab.com/mygroup/mysubgroup/mysubsubgroup/myproject', true),
  368. array('https://gitlab.com/mygroup/mysubgroup/mysubsubgroup/myproject', extension_loaded('openssl')),
  369. );
  370. }
  371. public function testGitlabSubDirectory()
  372. {
  373. $url = 'https://mycompany.com/gitlab/mygroup/my-pro.ject';
  374. $apiUrl = 'https://mycompany.com/gitlab/api/v4/projects/mygroup%2Fmy-pro%2Eject';
  375. $projectData = <<<JSON
  376. {
  377. "id": 17,
  378. "default_branch": "mymaster",
  379. "visibility": "private",
  380. "http_url_to_repo": "https://gitlab.com/gitlab/mygroup/my-pro.ject",
  381. "ssh_url_to_repo": "git@gitlab.com:mygroup/my-pro.ject.git",
  382. "last_activity_at": "2014-12-01T09:17:51.000+01:00",
  383. "name": "My Project",
  384. "name_with_namespace": "My Group / My Project",
  385. "path": "myproject",
  386. "path_with_namespace": "mygroup/my-pro.ject",
  387. "web_url": "https://gitlab.com/gitlab/mygroup/my-pro.ject"
  388. }
  389. JSON;
  390. $this->mockResponse($apiUrl, array(), $projectData)
  391. ->shouldBeCalledTimes(1)
  392. ;
  393. $driver = new GitLabDriver(array('url' => $url), $this->io->reveal(), $this->config, $this->httpDownloader->reveal(), $this->process->reveal());
  394. $driver->initialize();
  395. $this->assertEquals($apiUrl, $driver->getApiUrl(), 'API URL is derived from the repository URL');
  396. }
  397. public function testGitlabSubGroup()
  398. {
  399. $url = 'https://gitlab.com/mygroup/mysubgroup/myproject';
  400. $apiUrl = 'https://gitlab.com/api/v4/projects/mygroup%2Fmysubgroup%2Fmyproject';
  401. $projectData = <<<JSON
  402. {
  403. "id": 17,
  404. "default_branch": "mymaster",
  405. "visibility": "private",
  406. "http_url_to_repo": "https://gitlab.com/mygroup/mysubgroup/my-pro.ject",
  407. "ssh_url_to_repo": "git@gitlab.com:mygroup/mysubgroup/my-pro.ject.git",
  408. "last_activity_at": "2014-12-01T09:17:51.000+01:00",
  409. "name": "My Project",
  410. "name_with_namespace": "My Group / My Project",
  411. "path": "myproject",
  412. "path_with_namespace": "mygroup/mysubgroup/my-pro.ject",
  413. "web_url": "https://gitlab.com/mygroup/mysubgroup/my-pro.ject"
  414. }
  415. JSON;
  416. $this->mockResponse($apiUrl, array(), $projectData)
  417. ->shouldBeCalledTimes(1)
  418. ;
  419. $driver = new GitLabDriver(array('url' => $url), $this->io->reveal(), $this->config, $this->httpDownloader->reveal(), $this->process->reveal());
  420. $driver->initialize();
  421. $this->assertEquals($apiUrl, $driver->getApiUrl(), 'API URL is derived from the repository URL');
  422. }
  423. public function testGitlabSubDirectorySubGroup()
  424. {
  425. $url = 'https://mycompany.com/gitlab/mygroup/mysubgroup/myproject';
  426. $apiUrl = 'https://mycompany.com/gitlab/api/v4/projects/mygroup%2Fmysubgroup%2Fmyproject';
  427. $projectData = <<<JSON
  428. {
  429. "id": 17,
  430. "default_branch": "mymaster",
  431. "visibility": "private",
  432. "http_url_to_repo": "https://mycompany.com/gitlab/mygroup/mysubgroup/my-pro.ject",
  433. "ssh_url_to_repo": "git@mycompany.com:mygroup/mysubgroup/my-pro.ject.git",
  434. "last_activity_at": "2014-12-01T09:17:51.000+01:00",
  435. "name": "My Project",
  436. "name_with_namespace": "My Group / My Project",
  437. "path": "myproject",
  438. "path_with_namespace": "mygroup/mysubgroup/my-pro.ject",
  439. "web_url": "https://mycompany.com/gitlab/mygroup/mysubgroup/my-pro.ject"
  440. }
  441. JSON;
  442. $this->mockResponse($apiUrl, array(), $projectData)
  443. ->shouldBeCalledTimes(1)
  444. ;
  445. $driver = new GitLabDriver(array('url' => $url), $this->io->reveal(), $this->config, $this->httpDownloader->reveal(), $this->process->reveal());
  446. $driver->initialize();
  447. $this->assertEquals($apiUrl, $driver->getApiUrl(), 'API URL is derived from the repository URL');
  448. }
  449. public function testForwardsOptions()
  450. {
  451. $options = array(
  452. 'ssl' => array(
  453. 'verify_peer' => false,
  454. ),
  455. );
  456. $projectData = <<<JSON
  457. {
  458. "id": 17,
  459. "default_branch": "mymaster",
  460. "visibility": "private",
  461. "http_url_to_repo": "https://gitlab.mycompany.local/mygroup/myproject",
  462. "ssh_url_to_repo": "git@gitlab.mycompany.local:mygroup/myproject.git",
  463. "last_activity_at": "2014-12-01T09:17:51.000+01:00",
  464. "name": "My Project",
  465. "name_with_namespace": "My Group / My Project",
  466. "path": "myproject",
  467. "path_with_namespace": "mygroup/myproject",
  468. "web_url": "https://gitlab.mycompany.local/mygroup/myproject"
  469. }
  470. JSON;
  471. $this->mockResponse(Argument::cetera(), $options, $projectData)
  472. ->shouldBeCalled();
  473. $driver = new GitLabDriver(
  474. array('url' => 'https://gitlab.mycompany.local/mygroup/myproject', 'options' => $options),
  475. $this->io->reveal(),
  476. $this->config,
  477. $this->httpDownloader->reveal(),
  478. $this->process->reveal()
  479. );
  480. $driver->initialize();
  481. }
  482. private function mockResponse($url, $options, $return)
  483. {
  484. return $this->httpDownloader
  485. ->get($url, $options)
  486. ->willReturn(new Response(array('url' => $url), 200, array(), $return));
  487. }
  488. }