|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Github\Tests\Api; |
| 4 | + |
| 5 | +class SearchTest extends TestCase |
| 6 | +{ |
| 7 | + /** |
| 8 | + * @test |
| 9 | + */ |
| 10 | + public function shouldSearchRepositoriesByQuery() |
| 11 | + { |
| 12 | + $expectedArray = array(array('total_count' => '0')); |
| 13 | + |
| 14 | + $api = $this->getApiMock(); |
| 15 | + |
| 16 | + $api->expects($this->once()) |
| 17 | + ->method('get') |
| 18 | + ->with( |
| 19 | + '/search/repositories', |
| 20 | + array('q' => 'query text', 'sort' => 'updated', 'order' => 'desc') |
| 21 | + ) |
| 22 | + ->will($this->returnValue($expectedArray)); |
| 23 | + |
| 24 | + $this->assertEquals($expectedArray, $api->repositories('query text')); |
| 25 | + } |
| 26 | + |
| 27 | + /** |
| 28 | + * @test |
| 29 | + */ |
| 30 | + public function shouldSearchRepositoriesRegardingSortAndOrder() |
| 31 | + { |
| 32 | + $expectedArray = array(array('total_count' => '0')); |
| 33 | + |
| 34 | + $api = $this->getApiMock(); |
| 35 | + |
| 36 | + $api->expects($this->once()) |
| 37 | + ->method('get') |
| 38 | + ->with( |
| 39 | + '/search/repositories', |
| 40 | + array('q' => 'query text', 'sort' => 'created', 'order' => 'asc') |
| 41 | + ) |
| 42 | + ->will($this->returnValue($expectedArray)); |
| 43 | + |
| 44 | + $this->assertEquals( |
| 45 | + $expectedArray, |
| 46 | + $api->repositories('query text', 'created', 'asc') |
| 47 | + ); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * @test |
| 52 | + */ |
| 53 | + public function shouldSearchIssuesByQuery() |
| 54 | + { |
| 55 | + $expectedArray = array(array('total_count' => '0')); |
| 56 | + |
| 57 | + $api = $this->getApiMock(); |
| 58 | + |
| 59 | + $api->expects($this->once()) |
| 60 | + ->method('get') |
| 61 | + ->with( |
| 62 | + '/search/issues', |
| 63 | + array('q' => 'query text', 'sort' => 'updated', 'order' => 'desc') |
| 64 | + ) |
| 65 | + ->will($this->returnValue($expectedArray)); |
| 66 | + |
| 67 | + $this->assertEquals($expectedArray, $api->issues('query text')); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * @test |
| 72 | + */ |
| 73 | + public function shouldSearchIssuesRegardingSortAndOrder() |
| 74 | + { |
| 75 | + $expectedArray = array(array('total_count' => '0')); |
| 76 | + |
| 77 | + $api = $this->getApiMock(); |
| 78 | + |
| 79 | + $api->expects($this->once()) |
| 80 | + ->method('get') |
| 81 | + ->with( |
| 82 | + '/search/issues', |
| 83 | + array('q' => 'query text', 'sort' => 'created', 'order' => 'asc') |
| 84 | + ) |
| 85 | + ->will($this->returnValue($expectedArray)); |
| 86 | + |
| 87 | + $this->assertEquals( |
| 88 | + $expectedArray, |
| 89 | + $api->issues('query text', 'created', 'asc') |
| 90 | + ); |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * @test |
| 95 | + */ |
| 96 | + public function shouldSearchCodeByQuery() |
| 97 | + { |
| 98 | + $expectedArray = array(array('total_count' => '0')); |
| 99 | + |
| 100 | + $api = $this->getApiMock(); |
| 101 | + |
| 102 | + $api->expects($this->once()) |
| 103 | + ->method('get') |
| 104 | + ->with( |
| 105 | + '/search/code', |
| 106 | + array('q' => 'query text', 'sort' => 'updated', 'order' => 'desc') |
| 107 | + ) |
| 108 | + ->will($this->returnValue($expectedArray)); |
| 109 | + |
| 110 | + $this->assertEquals($expectedArray, $api->code('query text')); |
| 111 | + } |
| 112 | + |
| 113 | + /** |
| 114 | + * @test |
| 115 | + */ |
| 116 | + public function shouldSearchCodeRegardingSortAndOrder() |
| 117 | + { |
| 118 | + $expectedArray = array(array('total_count' => '0')); |
| 119 | + |
| 120 | + $api = $this->getApiMock(); |
| 121 | + |
| 122 | + $api->expects($this->once()) |
| 123 | + ->method('get') |
| 124 | + ->with( |
| 125 | + '/search/code', |
| 126 | + array('q' => 'query text', 'sort' => 'created', 'order' => 'asc') |
| 127 | + ) |
| 128 | + ->will($this->returnValue($expectedArray)); |
| 129 | + |
| 130 | + $this->assertEquals( |
| 131 | + $expectedArray, |
| 132 | + $api->code('query text', 'created', 'asc') |
| 133 | + ); |
| 134 | + } |
| 135 | + |
| 136 | + /** |
| 137 | + * @test |
| 138 | + */ |
| 139 | + public function shouldSearchUsersByQuery() |
| 140 | + { |
| 141 | + $expectedArray = array(array('total_count' => '0')); |
| 142 | + |
| 143 | + $api = $this->getApiMock(); |
| 144 | + |
| 145 | + $api->expects($this->once()) |
| 146 | + ->method('get') |
| 147 | + ->with( |
| 148 | + '/search/users', |
| 149 | + array('q' => 'query text', 'sort' => 'updated', 'order' => 'desc') |
| 150 | + ) |
| 151 | + ->will($this->returnValue($expectedArray)); |
| 152 | + |
| 153 | + $this->assertEquals($expectedArray, $api->users('query text')); |
| 154 | + } |
| 155 | + |
| 156 | + /** |
| 157 | + * @test |
| 158 | + */ |
| 159 | + public function shouldSearchUsersRegardingSortAndOrder() |
| 160 | + { |
| 161 | + $expectedArray = array(array('total_count' => '0')); |
| 162 | + |
| 163 | + $api = $this->getApiMock(); |
| 164 | + |
| 165 | + $api->expects($this->once()) |
| 166 | + ->method('get') |
| 167 | + ->with( |
| 168 | + '/search/users', |
| 169 | + array('q' => 'query text', 'sort' => 'created', 'order' => 'asc') |
| 170 | + ) |
| 171 | + ->will($this->returnValue($expectedArray)); |
| 172 | + |
| 173 | + $this->assertEquals( |
| 174 | + $expectedArray, |
| 175 | + $api->users('query text', 'created', 'asc') |
| 176 | + ); |
| 177 | + } |
| 178 | + |
| 179 | + protected function getApiClass() |
| 180 | + { |
| 181 | + return 'Github\Api\Search'; |
| 182 | + } |
| 183 | +} |
0 commit comments