1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Nip\Utility\Tests; |
4
|
|
|
|
5
|
|
|
use Nip\Utility\Str; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class StrTest |
9
|
|
|
* @package Nip\Utility\Tests |
10
|
|
|
*/ |
11
|
|
|
class StrTest extends AbstractTest |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @param $data |
15
|
|
|
* @param $start |
16
|
|
|
* @param $end |
17
|
|
|
* @param $masked |
18
|
|
|
* @dataProvider dataMask() |
19
|
|
|
*/ |
20
|
|
|
public function testMask($data, $start, $end, $masked) |
21
|
|
|
{ |
22
|
|
|
self::assertSame($masked, Str::mask($data, $start, $end)); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @return array |
27
|
|
|
*/ |
28
|
|
|
public function dataMask() |
29
|
|
|
{ |
30
|
|
|
return [ |
31
|
|
|
['test', 0, null, '****'], |
32
|
|
|
['test', 1, null, 't***'], |
33
|
|
|
['foe', 2, 1, '***'], |
34
|
|
|
['lorem', 5, false, '*****'], |
35
|
|
|
]; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param $name |
40
|
|
|
* @param $initials |
41
|
|
|
* @dataProvider dataInitials() |
42
|
|
|
*/ |
43
|
|
|
public function testInitials($name, $initials) |
44
|
|
|
{ |
45
|
|
|
self::assertSame($initials, Str::initials($name)); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @return array |
50
|
|
|
*/ |
51
|
|
|
public function dataInitials() |
52
|
|
|
{ |
53
|
|
|
return [ |
54
|
|
|
['test', 'T.'], |
55
|
|
|
['test test', 'T.T.'], |
56
|
|
|
['test-test', 'T.T.'], |
57
|
|
|
]; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* @dataProvider dataIsJson() |
62
|
|
|
* @param $json |
63
|
|
|
* @param $return |
64
|
|
|
* @param $params |
65
|
|
|
* @param $output |
66
|
|
|
*/ |
67
|
|
|
public function testIsJson($json, $return, $params, $output) |
68
|
|
|
{ |
69
|
|
|
self::assertSame($output, Str::isJson($json, $return, ...$params)); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return array |
74
|
|
|
*/ |
75
|
|
|
public function dataIsJson() |
76
|
|
|
{ |
77
|
|
|
return [ |
78
|
|
|
['test', null, [], false], |
79
|
|
|
[json_encode([1 => 2]), null, [], true], |
80
|
|
|
[json_encode([1 => 2]), false, [], true], |
81
|
|
|
[json_encode([1 => 2]), '', [], true], |
82
|
|
|
[json_encode([1 => 2]), true, [true], [1 => 2]], |
83
|
|
|
]; |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|