@@ -25,4 +25,102 @@ public function testSetEndpointTrailingSlash()
2525 $ api ->setEndPoint ($ url );
2626 $ this ->assertEquals ($ url , $ api ->getEndpoint ());
2727 }
28+
29+ /**
30+ * Tests that the updateVersion call constructs the correct api call
31+ */
32+ public function testUpdateVersion ()
33+ {
34+ $ params = array (
35+ 'released ' => true ,
36+ 'releaseDate ' => '2010-07-06 ' ,
37+ );
38+
39+ // Stub the api method and keep the rest intact
40+ /** @var Api|\PHPUnit_Framework_MockObject_MockObject $api */
41+ $ api = $ this ->getMockBuilder ('\chobie\Jira\Api ' )->setMethods (array ('api ' ))->disableOriginalConstructor ()->getMock ();
42+ $ api ->expects ($ this ->once ())->method ('api ' )->with (
43+ $ this ->equalTo (Api::REQUEST_PUT ),
44+ $ this ->equalTo ('/rest/api/2/version/111000 ' ),
45+ $ this ->equalTo ($ params )
46+ );
47+
48+ $ api ->updateVersion (111000 , $ params );
49+ }
50+
51+ /**
52+ * Tests that the releaseVersion call constructs the correct api call
53+ */
54+ public function testReleaseVersion ()
55+ {
56+ $ params = array (
57+ 'released ' => true ,
58+ 'releaseDate ' => date ('Y-m-d ' ),
59+ );
60+
61+ // Stub the api method and keep the rest intact
62+ /** @var Api|\PHPUnit_Framework_MockObject_MockObject $api */
63+ $ api = $ this ->getMockBuilder ('\chobie\Jira\Api ' )->setMethods (array ('api ' ))->disableOriginalConstructor ()->getMock ();
64+ $ api ->expects ($ this ->once ())->method ('api ' )->with (
65+ $ this ->equalTo (Api::REQUEST_PUT ),
66+ $ this ->equalTo ('/rest/api/2/version/111000 ' ),
67+ $ this ->equalTo ($ params )
68+ );
69+
70+ $ api ->releaseVersion (111000 );
71+ }
72+
73+ /**
74+ * Tests that the releaseVersion call constructs the correct api call with overriden release data and params
75+ */
76+ public function testReleaseVersionAdvanced ()
77+ {
78+ $ releaseDate = '2010-07-06 ' ;
79+
80+ $ params = array (
81+ 'released ' => true ,
82+ 'releaseDate ' => $ releaseDate ,
83+ 'test ' => 'extra '
84+ );
85+
86+ // Stub the api method and keep the rest intact
87+ /** @var Api|\PHPUnit_Framework_MockObject_MockObject $api */
88+ $ api = $ this ->getMockBuilder ('\chobie\Jira\Api ' )->setMethods (array ('api ' ))->disableOriginalConstructor ()->getMock ();
89+ $ api ->expects ($ this ->once ())->method ('api ' )->with (
90+ $ this ->equalTo (Api::REQUEST_PUT ),
91+ $ this ->equalTo ('/rest/api/2/version/111000 ' ),
92+ $ this ->equalTo ($ params )
93+ );
94+
95+ $ api ->releaseVersion (111000 , $ releaseDate , array ('test ' => 'extra ' ));
96+ }
97+
98+ /**
99+ * Tests FindVersionByName
100+ */
101+ public function testFindVersionByName ()
102+ {
103+ $ name = '3.36.0 ' ;
104+ $ versionId = '14206 ' ;
105+ $ projectKey = 'POR ' ;
106+
107+ $ versions = array (
108+ array ('id ' => '14205 ' , 'name ' => '3.62.0 ' ),
109+ array ('id ' => $ versionId , 'name ' => $ name ),
110+ array ('id ' => '14207 ' , 'name ' => '3.66.0 ' ),
111+ );
112+
113+ // Stub the getVersions method and keep the rest intact
114+ /** @var Api|\PHPUnit_Framework_MockObject_MockObject $api */
115+ $ api = $ this ->getMockBuilder ('\chobie\Jira\Api ' )->setMethods (array ('getVersions ' ))->disableOriginalConstructor ()->getMock ();
116+ $ api ->expects ($ this ->exactly (2 ))->method ('getVersions ' )->with (
117+ $ this ->equalTo ($ projectKey )
118+ )->willReturn ($ versions );
119+
120+ // He should find this one
121+ $ this ->assertEquals (array ('id ' => $ versionId , 'name ' => $ name ), $ api ->findVersionByName ($ projectKey , $ name ));
122+
123+ // And there should be no result for this one
124+ $ this ->assertNull ($ api ->findVersionByName ($ projectKey , 'i_do_not_exist ' ));
125+ }
28126}
0 commit comments