Conditions | 1 |
Paths | 1 |
Total Lines | 61 |
Code Lines | 44 |
Lines | 0 |
Ratio | 0 % |
Changes | 10 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
145 | public function testDoSearch() |
||
146 | { |
||
147 | $index = new CircleCITestIndex(); |
||
148 | |||
149 | $query = new BaseQuery(); |
||
150 | $query->addTerm('Home'); |
||
151 | |||
152 | $result = $index->doSearch($query); |
||
153 | $this->assertInstanceOf(SearchResult::class, $result); |
||
154 | $this->assertEquals(1, $result->getTotalItems()); |
||
155 | |||
156 | $admin = singleton(DefaultAdminService::class)->findOrCreateDefaultAdmin(); |
||
157 | $this->loginAs($admin); |
||
158 | // Result should be the same for now |
||
159 | $result2 = $index->doSearch($query); |
||
160 | $this->assertEquals($result, $result2); |
||
161 | |||
162 | $query->addClass(SiteTree::class); |
||
163 | |||
164 | $result3 = $index->doSearch($query); |
||
165 | $request = new NullHTTPRequest(); |
||
166 | $this->assertInstanceOf(PaginatedList::class, $result3->getPaginatedMatches($request)); |
||
167 | $this->assertEquals($result3->getTotalItems(), $result3->getPaginatedMatches($request)->getTotalItems()); |
||
168 | $this->assertInstanceOf(ArrayData::class, $result3->getFacets()); |
||
169 | $this->assertInstanceOf(CircleCITestIndex::class, $result3->getIndex()); |
||
170 | $this->assertInstanceOf(ArrayList::class, $result3->getSpellcheck()); |
||
171 | $this->assertInstanceOf(Highlighting::class, $result3->getHighlight()); |
||
172 | |||
173 | $this->assertContains(SiteTree::class, $result3->getQuery()->getClasses()); |
||
174 | |||
175 | $index = new CircleCITestIndex(); |
||
176 | $query = new BaseQuery(); |
||
177 | $query->addTerm('Home', ['SiteTree_Title'], 5); |
||
178 | $result4 = $index->doSearch($query); |
||
179 | |||
180 | $this->assertEquals(['SiteTree_Title:Home^5.0'], $index->getBoostTerms()); |
||
181 | $this->assertEquals(['Home'], $index->getQueryTerms()); |
||
182 | $this->assertEquals(1, $result4->getTotalItems()); |
||
183 | |||
184 | $index = new CircleCITestIndex(); |
||
185 | $query = new BaseQuery(); |
||
186 | $query->addTerm('Home', ['SiteTree.Title'], 3); |
||
187 | $result4 = $index->doSearch($query); |
||
188 | |||
189 | $this->assertEquals(['SiteTree_Title:Home^3.0'], $index->getBoostTerms()); |
||
190 | $this->assertEquals(['Home'], $index->getQueryTerms()); |
||
191 | $this->assertEquals(1, $result4->getTotalItems()); |
||
192 | |||
193 | $index = new CircleCITestIndex(); |
||
194 | $query = new BaseQuery(); |
||
195 | $query->addTerm('Home', [], 0, true); |
||
196 | $index->doSearch($query); |
||
197 | |||
198 | $this->assertContains('Home~', $index->getQueryTerms()); |
||
199 | |||
200 | $index = new CircleCITestIndex(); |
||
201 | $query = new BaseQuery(); |
||
202 | $query->addTerm('Home', [], 0, 2); |
||
203 | $index->doSearch($query); |
||
204 | |||
205 | $this->assertContains('Home~2', $index->getQueryTerms()); |
||
206 | } |
||
220 |