@@ -25,25 +25,184 @@ class ProjectServiceTest extends \PHPUnit\Framework\TestCase
2525
2626 public function setUp ()
2727 {
28- $ this ->mockProjectStore = $ this ->getMockBuilder ('PHPCensor\Store\ProjectStore ' )->getMock ();
29- $ this ->mockProjectStore ->expects ($ this ->any ())
30- ->method ('save ' )
31- ->will ($ this ->returnArgument (0 ));
28+ $ this ->mockProjectStore = $ this
29+ ->getMockBuilder ('PHPCensor\Store\ProjectStore ' )
30+ ->getMock ();
31+
32+ $ this ->mockProjectStore
33+ ->expects ($ this ->any ())
34+ ->method ('save ' )
35+ ->will (
36+ $ this ->returnArgument (0 )
37+ );
3238
3339 $ this ->testedService = new ProjectService ($ this ->mockProjectStore );
3440 }
3541
36- public function testExecute_CreateBasicProject ()
42+ public function testExecuteCreateGithubProject ()
43+ {
44+ $ project = $ this ->testedService ->createProject (
45+ 'Test Project ' ,
46+ 'github ' ,
47+ 'php-censor/php-censor1 ' ,
48+ 0
49+ );
50+
51+ self ::assertEquals ('Test Project ' , $ project ->getTitle ());
52+ self ::assertEquals ('github ' , $ project ->getType ());
53+ self ::assertEquals ('php-censor/php-censor1 ' , $ project ->getReference ());
54+ self ::assertEquals ('master ' , $ project ->getBranch ());
55+ self ::assertEquals ([], $ project ->getAccessInformation ());
56+ }
57+
58+ /**
59+ * @return array
60+ */
61+ public function getExecuteCreateGithubProjectAccessInformationData ()
62+ {
63+ return [
64+ [
65+ 'git@github.com:php-censor/php-censor.git ' , [
66+ 'user ' => 'git ' ,
67+ 'domain ' => 'github.com ' ,
68+ 'reference ' => 'php-censor/php-censor ' ,
69+ 'origin ' => 'git@github.com:php-censor/php-censor.git ' ,
70+ ],
71+ ], [
72+ 'git@sss.github.com:php-censor/php-censor.git ' , [
73+ 'user ' => 'git ' ,
74+ 'domain ' => 'sss.github.com ' ,
75+ 'reference ' => 'php-censor/php-censor ' ,
76+ 'origin ' => 'git@sss.github.com:php-censor/php-censor.git ' ,
77+ ],
78+ ], [
79+ 'ssh://git@github.com/php-censor/php-censor.git ' , [
80+ 'user ' => 'git ' ,
81+ 'domain ' => 'github.com ' ,
82+ 'reference ' => 'php-censor/php-censor ' ,
83+ 'origin ' => 'ssh://git@github.com/php-censor/php-censor.git ' ,
84+ ],
85+ ], [
86+ 'https://github.com/php-censor/php-censor.git ' , [
87+ 'domain ' => 'github.com ' ,
88+ 'reference ' => 'php-censor/php-censor ' ,
89+ 'origin ' => 'https://github.com/php-censor/php-censor.git ' ,
90+ ],
91+ ], [
92+ 'http://github.com/php-censor/php-censor.git ' , [
93+ 'domain ' => 'github.com ' ,
94+ 'reference ' => 'php-censor/php-censor ' ,
95+ 'origin ' => 'http://github.com/php-censor/php-censor.git ' ,
96+ ],
97+ ], [
98+ 'git@github.com:443/php-censor/php-censor.git ' , [
99+ 'user ' => 'git ' ,
100+ 'domain ' => 'github.com ' ,
101+ 'port ' => '443 ' ,
102+ 'reference ' => 'php-censor/php-censor ' ,
103+ 'origin ' => 'git@github.com:443/php-censor/php-censor.git ' ,
104+ ],
105+ ], [
106+ 'ssh://git@github.com:443/php-censor/php-censor.git ' , [
107+ 'user ' => 'git ' ,
108+ 'domain ' => 'github.com ' ,
109+ 'port ' => '443 ' ,
110+ 'reference ' => 'php-censor/php-censor ' ,
111+ 'origin ' => 'ssh://git@github.com:443/php-censor/php-censor.git ' ,
112+ ],
113+ ], [
114+ 'https://github.com:443/php-censor/php-censor.git ' , [
115+ 'domain ' => 'github.com ' ,
116+ 'port ' => '443 ' ,
117+ 'reference ' => 'php-censor/php-censor ' ,
118+ 'origin ' => 'https://github.com:443/php-censor/php-censor.git ' ,
119+ ],
120+ ], [
121+ 'http://github.com:443/php-censor/php-censor.git ' , [
122+ 'domain ' => 'github.com ' ,
123+ 'port ' => '443 ' ,
124+ 'reference ' => 'php-censor/php-censor ' ,
125+ 'origin ' => 'http://github.com:443/php-censor/php-censor.git ' ,
126+ ],
127+ ], [
128+ 'git@github:php-censor.git ' , [
129+ 'user ' => 'git ' ,
130+ 'domain ' => 'github ' ,
131+ 'reference ' => 'php-censor ' ,
132+ 'origin ' => 'git@github:php-censor.git ' ,
133+ ],
134+ ], [
135+ 'ssh://git@github/php-censor.git ' , [
136+ 'user ' => 'git ' ,
137+ 'domain ' => 'github ' ,
138+ 'reference ' => 'php-censor ' ,
139+ 'origin ' => 'ssh://git@github/php-censor.git ' ,
140+ ],
141+ ], [
142+ 'https://github/php-censor.git ' , [
143+ 'domain ' => 'github ' ,
144+ 'reference ' => 'php-censor ' ,
145+ 'origin ' => 'https://github/php-censor.git ' ,
146+ ],
147+ ], [
148+ 'http://github/php-censor.git ' , [
149+ 'domain ' => 'github ' ,
150+ 'reference ' => 'php-censor ' ,
151+ 'origin ' => 'http://github/php-censor.git ' ,
152+ ],
153+ ], [
154+ 'git@github:443/php-censor.git ' , [
155+ 'user ' => 'git ' ,
156+ 'domain ' => 'github ' ,
157+ 'port ' => '443 ' ,
158+ 'reference ' => 'php-censor ' ,
159+ 'origin ' => 'git@github:443/php-censor.git ' ,
160+ ],
161+ ], [
162+ 'ssh://git@github:443/php-censor.git ' , [
163+ 'user ' => 'git ' ,
164+ 'domain ' => 'github ' ,
165+ 'port ' => '443 ' ,
166+ 'reference ' => 'php-censor ' ,
167+ 'origin ' => 'ssh://git@github:443/php-censor.git ' ,
168+ ],
169+ ], [
170+ 'https://github:443/php-censor.git ' , [
171+ 'domain ' => 'github ' ,
172+ 'port ' => '443 ' ,
173+ 'reference ' => 'php-censor ' ,
174+ 'origin ' => 'https://github:443/php-censor.git ' ,
175+ ],
176+ ], [
177+ 'http://github:443/php-censor.git ' , [
178+ 'domain ' => 'github ' ,
179+ 'port ' => '443 ' ,
180+ 'reference ' => 'php-censor ' ,
181+ 'origin ' => 'http://github:443/php-censor.git ' ,
182+ ],
183+ ],
184+ ];
185+ }
186+
187+ /**
188+ * @param string $reference
189+ * @param array $accessInformation
190+ *
191+ * @dataProvider getExecuteCreateGithubProjectAccessInformationData
192+ */
193+ public function testExecuteCreateGithubProjectAccessInformation ($ reference , array $ accessInformation )
37194 {
38- $ returnValue = $ this ->testedService ->createProject ('Test Project ' , 'github ' , 'block8/phpci ' , 0 );
195+ $ project = $ this ->testedService ->createProject (
196+ 'Test Project ' ,
197+ 'github ' ,
198+ $ reference ,
199+ 0
200+ );
39201
40- self ::assertEquals ('Test Project ' , $ returnValue ->getTitle ());
41- self ::assertEquals ('github ' , $ returnValue ->getType ());
42- self ::assertEquals ('block8/phpci ' , $ returnValue ->getReference ());
43- self ::assertEquals ('master ' , $ returnValue ->getBranch ());
202+ self ::assertEquals ($ accessInformation , $ project ->getAccessInformation ());
44203 }
45204
46- public function testExecute_CreateProjectWithOptions ()
205+ public function testExecuteCreateProjectWithOptions ()
47206 {
48207 $ options = [
49208 'ssh_private_key ' => 'private ' ,
@@ -53,7 +212,13 @@ public function testExecute_CreateProjectWithOptions()
53212 'branch ' => 'testbranch ' ,
54213 ];
55214
56- $ returnValue = $ this ->testedService ->createProject ('Test Project ' , 'github ' , 'block8/phpci ' , 0 , $ options );
215+ $ returnValue = $ this ->testedService ->createProject (
216+ 'Test Project ' ,
217+ 'github ' ,
218+ 'block8/phpci ' ,
219+ 0 ,
220+ $ options
221+ );
57222
58223 self ::assertEquals ('private ' , $ returnValue ->getSshPrivateKey ());
59224 self ::assertEquals ('public ' , $ returnValue ->getSshPublicKey ());
@@ -62,25 +227,7 @@ public function testExecute_CreateProjectWithOptions()
62227 self ::assertEquals (true , $ returnValue ->getAllowPublicStatus ());
63228 }
64229
65- /**
66- * @link https://github.com/Block8/PHPCI/issues/484
67- */
68- public function testExecute_CreateGitlabProjectWithoutPort ()
69- {
70- $ reference = 'git@gitlab.block8.net:block8/phpci.git ' ;
71- $ returnValue = $ this ->testedService ->createProject (
72- 'Gitlab ' ,
73- Project::TYPE_GITLAB ,
74- $ reference ,
75- 0
76- );
77-
78- self ::assertEquals ('git ' , $ returnValue ->getAccessInformation ('user ' ));
79- self ::assertEquals ('gitlab.block8.net ' , $ returnValue ->getAccessInformation ('domain ' ));
80- self ::assertEquals ('block8/phpci ' , $ returnValue ->getReference ());
81- }
82-
83- public function testExecute_UpdateExistingProject ()
230+ public function testExecuteUpdateExistingProject ()
84231 {
85232 $ project = new Project ();
86233 $ project ->setTitle ('Before Title ' );
@@ -94,7 +241,7 @@ public function testExecute_UpdateExistingProject()
94241 self ::assertEquals ('bitbucket ' , $ returnValue ->getType ());
95242 }
96243
97- public function testExecute_EmptyPublicStatus ()
244+ public function testExecuteEmptyPublicStatus ()
98245 {
99246 $ project = new Project ();
100247 $ project ->setAllowPublicStatus (true );
@@ -110,7 +257,7 @@ public function testExecute_EmptyPublicStatus()
110257 self ::assertEquals (false , $ returnValue ->getAllowPublicStatus ());
111258 }
112259
113- public function testExecute_DeleteProject ()
260+ public function testExecuteDeleteProject ()
114261 {
115262 $ store = $ this ->getMockBuilder ('PHPCensor\Store\ProjectStore ' )->getMock ();
116263 $ store ->expects ($ this ->once ())
0 commit comments