|
| 1 | +<?php namespace Gitlab\Tests\Api; |
| 2 | + |
| 3 | +use Gitlab\Api\AbstractApi; |
| 4 | + |
| 5 | +class IssuesTest extends TestCase |
| 6 | +{ |
| 7 | + /** |
| 8 | + * @test |
| 9 | + */ |
| 10 | + public function shouldGetAllIssues() |
| 11 | + { |
| 12 | + $expectedArray = array( |
| 13 | + array('id' => 1, 'title' => 'An issue'), |
| 14 | + array('id' => 2, 'title' => 'Another issue'), |
| 15 | + ); |
| 16 | + |
| 17 | + $api = $this->getApiMock(); |
| 18 | + $api->expects($this->once()) |
| 19 | + ->method('get') |
| 20 | + ->with('issues', array('page' => 1, 'per_page' => AbstractApi::PER_PAGE)) |
| 21 | + ->will($this->returnValue($expectedArray)) |
| 22 | + ; |
| 23 | + |
| 24 | + $this->assertEquals($expectedArray, $api->all()); |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * @test |
| 29 | + */ |
| 30 | + public function shouldGetProjectIssuesWithPagination() |
| 31 | + { |
| 32 | + $expectedArray = array( |
| 33 | + array('id' => 1, 'title' => 'An issue'), |
| 34 | + array('id' => 2, 'title' => 'Another issue'), |
| 35 | + ); |
| 36 | + |
| 37 | + $api = $this->getApiMock(); |
| 38 | + $api->expects($this->once()) |
| 39 | + ->method('get') |
| 40 | + ->with('projects/1/issues', array('page' => 2, 'per_page' => 5)) |
| 41 | + ->will($this->returnValue($expectedArray)) |
| 42 | + ; |
| 43 | + |
| 44 | + $this->assertEquals($expectedArray, $api->all(1, 2, 5)); |
| 45 | + } |
| 46 | + |
| 47 | + /** |
| 48 | + * @test |
| 49 | + */ |
| 50 | + public function shouldGetProjectIssuesWithParams() |
| 51 | + { |
| 52 | + $expectedArray = array( |
| 53 | + array('id' => 1, 'title' => 'An issue'), |
| 54 | + array('id' => 2, 'title' => 'Another issue'), |
| 55 | + ); |
| 56 | + |
| 57 | + $api = $this->getApiMock(); |
| 58 | + $api->expects($this->once()) |
| 59 | + ->method('get') |
| 60 | + ->with('projects/1/issues', array('page' => 2, 'per_page' => 5, 'order_by' => 'created_at', 'sort' => 'desc', 'labels' => 'foo,bar', 'state' => 'open')) |
| 61 | + ->will($this->returnValue($expectedArray)) |
| 62 | + ; |
| 63 | + |
| 64 | + $this->assertEquals($expectedArray, $api->all(1, 2, 5, array('order_by' => 'created_at', 'sort' => 'desc', 'labels' => 'foo,bar', 'state' => 'open'))); |
| 65 | + } |
| 66 | + |
| 67 | + /** |
| 68 | + * @test |
| 69 | + */ |
| 70 | + public function shouldShowIssue() |
| 71 | + { |
| 72 | + $expectedArray = array('id' => 2, 'title' => 'Another issue'); |
| 73 | + |
| 74 | + $api = $this->getApiMock(); |
| 75 | + $api->expects($this->once()) |
| 76 | + ->method('get') |
| 77 | + ->with('projects/1/issues/2') |
| 78 | + ->will($this->returnValue($expectedArray)) |
| 79 | + ; |
| 80 | + |
| 81 | + $this->assertEquals($expectedArray, $api->show(1, 2)); |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * @test |
| 86 | + */ |
| 87 | + public function shouldCreateIssue() |
| 88 | + { |
| 89 | + $expectedArray = array('id' => 3, 'title' => 'A new issue'); |
| 90 | + |
| 91 | + $api = $this->getApiMock(); |
| 92 | + $api->expects($this->once()) |
| 93 | + ->method('post') |
| 94 | + ->with('projects/1/issues', array('title' => 'A new issue', 'labels' => 'foo,bar')) |
| 95 | + ->will($this->returnValue($expectedArray)) |
| 96 | + ; |
| 97 | + |
| 98 | + $this->assertEquals($expectedArray, $api->create(1, array('title' => 'A new issue', 'labels' => 'foo,bar'))); |
| 99 | + } |
| 100 | + |
| 101 | + /** |
| 102 | + * @test |
| 103 | + */ |
| 104 | + public function shouldUpdateIssue() |
| 105 | + { |
| 106 | + $expectedArray = array('id' => 2, 'title' => 'A renamed issue'); |
| 107 | + |
| 108 | + $api = $this->getApiMock(); |
| 109 | + $api->expects($this->once()) |
| 110 | + ->method('put') |
| 111 | + ->with('projects/1/issues/2', array('title' => 'A renamed issue', 'labels' => 'foo')) |
| 112 | + ->will($this->returnValue($expectedArray)) |
| 113 | + ; |
| 114 | + |
| 115 | + $this->assertEquals($expectedArray, $api->update(1, 2, array('title' => 'A renamed issue', 'labels' => 'foo'))); |
| 116 | + } |
| 117 | + |
| 118 | + /** |
| 119 | + * @test |
| 120 | + */ |
| 121 | + public function shouldGetIssueComments() |
| 122 | + { |
| 123 | + $expectedArray = array( |
| 124 | + array('id' => 1, 'body' => 'A comment'), |
| 125 | + array('id' => 2, 'body' => 'Another comment') |
| 126 | + ); |
| 127 | + |
| 128 | + $api = $this->getApiMock(); |
| 129 | + $api->expects($this->once()) |
| 130 | + ->method('get') |
| 131 | + ->with('projects/1/issues/2/notes') |
| 132 | + ->will($this->returnValue($expectedArray)) |
| 133 | + ; |
| 134 | + |
| 135 | + $this->assertEquals($expectedArray, $api->showComments(1, 2)); |
| 136 | + } |
| 137 | + |
| 138 | + /** |
| 139 | + * @test |
| 140 | + */ |
| 141 | + public function shouldGetIssueComment() |
| 142 | + { |
| 143 | + $expectedArray = array('id' => 3, 'body' => 'A new comment'); |
| 144 | + |
| 145 | + $api = $this->getApiMock(); |
| 146 | + $api->expects($this->once()) |
| 147 | + ->method('get') |
| 148 | + ->with('projects/1/issues/2/notes/3') |
| 149 | + ->will($this->returnValue($expectedArray)) |
| 150 | + ; |
| 151 | + |
| 152 | + $this->assertEquals($expectedArray, $api->showComment(1, 2, 3)); |
| 153 | + } |
| 154 | + |
| 155 | + /** |
| 156 | + * @test |
| 157 | + */ |
| 158 | + public function shouldCreateComment() |
| 159 | + { |
| 160 | + $expectedArray = array('id' => 3, 'body' => 'A new comment'); |
| 161 | + |
| 162 | + $api = $this->getApiMock(); |
| 163 | + $api->expects($this->exactly(2)) |
| 164 | + ->method('post') |
| 165 | + ->with('projects/1/issues/2/notes', array('body' => 'A new comment')) |
| 166 | + ->will($this->returnValue($expectedArray)) |
| 167 | + ; |
| 168 | + |
| 169 | + $this->assertEquals($expectedArray, $api->addComment(1, 2, array('body' => 'A new comment'))); |
| 170 | + $this->assertEquals($expectedArray, $api->addComment(1, 2, 'A new comment')); |
| 171 | + } |
| 172 | + |
| 173 | + /** |
| 174 | + * @test |
| 175 | + */ |
| 176 | + public function shouldUpdateComment() |
| 177 | + { |
| 178 | + $expectedArray = array('id' => 3, 'body' => 'An edited comment'); |
| 179 | + |
| 180 | + $api = $this->getApiMock(); |
| 181 | + $api->expects($this->once()) |
| 182 | + ->method('put') |
| 183 | + ->with('projects/1/issues/2/notes/3', array('body' => 'An edited comment')) |
| 184 | + ->will($this->returnValue($expectedArray)) |
| 185 | + ; |
| 186 | + |
| 187 | + $this->assertEquals($expectedArray, $api->updateComment(1, 2, 3, 'An edited comment')); |
| 188 | + } |
| 189 | + |
| 190 | + protected function getApiClass() |
| 191 | + { |
| 192 | + return 'Gitlab\Api\Issues'; |
| 193 | + } |
| 194 | +} |
0 commit comments