|
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
|
|
|
} |