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

AndXFactoryTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 73
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 7
dl 73
loc 73
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testConstruct() 6 6 1
A testCreateReturnsAndxQuery() 11 11 1
A createAndX() 7 7 1
A createRegistry() 23 23 1
A testCreateThrowExceptionIfNotAndXSpecification() 10 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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