SelectorFactoryInterfaceTestCase   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 104
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Importance

Changes 0
Metric Value
wmc 4
lcom 2
cbo 2
dl 0
loc 104
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testClass() 0 7 1
A testAddNamespace() 0 21 1
B testAddSelector() 0 46 1
A testCreate() 0 12 1
1
<?php
2
/**
3
 * This file is part of the Cubiche package.
4
 *
5
 * Copyright (c) Cubiche
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace Cubiche\Core\Selector\Tests\Units;
11
12
use Cubiche\Core\Selector\Key;
13
use Cubiche\Core\Selector\Property;
14
use Cubiche\Core\Selector\SelectorFactory;
15
use Cubiche\Core\Selector\SelectorFactoryInterface;
16
use Cubiche\Tests\TestCase;
17
18
/**
19
 * Selector Factory Interface Test Case Class.
20
 *
21
 * @author Karel Osorio Ramírez <[email protected]>
22
 */
23
abstract class SelectorFactoryInterfaceTestCase extends TestCase
24
{
25
    /**
26
     * Test class.
27
     */
28
    public function testClass()
29
    {
30
        $this
31
            ->testedClass
32
                ->implements(SelectorFactoryInterface::class)
33
        ;
34
    }
35
36
    /**
37
     * Test addNamespace.
38
     */
39
    public function testAddNamespace()
40
    {
41
        $this
42
            /* @var \Cubiche\Core\Selector\SelectorFactoryInterface $factory */
43
            ->given($factory = $this->newDefaultTestedInstance())
44
            ->when($factory->addNamespace('Cubiche\Core\Selector'))
45
            ->then()
46
                /* @var \Cubiche\Core\Selector\Key $key */
47
                ->object($key = $factory->create('key', array('foo')))
48
                    ->isInstanceOf(Key::class)
49
                ->string($key->name())
50
                    ->isEqualto('foo')
51
        ;
52
53
        $this
54
            ->exception(function () use ($factory) {
55
                $factory->addNamespace(null);
56
            })
57
            ->isInstanceOf(\InvalidArgumentException::class)
58
        ;
59
    }
60
61
    /**
62
     * Test addSelector.
63
     */
64
    public function testAddSelector()
65
    {
66
        $this
67
            /* @var \Cubiche\Core\Selector\SelectorFactoryInterface $factory */
68
            ->given($factory = $this->newDefaultTestedInstance())
69
            ->when($factory->addSelector(Key::class))
70
            ->then()
71
                /* @var \Cubiche\Core\Selector\Key $key */
72
                ->object($key = $factory->create('key', array('foo')))
73
                    ->isInstanceOf(Key::class)
74
                ->string($key->name())
75
                    ->isEqualto('foo')
76
        ;
77
78
        $this
79
            ->given($factory)
80
            ->when($factory->addSelector(Property::class, 'attribute'))
81
            ->then()
82
                /* @var \Cubiche\Core\Selector\Property $key */
83
                ->object($property = $factory->create('attribute', array('foo')))
84
                    ->isInstanceOf(Property::class)
85
                ->string($property->name())
86
                    ->isEqualto('foo')
87
        ;
88
89
        $this
90
            ->exception(function () use ($factory) {
91
                $factory->addSelector(Key::class);
92
            })
93
            ->isInstanceOf(\InvalidArgumentException::class)
94
        ;
95
96
        $this
97
            ->exception(function () use ($factory) {
98
                $factory->addSelector('foo');
99
            })
100
            ->isInstanceOf(\InvalidArgumentException::class)
101
        ;
102
103
        $this
104
            ->exception(function () use ($factory) {
105
                $factory->addSelector(SelectorFactory::class);
106
            })
107
            ->isInstanceOf(\InvalidArgumentException::class)
108
        ;
109
    }
110
111
    /**
112
     * Test create.
113
     */
114
    public function testCreate()
115
    {
116
        $this
117
            /* @var \Cubiche\Core\Selector\SelectorFactoryInterface $factory */
118
            ->given($factory = $this->newDefaultTestedInstance())
119
            ->exception(function () use ($factory) {
120
                $factory->addNamespace('foo');
121
                $factory->create('count');
122
            })
123
            ->isInstanceOf(\InvalidArgumentException::class)
124
        ;
125
    }
126
}
127