|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the sauls/helpers package. |
|
4
|
|
|
* |
|
5
|
|
|
* @author Saulius Vaičeliūnas <[email protected]> |
|
6
|
|
|
* @link http://saulius.vaiceliunas.lt |
|
7
|
|
|
* @copyright 2018 |
|
8
|
|
|
* |
|
9
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
10
|
|
|
* file that was distributed with this source code. |
|
11
|
|
|
*/ |
|
12
|
|
|
|
|
13
|
|
|
namespace Sauls\Component\Helper; |
|
14
|
|
|
|
|
15
|
|
|
use PHPUnit\Framework\TestCase; |
|
16
|
|
|
|
|
17
|
|
|
class StringTest extends TestCase |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @test |
|
21
|
|
|
* @dataProvider getDataArrayForStringCamelize |
|
22
|
|
|
*/ |
|
23
|
|
|
public function should_camelize_given_strings(string $expected, string $value) |
|
24
|
|
|
{ |
|
25
|
|
|
$this->assertSame($expected, string_camelize($value)); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function getDataArrayForStringCamelize(): array |
|
29
|
|
|
{ |
|
30
|
|
|
return [ |
|
31
|
|
|
['Text', 'text'], |
|
32
|
|
|
['SimpleWord', 'simple word'], |
|
33
|
|
|
['SimpleWord', 'simple_word'], |
|
34
|
|
|
['Simple_Word', 'simple.word'], |
|
35
|
|
|
['Simple_Class', 'simple\\class'], |
|
36
|
|
|
]; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @test |
|
41
|
|
|
* @dataProvider getDataArrayForStringSnakeify |
|
42
|
|
|
*/ |
|
43
|
|
|
public function should_snakeify_given_strings(string $expected, string $value) |
|
44
|
|
|
{ |
|
45
|
|
|
$this->assertSame($expected, string_snakeify($value)); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function getDataArrayForStringSnakeify(): array |
|
49
|
|
|
{ |
|
50
|
|
|
return [ |
|
51
|
|
|
['test_test', 'TestTest'], |
|
52
|
|
|
['this_is_snake_string', 'thisIsSnakeString'], |
|
53
|
|
|
['test25_link', 'test25Link'], |
|
54
|
|
|
]; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* @test |
|
59
|
|
|
*/ |
|
60
|
|
|
public function should_explode_string_by_multiple_delimiters() |
|
61
|
|
|
{ |
|
62
|
|
|
$this->assertSame(['one', 'two', 'three'], multi_explode(['.'], 'one.two.three')); |
|
63
|
|
|
$this->assertSame(['one', 'two', 'three'], multi_explode(['.', ','], 'one.two,three')); |
|
64
|
|
|
$this->assertSame(['one', 'two', 'three', 'four'], multi_explode(['.', ',', '#'], 'one.two,three#four')); |
|
65
|
|
|
$this->assertSame(['one', 'two', 'three', 'four|five'], multi_explode(['.', ',', '#'], 'one.two,three#four|five')); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* @test |
|
70
|
|
|
*/ |
|
71
|
|
|
public function should_base64_encode_given_urls() |
|
72
|
|
|
{ |
|
73
|
|
|
$this->assertSame('VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==', base64_url_encode('This is an encoded string')); |
|
74
|
|
|
$this->assertSame('YcSNacWrIC0gdGhhbmsgeW91IQ==', base64_url_encode('ačiū - thank you!')); |
|
75
|
|
|
$this->assertSame('NTU1LTQ0NC01NTU=', base64_url_encode('555-444-555')); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @test |
|
80
|
|
|
*/ |
|
81
|
|
|
public function should_base64_decode_given_urls() |
|
82
|
|
|
{ |
|
83
|
|
|
$this->assertSame('This is an encoded string', base64_url_decode('VGhpcyBpcyBhbiBlbmNvZGVkIHN0cmluZw==')); |
|
84
|
|
|
$this->assertSame('ačiū - thank you!', base64_url_decode('YcSNacWrIC0gdGhhbmsgeW91IQ==')); |
|
85
|
|
|
$this->assertSame('555-444-555', base64_url_decode('NTU1LTQ0NC01NTU=')); |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|