| Conditions | 1 |
| Paths | 1 |
| Total Lines | 52 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 35 |
| CRAP Score | 1 |
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 |
||
| 18 | 1 | public function testSearchableAndAutocompleteInherited() { |
|
| 19 | 1 | $page = $this->objFromFixture('SearchableTestPage', 'first'); |
|
| 20 | 1 | $this->assertTrue($page->hasExtension('SilverStripe\Elastica\Searchable'), |
|
| 21 | 1 | 'Page extending SiteTree has Searchable extension'); |
|
| 22 | |||
| 23 | 1 | $fields = $page->getElasticaFields(); |
|
| 24 | 1 | $terms = $page->getTermVectors(); |
|
| 25 | |||
| 26 | 1 | $expected = array('first'); |
|
| 27 | 1 | $this->assertEquals($expected, array_keys($terms['Title.standard']['terms'])); |
|
| 28 | |||
| 29 | 1 | $expected = array('fi','fir','firs','first','ir','irs','irst','rs','rst','st'); |
|
| 30 | 1 | $this->assertEquals($expected, array_keys($terms['Title.autocomplete']['terms'])); |
|
| 31 | |||
| 32 | // ---- now a parental class page ---- |
||
| 33 | 1 | $this->assertTrue(isset($fields['Title']['fields']['autocomplete'])); |
|
| 34 | |||
| 35 | |||
| 36 | 1 | $page = $this->objFromFixture('SearchableTestFatherPage', 'father0001'); |
|
| 37 | 1 | $this->assertTrue($page->hasExtension('SilverStripe\Elastica\Searchable'), |
|
| 38 | 1 | 'Page extending SiteTree has Searchable extension'); |
|
| 39 | |||
| 40 | 1 | $fields = $page->getElasticaFields(); |
|
| 41 | 1 | $this->assertTrue(isset($fields['Title']['fields']['autocomplete'])); |
|
| 42 | |||
| 43 | 1 | $page = $this->objFromFixture('SearchableTestGrandFatherPage', 'grandfather0001'); |
|
| 44 | 1 | $this->assertTrue($page->hasExtension('SilverStripe\Elastica\Searchable'), |
|
| 45 | 1 | 'Page extending SiteTree has Searchable extension'); |
|
| 46 | |||
| 47 | 1 | $fields = $page->getElasticaFields(); |
|
| 48 | 1 | $this->assertTrue(isset($fields['Title']['fields']['autocomplete'])); |
|
| 49 | |||
| 50 | 1 | $terms = $page->getTermVectors(); |
|
| 51 | |||
| 52 | //Check the expected fields are indexed |
||
| 53 | 1 | $expected = array('Content','Content.shingles','Content.standard','FatherText','FatherText.shingles','FatherText.standard', |
|
| 54 | 1 | 'GrandFatherText','GrandFatherText.shingles','GrandFatherText.standard','Link','Title','Title.autocomplete', |
|
| 55 | 1 | 'Title.shingles','Title.standard'); |
|
| 56 | 1 | $indexedFields = array_keys($terms); |
|
| 57 | 1 | sort($indexedFields); |
|
| 58 | |||
| 59 | 1 | $this->assertEquals($expected, $indexedFields); |
|
| 60 | |||
| 61 | 1 | $fatherTerms = $terms['FatherText.standard']['terms']; |
|
| 62 | 1 | $grandFatherTerms = $terms['GrandFatherText.standard']['terms']; |
|
| 63 | |||
| 64 | 1 | $expected = array('father', 'field', 'grandfather', 'page', 'trace3');; |
|
| 65 | 1 | $this->assertEquals($expected, array_keys($fatherTerms)); |
|
| 66 | |||
| 67 | 1 | $expected = array('grandfather', 'page', 'trace4'); |
|
| 68 | 1 | $this->assertEquals($expected, array_keys($grandFatherTerms)); |
|
| 69 | 1 | } |
|
| 70 | |||
| 72 |