Code Duplication    Length = 73-73 lines in 2 locations

tests/AlgoliaSpecification/QueryFactory/AndXFactoryTest.php 1 location

@@ 12-84 (lines=73) @@
9
use GBProd\Specification\Specification;
10
use PHPUnit\Framework\TestCase;
11
12
class AndXFactoryTest extends TestCase
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);
68
        $registry->register(get_class($andx->getSecondPart()), $secondFactory);
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);
83
    }
84
}
85

tests/AlgoliaSpecification/QueryFactory/OrXFactoryTest.php 1 location

@@ 12-84 (lines=73) @@
9
use GBProd\Specification\Specification;
10
use PHPUnit\Framework\TestCase;
11
12
class OrXFactoryTest extends TestCase
13
{
14
    public function testConstruct()
15
    {
16
        $factory = new OrXFactory(new Registry());
17
18
        $this->assertInstanceOf(OrXFactory::class, $factory);
19
    }
20
21
    public function testCreateReturnsAndxQuery()
22
    {
23
        $andx = $this->createOrX();
24
        $registry = $this->createRegistry($andx);
25
26
        $factory = new OrXFactory($registry);
27
28
        $query = $factory->create($andx);
29
30
        $this->assertEquals('(first_part) OR (second_part)', $query);
31
    }
32
33
    /**
34
     * @return OrX
35
     */
36
    private function createOrX()
37
    {
38
        return new OrX(
39
            $this->prophesize(Specification::class)->reveal(),
40
            $this->prophesize(Specification::class)->reveal()
41
        );
42
    }
43
44
    /**
45
     * @param OrX $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);
68
        $registry->register(get_class($andx->getSecondPart()), $secondFactory);
69
70
        return $registry;
71
    }
72
73
74
    public function testCreateThrowExceptionIfNotOrXSpecification()
75
    {
76
        $spec = $this->createMock(Specification::class);
77
        $registry = new Registry();
78
        $factory = new OrXFactory($registry);
79
80
        $this->expectException(\InvalidArgumentException::class);
81
82
        $factory->create($spec);
83
    }
84
}
85