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

HandlerTest::testHandle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 10
nc 1
nop 0
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\QueryFactory\NotFactory;
8
use GBProd\AlgoliaSpecification\QueryFactory\OrXFactory;
9
use GBProd\AlgoliaSpecification\Handler;
10
use GBProd\AlgoliaSpecification\Registry;
11
use GBProd\Specification\AndX;
12
use GBProd\Specification\Not;
13
use GBProd\Specification\OrX;
14
use GBProd\Specification\Specification;
15
16
class HandlerTest extends \PHPUnit_Framework_TestCase
17
{
18
    /**
19
     * @var Registry
20
     */
21
    private $registry;
22
23
    /**
24
     * @var Handler
25
     */
26
    private $handler;
27
28
    protected function setUp()
29
    {
30
        $this->registry = new Registry();
31
        $this->handler = new Handler($this->registry);
32
    }
33
34
    public function testConstructWillRegisterBaseFactoriess()
35
    {
36
        $spec1 = $this->createMock(Specification::class);
37
        $spec2 = $this->createMock(Specification::class);
38
39
        $this->assertInstanceOf(
40
            AndXFactory::class,
41
            $this->registry->getFactory(new AndX($spec1, $spec2))
42
        );
43
44
        $this->assertInstanceOf(
45
            OrXFactory::class,
46
            $this->registry->getFactory(new OrX($spec1, $spec2))
47
        );
48
49
        $this->assertInstanceOf(
50
            NotFactory::class,
51
            $this->registry->getFactory(new Not($spec1))
52
        );
53
    }
54
55
    public function testRegisterFactoryAddFactoryInRegistry()
56
    {
57
        $factory = $this->createMock(Factory::class);
58
        $spec = $this->createMock(Specification::class);
59
60
        $this->handler->registerFactory(get_class($spec), $factory);
61
62
        $this->assertEquals(
63
            $factory,
64
            $this->registry->getFactory($spec)
65
        );
66
    }
67
68
    public function testHandle()
69
    {
70
        $this->handler = new Handler(new Registry());
71
72
        $factory = $this->prophesize(Factory::class);
73
74
        $spec = $this->createMock(Specification::class);
75
        $this->handler->registerFactory(get_class($spec), $factory->reveal());
76
77
        $factory
78
            ->create($spec)
79
            ->willReturn('query')
80
            ->shouldBeCalled()
81
        ;
82
83
        $this->assertEquals('query', $this->handler->handle($spec));
84
    }
85
}
86