Conditions | 1 |
Paths | 1 |
Total Lines | 55 |
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 |
||
13 | public function testInitDiscriminatorConditionsSuccess() |
||
14 | { |
||
15 | $configFieldName = 'type'; |
||
16 | $documentFieldName = 'd_type'; |
||
17 | $configFieldValue1 = 'article'; |
||
18 | $configFieldValue2 = 'news'; |
||
19 | $entityConfig1 = [ |
||
20 | 'config' => [ |
||
21 | [ 'name' => $configFieldName, 'value' => $configFieldValue1 ] |
||
22 | ] |
||
23 | ]; |
||
24 | |||
25 | $entityConfig2 = [ |
||
26 | 'config' => [ |
||
27 | [ 'name' => $configFieldName, 'value' => $configFieldValue2 ] |
||
28 | ] |
||
29 | ]; |
||
30 | |||
31 | /** @var \Solarium\Client|\PHPUnit_Framework_MockObject_MockObject $client */ |
||
32 | $client = $this->getMockBuilder('Solarium\Client')->disableOriginalConstructor()->getMock(); |
||
33 | $client->expects($this->at(0))->method('createSelect') |
||
34 | ->will($this->returnValue( |
||
35 | $this->getMockBuilder('Solarium\QueryType\Select\Query\Query')->disableOriginalConstructor()->getMock() |
||
36 | )); |
||
37 | |||
38 | |||
39 | /** @var Schema|\PHPUnit_Framework_MockObject_MockObject $schema */ |
||
40 | $schema = $this->getMockBuilder('Mdiyakov\DoctrineSolrBundle\Schema\Schema')->disableOriginalConstructor()->getMock(); |
||
41 | $discriminatorField = new ConfigEntityField($configFieldName, $documentFieldName, true, 10); |
||
42 | $primaryKeyField = $this->getMockBuilder('Mdiyakov\DoctrineSolrBundle\Schema\Field\Entity\Field')->disableOriginalConstructor()->getMock(); |
||
43 | |||
44 | $schema->expects($this->any())->method('getDiscriminatorConfigField') |
||
45 | ->will($this->returnValue($discriminatorField)); |
||
46 | |||
47 | $schema->expects($this->any())->method('getEntityPrimaryKeyField') |
||
48 | ->will($this->returnValue($primaryKeyField)); |
||
49 | |||
50 | /** @var SelectQueryHydrator|\PHPUnit_Framework_MockObject_MockObject $hydrator */ |
||
51 | $hydrator = $this->getMockBuilder('Mdiyakov\DoctrineSolrBundle\Query\Hydrator\SelectQueryHydrator')->disableOriginalConstructor()->getMock(); |
||
52 | $query = new MultiClassSelectQuery( |
||
53 | $schema, |
||
54 | $client, |
||
55 | [$entityConfig1, $entityConfig2], |
||
|
|||
56 | [$hydrator] |
||
57 | ); |
||
58 | |||
59 | $this->assertEquals( |
||
60 | sprintf( |
||
61 | '%s:"%s" OR %s:"%s"', |
||
62 | $documentFieldName, |
||
63 | $configFieldValue1, |
||
64 | $documentFieldName, |
||
65 | $configFieldValue2 |
||
66 | ), |
||
67 | $query->getQueryString() |
||
68 | ); |
||
71 | } |