Conditions | 1 |
Paths | 1 |
Total Lines | 62 |
Code Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Changes | 18 | ||
Bugs | 1 | 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 |
||
139 | public function testDoSearch() |
||
140 | { |
||
141 | $index = new CircleCITestIndex(); |
||
142 | |||
143 | $query = new BaseQuery(); |
||
144 | $query->addTerm('Home'); |
||
145 | |||
146 | $result = $index->doSearch($query); |
||
147 | $this->assertInstanceOf(SearchResult::class, $result); |
||
148 | $this->assertEquals(1, $result->getTotalItems()); |
||
149 | |||
150 | $admin = singleton(DefaultAdminService::class)->findOrCreateDefaultAdmin(); |
||
151 | $this->loginAs($admin); |
||
152 | // Result should be the same for now |
||
153 | $result2 = $index->doSearch($query); |
||
154 | $this->assertEquals($result, $result2); |
||
155 | |||
156 | $query->addClass(SiteTree::class); |
||
157 | |||
158 | $result3 = $index->doSearch($query); |
||
159 | $request = new NullHTTPRequest(); |
||
160 | $this->assertInstanceOf(PaginatedList::class, $result3->getPaginatedMatches($request)); |
||
161 | $this->assertEquals($result3->getTotalItems(), $result3->getPaginatedMatches($request)->getTotalItems()); |
||
162 | $this->assertInstanceOf(ArrayData::class, $result3->getFacets()); |
||
163 | $this->assertInstanceOf(ArrayList::class, $result3->getSpellcheck()); |
||
164 | $this->assertInstanceOf(Highlighting::class, $result3->getHighlight()); |
||
165 | |||
166 | $result3->setCustomisedMatches([]); |
||
167 | $this->assertInstanceOf(ArrayList::class, $result3->getMatches()); |
||
168 | $this->assertCount(0, $result3->getMatches()); |
||
169 | |||
170 | $index = new CircleCITestIndex(); |
||
171 | $query = new BaseQuery(); |
||
172 | $query->addTerm('Home', ['SiteTree_Title'], 5); |
||
173 | $result4 = $index->doSearch($query); |
||
174 | |||
175 | $this->assertContains('SiteTree_Title:Home^5.0', $index->getQueryFactory()->getBoostTerms()); |
||
176 | $this->assertContains('Home', $index->getQueryTerms()); |
||
177 | $this->assertEquals(1, $result4->getTotalItems()); |
||
178 | |||
179 | $index = new CircleCITestIndex(); |
||
180 | $query = new BaseQuery(); |
||
181 | $query->addTerm('Home', ['SiteTree.Title'], 3); |
||
182 | $result4 = $index->doSearch($query); |
||
183 | |||
184 | $this->assertContains('SiteTree_Title:Home^3.0', $index->getQueryFactory()->getBoostTerms()); |
||
185 | $this->assertContains('Home', $index->getQueryTerms()); |
||
186 | $this->assertEquals(1, $result4->getTotalItems()); |
||
187 | |||
188 | $index = new CircleCITestIndex(); |
||
189 | $query = new BaseQuery(); |
||
190 | $query->addTerm('Home', [], 0, true); |
||
191 | $index->doSearch($query); |
||
192 | |||
193 | $this->assertContains('Home~', $index->getQueryTerms()); |
||
194 | |||
195 | $index = new CircleCITestIndex(); |
||
196 | $query = new BaseQuery(); |
||
197 | $query->addTerm('Home', [], 0, 2); |
||
198 | $index->doSearch($query); |
||
199 | |||
200 | $this->assertContains('Home~2', $index->getQueryTerms()); |
||
201 | } |
||
238 |