Completed
Push — master ( a8b608...dc5b75 )
by Valentin
02:10
created

UtilsTest::injectValuesProvider()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 29
rs 9.456
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Cycle\ORM\Promise\Tests;
4
5
use Cycle\ORM\Promise\Utils;
6
use PHPUnit\Framework\TestCase;
7
8
class UtilsTest extends TestCase
9
{
10
    /**
11
     * @dataProvider trailingProvider
12
     *
13
     * @param string $name
14
     * @param int    $sequence
15
     * @param string $expected
16
     */
17
    public function testTrimTrailingDigits(string $name, int $sequence, string $expected): void
18
    {
19
        $this->assertEquals($expected, Utils::trimTrailingDigits($name, $sequence));
20
    }
21
22
    public function trailingProvider(): array
23
    {
24
        return [
25
            ['name7', 7, 'name',],
26
            ['name', 0, 'name',],
27
            ['name0', 0, 'name',],
28
            ['name1', 1, 'name'],
29
            ['name-1', 1, 'name-'],
30
            ['name-1', -1, 'name'],
31
        ];
32
    }
33
34
    /**
35
     * @dataProvider injectValuesProvider
36
     *
37
     * @param array $array
38
     * @param int   $index
39
     * @param array $child
40
     * @param array $expected
41
     */
42
    public function testInjectValues(array $array, int $index, array $child, array $expected): void
43
    {
44
        $this->assertEquals($expected, Utils::injectValues($array, $index, $child));
45
    }
46
47
    public function injectValuesProvider(): array
48
    {
49
        return [
50
            [
51
                ['a', 'b', 'c', 'd', 'e'],
52
                0,
53
                ['aa', 'bb'],
54
                ['aa', 'bb', 'a', 'b', 'c', 'd', 'e'],
55
            ],
56
            [
57
                ['a', 'b', 'c', 'd', 'e'],
58
                -2,
59
                ['aa', 'bb'],
60
                ['a', 'b', 'c', 'aa', 'bb', 'd', 'e'],
61
            ],
62
            [
63
                ['a', 'b', 'c', 'd', 'e'],
64
                2,
65
                ['aa', 'bb'],
66
                ['a', 'b', 'aa', 'bb', 'c', 'd', 'e'],
67
            ],
68
            [
69
                ['a', 'b', 'c', 'd', 'e'],
70
                5,
71
                ['aa', 'bb'],
72
                ['a', 'b', 'c', 'd', 'e', 'aa', 'bb'],
73
            ],
74
        ];
75
    }
76
77
    /**
78
     * @dataProvider shortNameProvider
79
     *
80
     * @param string $name
81
     * @param string $expected
82
     */
83
    public function testShortName(string $name, string $expected): void
84
    {
85
        $this->assertEquals($expected, Utils::shortName($name));
86
    }
87
88
    public function shortNameProvider(): array
89
    {
90
        return [
91
            ['a\b\cdef', 'cdef'],
92
            ['abcdef', 'abcdef'],
93
            ['abcdef\\', ''],
94
        ];
95
    }
96
}