HandlerTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
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\Handler;
8
use GBProd\ElasticaSpecification\QueryFactory\AndXFactory;
9
use GBProd\ElasticaSpecification\QueryFactory\Factory;
10
use GBProd\ElasticaSpecification\QueryFactory\NotFactory;
11
use GBProd\ElasticaSpecification\QueryFactory\OrXFactory;
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
use PHPUnit\Framework\TestCase;
18
19
class HandlerTest extends TestCase
20
{
21
    /**
22
     * @var Registry
23
     */
24
    private $registry;
25
26
    /**
27
     * @var QueryBuilder
28
     */
29
    private $qb;
30
31
    /**
32
     * @var Handler
33
     */
34
    private $handler;
35
36
    protected function setUp()
37
    {
38
        $this->registry = new Registry();
39
        $this->qb = new QueryBuilder();
40
        $this->handler = new Handler($this->registry, $this->qb);
41
    }
42
43
    public function testConstructWillRegisterBaseFactoriess()
44
    {
45
        $spec1 = $this->createMock(Specification::class);
46
        $spec2 = $this->createMock(Specification::class);
47
48
        $this->assertInstanceOf(
49
            AndXFactory::class,
50
            $this->registry->getFactory(new AndX($spec1, $spec2))
0 ignored issues
show
Documentation introduced by
$spec1 is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<GBProd\Specification\Specification>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$spec2 is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<GBProd\Specification\Specification>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
51
        );
52
53
        $this->assertInstanceOf(
54
            OrXFactory::class,
55
            $this->registry->getFactory(new OrX($spec1, $spec2))
0 ignored issues
show
Documentation introduced by
$spec1 is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<GBProd\Specification\Specification>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
Documentation introduced by
$spec2 is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<GBProd\Specification\Specification>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
56
        );
57
58
        $this->assertInstanceOf(
59
            NotFactory::class,
60
            $this->registry->getFactory(new Not($spec1))
0 ignored issues
show
Documentation introduced by
$spec1 is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<GBProd\Specification\Specification>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
61
        );
62
    }
63
64
    public function testRegisterFactoryAddFactoryInRegistry()
65
    {
66
        $factory = $this->createMock(Factory::class);
67
        $spec = $this->createMock(Specification::class);
68
69
        $this->handler->registerFactory(get_class($spec), $factory);
0 ignored issues
show
Documentation introduced by
$factory is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<GBProd\ElasticaSp...n\QueryFactory\Factory>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
70
71
        $this->assertEquals(
72
            $factory,
73
            $this->registry->getFactory($spec)
0 ignored issues
show
Documentation introduced by
$spec is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<GBProd\Specification\Specification>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
74
        );
75
    }
76
77
    public function testHandle()
78
    {
79
        $factory = $this->prophesize(Factory::class);
80
81
        $spec = $this->createMock(Specification::class);
82
        $this->handler->registerFactory(get_class($spec), $factory->reveal());
83
84
        $builtQuery = $this->getMockForAbstractClass(AbstractQuery::class);
85
86
        $factory
87
            ->create($spec, $this->qb)
88
            ->willReturn($builtQuery)
89
            ->shouldBeCalled()
90
        ;
91
92
        $this->assertEquals(
93
            $builtQuery,
94
            $this->handler->handle($spec)
0 ignored issues
show
Documentation introduced by
$spec is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<GBProd\Specification\Specification>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
95
        );
96
    }
97
}
98