UtilitiesTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 83
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testPregSplitArray() 0 10 1
A testPregSplitFlatArray() 0 11 1
A pregSplitArrayProvider() 0 20 1
1
<?php
2
3
/**
4
 * This file is part of the GitElephant package.
5
 *
6
 * (c) Matteo Giachino <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * Just for fun...
12
 */
13
14
declare(strict_types=1);
15
16
namespace GitElephant;
17
18
/**
19
 * @author Matteo Giachino <[email protected]>
20
 */
21
final class UtilitiesTest extends TestCase
22
{
23
    /**
24
     * An array containing chars
25
     *
26
     * @var array<string>
27
     */
28
    private $arr = [
29
        'a',
30
        'b',
31
        'c',
32
        '1',
33
        'd',
34
        'b',
35
        'e',
36
    ];
37
38
    /**
39
     * @dataProvider pregSplitArrayProvider()
40
     *
41
     * @covers \GitElephant\Utilities::pregSplitArray
42
     *
43
     * @param array<string> $expected
44
     * @param array<string> $list
45
     * @param string $pattern
46
     * @return void
47
     */
48
    public function testPregSplitArray(array $expected, array $list, string $pattern): void
49
    {
50
        $this->assertEquals(
51
            $expected,
52
            Utilities::pregSplitArray(
53
                $list,
54
                $pattern
55
            )
56
        );
57
    }
58
59
    /**
60
     *
61
     *
62
     * @dataProvider
63
     *
64
     * @return void
65
     */
66
    public function testPregSplitFlatArray(): void
67
    {
68
        $this->assertEquals(
69
            [
70
                ['a'],
71
                ['b', 'c', '1', 'd'],
72
                ['b', 'e'],
73
            ],
74
            Utilities::pregSplitFlatArray($this->arr, '/^b$/')
75
        );
76
    }
77
78
    /**
79
     * Get the array test contents
80
     *
81
     * @return array
82
     */
83
    public function pregSplitArrayProvider(): array
84
    {
85
        return [
86
            [
87
                [
88
                    ['b', 'c', '1', 'd'],
89
                    ['b', 'e'],
90
                ],
91
                $this->arr,
92
                '/^b$/',
93
            ],
94
            [
95
                [
96
                    ['1', 'd', 'b', 'e'],
97
                ],
98
                $this->arr,
99
                '/^\d$/',
100
            ],
101
        ];
102
    }
103
}
104