Completed
Push — master ( a017c2...285708 )
by GBProd
02:17
created

AndXFactoryTest::createRegistry()   A

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