HandlerTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
namespace Tests\GBProd\AlgoliaSpecification;
4
5
use GBProd\AlgoliaSpecification\Handler;
6
use GBProd\AlgoliaSpecification\QueryFactory\AndXFactory;
7
use GBProd\AlgoliaSpecification\QueryFactory\Factory;
8
use GBProd\AlgoliaSpecification\QueryFactory\NotFactory;
9
use GBProd\AlgoliaSpecification\QueryFactory\OrXFactory;
10
use GBProd\AlgoliaSpecification\Registry;
11
use GBProd\Specification\AndX;
12
use GBProd\Specification\Not;
13
use GBProd\Specification\OrX;
14
use GBProd\Specification\Specification;
15
use PHPUnit\Framework\TestCase;
16
17
class HandlerTest extends TestCase
18
{
19
    /**
20
     * @var Registry
21
     */
22
    private $registry;
23
24
    /**
25
     * @var Handler
26
     */
27
    private $handler;
28
29
    protected function setUp()
30
    {
31
        $this->registry = new Registry();
32
        $this->handler = new Handler($this->registry);
33
    }
34
35
    public function testConstructWillRegisterBaseFactoriess()
36
    {
37
        $spec1 = $this->createMock(Specification::class);
38
        $spec2 = $this->createMock(Specification::class);
39
40
        $this->assertInstanceOf(
41
            AndXFactory::class,
42
            $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...
43
        );
44
45
        $this->assertInstanceOf(
46
            OrXFactory::class,
47
            $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...
48
        );
49
50
        $this->assertInstanceOf(
51
            NotFactory::class,
52
            $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...
53
        );
54
    }
55
56
    public function testRegisterFactoryAddFactoryInRegistry()
57
    {
58
        $factory = $this->createMock(Factory::class);
59
        $spec = $this->createMock(Specification::class);
60
61
        $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\AlgoliaSpe...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...
62
63
        $this->assertEquals(
64
            $factory,
65
            $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...
66
        );
67
    }
68
69
    public function testHandle()
70
    {
71
        $this->handler = new Handler(new Registry());
72
73
        $factory = $this->prophesize(Factory::class);
74
75
        $spec = $this->createMock(Specification::class);
76
        $this->handler->registerFactory(get_class($spec), $factory->reveal());
77
78
        $factory
79
            ->create($spec)
80
            ->willReturn('query')
81
            ->shouldBeCalled()
82
        ;
83
84
        $this->assertEquals('query', $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...
85
    }
86
}
87