AndXFactoryTest::createRegistry()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 15

Duplication

Lines 23
Ratio 100 %

Importance

Changes 0
Metric Value
dl 23
loc 23
rs 9.0856
c 0
b 0
f 0
cc 1
eloc 15
nc 1
nop 1
1
<?php
2
3
namespace Tests\GBProd\AlgoliaSpecification;
4
5
use GBProd\AlgoliaSpecification\QueryFactory\AndXFactory;
6
use GBProd\AlgoliaSpecification\QueryFactory\Factory;
7
use GBProd\AlgoliaSpecification\Registry;
8
use GBProd\Specification\AndX;
9
use GBProd\Specification\Specification;
10
use PHPUnit\Framework\TestCase;
11
12 View Code Duplication
class AndXFactoryTest extends TestCase
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
13
{
14
    public function testConstruct()
15
    {
16
        $factory = new AndXFactory(new Registry());
17
18
        $this->assertInstanceOf(AndXFactory::class, $factory);
19
    }
20
21
    public function testCreateReturnsAndxQuery()
22
    {
23
        $andx = $this->createAndX();
24
        $registry = $this->createRegistry($andx);
25
26
        $factory = new AndXFactory($registry);
27
28
        $query = $factory->create($andx);
29
30
        $this->assertEquals('(first_part) AND (second_part)', $query);
31
    }
32
33
    /**
34
     * @return AndX
35
     */
36
    private function createAndX()
37
    {
38
        return new AndX(
39
            $this->prophesize(Specification::class)->reveal(),
40
            $this->prophesize(Specification::class)->reveal()
41
        );
42
    }
43
44
    /**
45
     * @param AndX $andx
46
     *
47
     * @return Registry
48
     */
49
    private function createRegistry($andx)
50
    {
51
        $firstFactory = $this->createMock(Factory::class);
52
        $firstFactory
53
            ->expects($this->any())
54
            ->method('create')
55
            ->willReturn('first_part')
56
        ;
57
58
        $secondFactory = $this->createMock(Factory::class);
59
        $secondFactory
60
            ->expects($this->any())
61
            ->method('create')
62
            ->willReturn('second_part')
63
        ;
64
65
        $registry = new Registry();
66
67
        $registry->register(get_class($andx->getFirstPart()), $firstFactory);
0 ignored issues
show
Documentation introduced by
$firstFactory 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...
68
        $registry->register(get_class($andx->getSecondPart()), $secondFactory);
0 ignored issues
show
Documentation introduced by
$secondFactory 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...
69
70
        return $registry;
71
    }
72
73
74
    public function testCreateThrowExceptionIfNotAndXSpecification()
75
    {
76
        $spec = $this->createMock(Specification::class);
77
        $registry = new Registry();
78
        $factory = new AndXFactory($registry);
79
80
        $this->expectException(\InvalidArgumentException::class);
81
82
        $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...
83
    }
84
}
85