Completed
Push — feature/shared-folder ( 960872...a08018 )
by Tom
04:21
created

ArrayFunctionsTest::mergeArraysProvider()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 34
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 34
rs 8.8571
cc 1
eloc 22
nc 1
nop 0
1
<?php
2
3
namespace N98\Util;
4
5
class ArrayFunctionsTest extends \PHPUnit_Framework_TestCase
6
{
7
    /**
8
     * @test
9
     * @param array $a
10
     * @param array $b
11
     * @param array $expected
12
     * @dataProvider mergeArraysProvider
13
     */
14
    public function mergeArrays(array $a, array $b, array $expected)
15
    {
16
        $this->assertEquals($expected, ArrayFunctions::mergeArrays($a, $b));
17
    }
18
19
    /**
20
     * @return array
21
     */
22
    public function mergeArraysProvider()
23
    {
24
        return array(
25
            array(
26
                array(),
27
                array('Foo', 'Bar'),
28
                array('Foo', 'Bar')
29
            ),
30
            array(
31
                array('Foo', 'Bar'),
32
                array(),
33
                array('Foo', 'Bar')
34
            ),
35
            array(
36
                array('Foo'),
37
                array('Bar'),
38
                array('Foo', 'Bar')
39
            ),
40
            array(
41
                array('Foo', array('Bar')),
42
                array('Bar'),
43
                array('Foo', array('Bar'), 'Bar')
44
            ),
45
46
            /**
47
             * Override Bar->Bar
48
             */
49
            array(
50
                array('Foo', 'Bar' => array('Bar' => 1)),
51
                array('Bar' => array('Bar' => 2)),
52
                array('Foo', 'Bar' => array('Bar' => 2))
53
            ),
54
        );
55
    }
56
57
    /**
58
     * @return array
59
     * @see filterMatrixByValue
60
     */
61
    public function provideMatrix()
62
    {
63
        return array(
64
            array(
65
                array(
66
                    array('foo' => 'bar'),
67
                    array('foo' => 'baz'),
68
                    array('foo' => 'zaz'),
69
                )
70
            )
71
        );
72
    }
73
74
    /**
75
     * @param array $matrix
76
     * @test
77
     * @dataProvider provideMatrix
78
     */
79
    public function matrixFilterByValue(array $matrix)
80
    {
81
        $this->assertCount(3, $matrix);
82
        $filtered = ArrayFunctions::matrixFilterByValue($matrix, 'foo', 'bar');
83
        $this->assertCount(1, $filtered);
84
    }
85
86
    /**
87
     * @param array $matrix
88
     * @test
89
     * @dataProvider provideMatrix
90
     */
91
    public function matrixFilterStartsWith(array $matrix)
92
    {
93
        $this->assertCount(3, $matrix);
94
        $filtered = ArrayFunctions::matrixFilterStartswith($matrix, 'foo', 'ba');
95
        $this->assertCount(2, $filtered);
96
    }
97
}
98