GitLabDriverTest.php 22 KB

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