NotFactoryTest::createRegistry()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 1
1
<?php
2
3
namespace AlgoliaSpecification\QueryFactory;
4
5
use GBProd\AlgoliaSpecification\QueryFactory\Factory;
6
use GBProd\AlgoliaSpecification\QueryFactory\NotFactory;
7
use GBProd\AlgoliaSpecification\Registry;
8
use GBProd\Specification\Not;
9
use GBProd\Specification\OrX;
10
use GBProd\Specification\Specification;
11
use PHPUnit\Framework\TestCase;
12
13
class NotFactoryTest extends TestCase
14
{
15
    public function testConstruct()
16
    {
17
        $factory = new NotFactory(new Registry());
18
19
        $this->assertInstanceOf(NotFactory::class, $factory);
20
    }
21
22
    public function testCreateReturnsNotQuery()
23
    {
24
        $not = $this->createNot();
25
        $registry = $this->createRegistry($not);
26
27
        $factory = new NotFactory($registry);
28
29
        $query = $factory->create($not);
30
31
        $this->assertEquals('NOT query', $query);
32
    }
33
34
    /**
35
     * @return Not
36
     */
37
    private function createNot()
38
    {
39
        return new Not(
40
            $this->createMock(Specification::class)
0 ignored issues
show
Documentation introduced by
$this->createMock(\GBPro...n\Specification::class) 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...
41
        );
42
    }
43
44
    /**
45
     * @param Not $not
46
     *
47
     * @return Registry
48
     */
49
    private function createRegistry($not)
50
    {
51
        $factory = $this->createMock(Factory::class);
52
        $factory
53
            ->expects($this->any())
54
            ->method('create')
55
            ->willReturn('query')
56
        ;
57
58
        $registry = new Registry();
59
60
        $registry->register(get_class($not->getWrappedSpecification()), $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...
61
62
        return $registry;
63
    }
64
65
    public function testCreateThrowExceptionIfNotNotSpecification()
66
    {
67
        $spec = $this->createMock(Specification::class);
68
        $registry = new Registry();
69
        $factory = new NotFactory($registry);
70
71
        $this->expectException(\InvalidArgumentException::class);
72
73
        $factory->create($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
    public function testCreateThrowExceptionIfWrappedSpecificationIsAGroup()
77
    {
78
        $spec = new Not(
79
            new OrX(
80
                $this->createMock(Specification::class),
0 ignored issues
show
Documentation introduced by
$this->createMock(\GBPro...n\Specification::class) 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...
81
                $this->createMock(Specification::class)
0 ignored issues
show
Documentation introduced by
$this->createMock(\GBPro...n\Specification::class) 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...
82
            )
83
        );
84
85
        $registry = new Registry();
86
        $factory = new NotFactory($registry);
87
88
        $this->expectException(\InvalidArgumentException::class);
89
90
        $factory->create($spec);
91
    }
92
}
93