Conditions | 1 |
Paths | 1 |
Total Lines | 53 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
46 | public function testGetTermsForSingleTermWithDefinitionOnNonCachedResult() { |
||
47 | |||
48 | $page = DIWikiPage::newFromTitle( Title::newFromText( __METHOD__ ) ); |
||
49 | |||
50 | $queryResult = $this->getMockBuilder( '\stdClass' ) |
||
51 | ->disableOriginalConstructor() |
||
52 | ->setMethods( array( 'getResults' ) ) |
||
53 | ->getMock(); |
||
54 | |||
55 | $queryResult->expects( $this->once() ) |
||
56 | ->method( 'getResults' ) |
||
57 | ->will( $this->returnValue( array( $page ) ) ); |
||
58 | |||
59 | $store = $this->getMockBuilder( 'SMWStore' ) |
||
60 | ->disableOriginalConstructor() |
||
61 | ->getMockForAbstractClass(); |
||
62 | |||
63 | $store->expects( $this->once() ) |
||
64 | ->method( 'getQueryResult' ) |
||
65 | ->will( $this->returnValue( $queryResult ) ); |
||
66 | |||
67 | // at() position depends on the sequence as to when a method is called |
||
68 | |||
69 | $store->expects( $this->at( 1 ) ) |
||
70 | ->method( 'getPropertyValues' ) |
||
71 | ->will( $this->returnValue( array( new DIBlob( ' Foo term ' ) ) ) ); |
||
72 | |||
73 | $store->expects( $this->at( 2 ) ) |
||
74 | ->method( 'getPropertyValues' ) |
||
75 | ->will( $this->returnValue( array( new DIBlob( ' some Definition ' ) ) ) ); |
||
76 | |||
77 | $glossaryCache = new GlossaryCache( new HashBagOStuff() ); |
||
78 | |||
79 | $instance = new ElementsCacheBuilder( |
||
80 | $store, |
||
81 | $glossaryCache |
||
82 | ); |
||
83 | |||
84 | $results = $instance->getElements(); |
||
85 | |||
86 | $this->assertEquals( |
||
87 | $results, |
||
88 | $glossaryCache->getCache()->get( $glossaryCache->getKeyForSubject( $page ) ) |
||
89 | ); |
||
90 | |||
91 | $this->assertLingoElement( |
||
92 | 'Foo term', |
||
93 | 'some Definition', |
||
94 | null, |
||
95 | null, |
||
96 | $results[0] |
||
97 | ); |
||
98 | } |
||
99 | |||
114 |