testInitDiscriminatorConditionsSuccess()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 55

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 55
rs 8.9818
c 0
b 0
f 0
cc 1
nc 1
nop 0

How to fix   Long Method   

Long Method

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:

1
<?php
2
3
namespace Mdiyakov\DoctrineSolrBundle\Tests\Query\Select;
4
5
use Mdiyakov\DoctrineSolrBundle\Query\Hydrator\SelectQueryHydrator;
6
use Mdiyakov\DoctrineSolrBundle\Query\Select\MultiClassSelectQuery;
7
use Mdiyakov\DoctrineSolrBundle\Schema\Field\ConfigEntityField;
8
use Mdiyakov\DoctrineSolrBundle\Schema\Schema;
9
10
class MultiClassSelectQueryTest extends \PHPUnit_Framework_TestCase
11
{
12
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],
0 ignored issues
show
Bug introduced by
array($entityConfig1, $entityConfig2) of type array<integer,array<stri...array<string,string>>>> is incompatible with the type array<mixed,string[]> expected by parameter $entityConfigs of Mdiyakov\DoctrineSolrBun...ectQuery::__construct(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

55
            /** @scrutinizer ignore-type */ [$entityConfig1, $entityConfig2],
Loading history...
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
        );
69
    }
70
71
}