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

NotFactoryTest::createNot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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