Completed
Push — develop ( 8a0cb6...d5d9d0 )
by Tom
04:26
created

ArrayFunctionsTest::provideColumnOrderings()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 35
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 35
rs 8.8571
cc 1
eloc 26
nc 1
nop 0
1
<?php
2
3
namespace N98\Util;
4
5
/**
6
 * Class ArrayFunctionsTest
7
 *
8
 * @covers N98\Util\ArrayFunctions
9
 */
10
class ArrayFunctionsTest extends \PHPUnit_Framework_TestCase
11
{
12
    /**
13
     * @test
14
     * @param array $a
15
     * @param array $b
16
     * @param array $expected
17
     * @dataProvider mergeArraysProvider
18
     */
19
    public function mergeArrays(array $a, array $b, array $expected)
20
    {
21
        $this->assertEquals($expected, ArrayFunctions::mergeArrays($a, $b));
22
    }
23
24
    /**
25
     * @return array
26
     */
27
    public static function mergeArraysProvider()
28
    {
29
        return array(
30
            array(
31
                array(),
32
                array('Foo', 'Bar'),
33
                array('Foo', 'Bar')
34
            ),
35
            array(
36
                array('Foo', 'Bar'),
37
                array(),
38
                array('Foo', 'Bar')
39
            ),
40
            array(
41
                array('Foo'),
42
                array('Bar'),
43
                array('Foo', 'Bar')
44
            ),
45
            array(
46
                array('Foo', array('Bar')),
47
                array('Bar'),
48
                array('Foo', array('Bar'), 'Bar')
49
            ),
50
51
            /**
52
             * Override Bar->Bar
53
             */
54
            array(
55
                array('Foo', 'Bar' => array('Bar' => 1)),
56
                array('Bar' => array('Bar' => 2)),
57
                array('Foo', 'Bar' => array('Bar' => 2))
58
            ),
59
        );
60
    }
61
62
    /**
63
     * @test
64
     */
65
    public function columnOrderArrayTable()
66
    {
67
        $headers = array('foo', 'bar', 'baz');
68
        $table = array(
69
            array('foo' => 'A1', 'baz' => 'C1', 'B1', 'D1'),
70
            array('A2', 'B2', 'C2', 'D2'),
71
            array(null, null, null, 'foo' => 'A3'),
72
        );
73
74
        $actual = ArrayFunctions::columnOrderArrayTable($headers, $table);
75
        $this->assertInternalType('array', $actual);
76
        $this->assertCount(count($table), $actual);
77
        $expected = array(
78
            array('foo' => 'A1', 'bar' => 'B1', 'baz' => 'C1', 'D1'),
79
            array('foo' => 'A2', 'bar' => 'B2', 'baz' => 'C2', 'D2'),
80
            array('foo' => 'A3', 'bar' => null, 'baz' => null, null),
81
        );
82
        $this->assertEquals($expected, $actual);
83
        $this->assertSame($expected, $actual);
84
    }
85
86
    /**
87
     * @test
88
     * @dataProvider provideColumnOrderings
89
     */
90
    public function columnOrder($columns, $array, $expected)
91
    {
92
        $actual = ArrayFunctions::columnOrder($columns, $array);
93
        $this->assertInternalType('array', $actual);
94
        $this->assertEquals($expected, $actual);
95
        $this->assertSame($expected, $actual);
96
    }
97
98
    /**
99
     * @see columnOrder
100
     * @return array
101
     */
102
    public function provideColumnOrderings()
103
    {
104
        return array(
105
            array(
106
                array('foo', 'bar', 'baz'),
107
                array('A', 'B', 'C'),
108
                array('foo' => 'A', 'bar' => 'B', 'baz' => 'C'),
109
            ),
110
            array(
111
                array('foo', 'bar', 'baz'),
112
                array('A', 'B', 'C', 'D'),
113
                array('foo' => 'A', 'bar' => 'B', 'baz' => 'C', 'D'),
114
            ),
115
            array(
116
                array('foo', 'bar', 'baz'),
117
                array('A', 'B', 'C'),
118
                array('foo' => 'A', 'bar' => 'B', 'baz' => 'C'),
119
            ),
120
            array(
121
                array('foo', 'bar', 'baz'),
122
                array('buz' => 'D', 'A', 'B', 'C'),
123
                array('foo' => 'A', 'bar' => 'B', 'baz' => 'C', 'buz' => 'D'),
124
            ),
125
            array(
126
                array('foo', 'bar', 'baz'),
127
                array('foo' => 'A', 'baz' => 'C', 'B', 'D'),
128
                array('foo' => 'A', 'bar' => 'B', 'baz' => 'C', 'D'),
129
            ),
130
            array(
131
                array('foo', 'bar', 'baz'),
132
                array('foo' => 'A', 'baz' => 'C'),
133
                array('foo' => 'A', 'bar' => null, 'baz' => 'C'),
134
            ),
135
        );
136
    }
137
}
138