1+ <?php namespace Gitlab \Tests \Api ;
2+
3+ use Gitlab \Api \AbstractApi ;
4+
5+ class ProjectsTest extends TestCase
6+ {
7+ /**
8+ * @test
9+ */
10+ public function shouldGetAllProjects ()
11+ {
12+ $ expectedArray = $ this ->getMultipleProjectsData ();
13+
14+ $ api = $ this ->getMultipleProjectsRequestMock ('projects/all ' , $ expectedArray );
15+
16+ $ this ->assertEquals ($ expectedArray , $ api ->all (1 , 10 ));
17+ }
18+
19+ /**
20+ * @test
21+ */
22+ public function shouldNotNeedPaginationWhenGettingProjects ()
23+ {
24+ $ expectedArray = $ this ->getMultipleProjectsData ();
25+
26+ $ api = $ this ->getApiMock ();
27+ $ api ->expects ($ this ->once ())
28+ ->method ('get ' )
29+ ->with ('projects/all ' , array ('page ' => 1 , 'per_page ' => AbstractApi::PER_PAGE ))
30+ ->will ($ this ->returnValue ($ expectedArray ))
31+ ;
32+
33+ $ this ->assertEquals ($ expectedArray , $ api ->all ());
34+ }
35+
36+ /**
37+ * @test
38+ */
39+ public function shouldGetAccessibleProjects ()
40+ {
41+ $ expectedArray = $ this ->getMultipleProjectsData ();
42+
43+ $ api = $ this ->getMultipleProjectsRequestMock ('projects ' , $ expectedArray , 2 , 7 );
44+
45+ $ this ->assertEquals ($ expectedArray , $ api ->accessible (2 , 7 ));
46+ }
47+
48+ /**
49+ * @test
50+ */
51+ public function shouldGetOwnedProjects ()
52+ {
53+ $ expectedArray = $ this ->getMultipleProjectsData ();
54+
55+ $ api = $ this ->getMultipleProjectsRequestMock ('projects/owned ' , $ expectedArray , 3 , 50 );
56+
57+ $ this ->assertEquals ($ expectedArray , $ api ->owned (3 , 50 ));
58+ }
59+
60+ /**
61+ * @test
62+ */
63+ public function shouldSearchProjects ()
64+ {
65+ $ expectedArray = $ this ->getMultipleProjectsData ();
66+
67+ $ api = $ this ->getMultipleProjectsRequestMock ('projects/search/a+project ' , $ expectedArray );
68+
69+ $ this ->assertEquals ($ expectedArray , $ api ->search ('a project ' , 1 , 10 ));
70+ }
71+
72+ /**
73+ * @test
74+ */
75+ public function shouldShowProject ()
76+ {
77+ $ expectedArray = array ('id ' => 1 , 'name ' => 'Project Name ' );
78+
79+ $ api = $ this ->getApiMock ();
80+ $ api ->expects ($ this ->once ())
81+ ->method ('get ' )
82+ ->with ('projects/1 ' )
83+ ->will ($ this ->returnValue ($ expectedArray ))
84+ ;
85+
86+ $ this ->assertEquals ($ expectedArray , $ api ->show (1 ));
87+ }
88+
89+ /**
90+ * @test
91+ */
92+ public function shouldCreateProject ()
93+ {
94+ $ expectedArray = array ('id ' => 1 , 'name ' => 'Project Name ' );
95+
96+ $ api = $ this ->getApiMock ();
97+ $ api ->expects ($ this ->once ())
98+ ->method ('post ' )
99+ ->with ('projects ' , array ('name ' => 'Project Name ' , 'issues_enabled ' => true ))
100+ ->will ($ this ->returnValue ($ expectedArray ))
101+ ;
102+
103+ $ this ->assertEquals ($ expectedArray , $ api ->create ('Project Name ' , array (
104+ 'issues_enabled ' => true
105+ )));
106+ }
107+
108+ protected function getMultipleProjectsRequestMock ($ path , $ expectedArray = array (), $ page = 1 , $ per_page = 10 )
109+ {
110+ $ api = $ this ->getApiMock ();
111+ $ api ->expects ($ this ->once ())
112+ ->method ('get ' )
113+ ->with ($ path , array ('page ' => $ page , 'per_page ' => $ per_page ))
114+ ->will ($ this ->returnValue ($ expectedArray ))
115+ ;
116+
117+ return $ api ;
118+ }
119+
120+ protected function getMultipleProjectsData ()
121+ {
122+ return array (
123+ array ('id ' => 1 , 'name ' => 'A project ' ),
124+ array ('id ' => 2 , 'name ' => 'Another project ' )
125+ );
126+ }
127+
128+ protected function getApiClass ()
129+ {
130+ return 'Gitlab\Api\Projects ' ;
131+ }
132+ }
0 commit comments