Failed Conditions
Pull Request — master (#6)
by GBProd
02:28
created

HandlerTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Tests\GBProd\ElasticaSpecification;
4
5
use Elastica\QueryBuilder;
6
use Elastica\Query\AbstractQuery;
7
use GBProd\ElasticaSpecification\ExpressionBuilder\AndXBuilder;
8
use GBProd\ElasticaSpecification\ExpressionBuilder\Builder;
9
use GBProd\ElasticaSpecification\ExpressionBuilder\NotBuilder;
10
use GBProd\ElasticaSpecification\ExpressionBuilder\OrXBuilder;
11
use GBProd\ElasticaSpecification\Handler;
12
use GBProd\ElasticaSpecification\Registry;
13
use GBProd\Specification\AndX;
14
use GBProd\Specification\Not;
15
use GBProd\Specification\OrX;
16
use GBProd\Specification\Specification;
17
18
class HandlerTest extends \PHPUnit_Framework_TestCase
19
{
20
    /**
21
     * @var Registry
22
     */
23
    private $registry;
24
25
    /**
26
     * @var Handler
27
     */
28
    private $handler;
29
30
    protected function setUp()
31
    {
32
        $this->registry = new Registry();
33
        $this->handler = new Handler($this->registry);
34
    }
35
36
    public function testConstructWillRegisterBaseBuilders()
37
    {
38
        $spec1 = $this->createMock(Specification::class);
39
        $spec2 = $this->createMock(Specification::class);
40
41
        $this->assertInstanceOf(
42
            AndXBuilder::class,
43
            $this->registry->getBuilder(new AndX($spec1, $spec2))
44
        );
45
46
        $this->assertInstanceOf(
47
            OrXBuilder::class,
48
            $this->registry->getBuilder(new OrX($spec1, $spec2))
49
        );
50
51
        $this->assertInstanceOf(
52
            NotBuilder::class,
53
            $this->registry->getBuilder(new Not($spec1))
54
        );
55
    }
56
57
    public function testRegisterBuilderAddBuilderInRegistry()
58
    {
59
        $builder = $this->createMock(Builder::class);
60
        $spec = $this->createMock(Specification::class);
61
62
        $this->handler->registerBuilder(get_class($spec), $builder);
63
64
        $this->assertEquals(
65
            $builder,
66
            $this->registry->getBuilder($spec)
67
        );
68
    }
69
70
    public function testHandle()
71
    {
72
        $this->handler = new Handler(new Registry());
73
74
        $builder = $this->prophesize(Builder::class);
75
76
        $spec = $this->createMock(Specification::class);
77
        $this->handler->registerBuilder(get_class($spec), $builder->reveal());
78
79
        $builtQuery = $this->getMockForAbstractClass(AbstractQuery::class);
80
        $qb = new QueryBuilder();
81
82
        $builder
83
            ->build($spec, $qb)
84
            ->willReturn($builtQuery)
85
            // ->shouldBeCalled()
86
        ;
87
88
            $this->handler->handle($spec, $qb);
89
        // $this->assertEquals(
90
        //     $builtQuery,
91
        // );
92
    }
93
94
    // private function createQueryWithResult($result)
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
95
    // {
96
    //     $query = $this
97
    //         ->getMockBuilder(AbstractQuery::class)
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
98
    //         ->disableOriginalConstructor()
99
    //         ->getMock()
100
    //     ;
101
102
    //     $query
103
    //         ->expects($this->once())
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
104
    //         ->method('getResult')
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
105
    //         ->willReturn($result)
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
106
    //     ;
107
108
    //     return $query;
109
    // }
110
111
    // private function createQueryBuilderBuildingQuery($query, $buildedExpr, $spec)
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
112
    // {
113
    //     $qb = $this
114
    //         ->getMockBuilder(QueryBuilder::class)
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
115
    //         ->disableOriginalConstructor()
116
    //         ->getMock()
117
    //     ;
118
119
    //     $qb
120
    //         ->expects($this->at(0))
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
121
    //         ->method('where')
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
122
    //         ->with($buildedExpr)
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
123
    //     ;
124
125
    //     $qb
126
    //         ->expects($this->at(1))
0 ignored issues
show
Unused Code Comprehensibility introduced by
73% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
127
    //         ->method('getQuery')
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
128
    //         ->willReturn($query)
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
129
    //     ;
130
131
    //     return $qb;
132
    // }
133
}
134