Completed
Push — master ( bc4f39...bfef40 )
by Mantas
03:23
created

KeyBagTest::testGetNamespaces()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 18
rs 9.4286
cc 2
eloc 11
nc 2
nop 0
1
<?php
2
3
/*
4
 * (c) Mantas Varatiejus <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace MVar\Apache2LogParser\Tests;
11
12
use MVar\Apache2LogParser\KeyBag;
13
14
class KeyBagTest extends \PHPUnit_Framework_TestCase
15
{
16
    /**
17
     * Test for add() and get() methods.
18
     *
19
     * @param string $namespace
20
     * @param string $key
21
     *
22
     * @dataProvider getTestAddAndGetData()
23
     */
24
    public function testAddAndGet($namespace, $key)
25
    {
26
        $holder = new KeyBag();
27
        $index = $holder->add($namespace, $key);
28
29
        $this->assertEquals($key, $holder->get($namespace, $index));
30
    }
31
32
    /**
33
     * Test for get() when nothing is set.
34
     */
35
    public function testGetNull()
36
    {
37
        $holder = new KeyBag();
38
39
        $this->assertNull($holder->get('ns', 'test'));
40
    }
41
42
    /**
43
     * Test for getNamespaces().
44
     */
45
    public function testGetNamespaces()
46
    {
47
        $data = [
48
            ['namespace_1', 'key_11'],
49
            ['namespace_2', 'key_21'],
50
        ];
51
52
        $holder = new KeyBag();
53
        $namespaces = [];
54
55
        foreach ($data as $row) {
56
            list($namespace, $key) = $row;
57
            $namespaces[] = $namespace;
58
            $holder->add($namespace, $key);
59
        }
60
61
        $this->assertEquals($namespaces, $holder->getNamespaces());
62
    }
63
64
    /**
65
     * Test for registerNamespace().
66
     */
67
    public function testRegisterNamespace()
68
    {
69
        $namespaces = ['ns_1'];
70
71
        $holder = new KeyBag();
72
        $holder->registerNamespace($namespaces[0]);
73
74
        $this->assertEquals($namespaces, $holder->getNamespaces());
75
    }
76
77
    /**
78
     * Data provider for testAddAndGet().
79
     *
80
     * @return array[]
81
     */
82
    public function getTestAddAndGetData()
83
    {
84
        return [
85
            ['namespace_1', 'key_11'],
86
            ['namespace_2', 'key_21'],
87
        ];
88
    }
89
}
90