1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace AmaTeam\ElasticSearch\Test\Suite\Unit\Utility; |
6
|
|
|
|
7
|
|
|
use AmaTeam\ElasticSearch\Utility\Strings; |
8
|
|
|
use Codeception\Test\Unit; |
9
|
|
|
use PHPUnit\Framework\Assert; |
10
|
|
|
|
11
|
|
|
class StringsTest extends Unit |
12
|
|
|
{ |
13
|
|
|
public function camelToSnakeDataProvider() |
14
|
|
|
{ |
15
|
|
|
return [ |
16
|
|
|
['', ''], |
17
|
|
|
['camel_case', 'camel_case'], |
18
|
|
|
['camelCase', 'camel_case'], |
19
|
|
|
['CamelCase', 'camel_case'], |
20
|
|
|
['camelCAse', 'camel_case'], |
21
|
|
|
['_source', '_source'], |
22
|
|
|
]; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function snakeToCamelDataProvider() |
26
|
|
|
{ |
27
|
|
|
return [ |
28
|
|
|
['', ''], |
29
|
|
|
['snake_case', 'snakeCase'], |
30
|
|
|
['_snake_case_', 'snakeCase'], |
31
|
|
|
['snake___case', 'snakeCase'] |
32
|
|
|
]; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param string $input |
37
|
|
|
* @param string $expectation |
38
|
|
|
* |
39
|
|
|
* @dataProvider camelToSnakeDataProvider |
40
|
|
|
* @test |
41
|
|
|
*/ |
42
|
|
|
public function shouldConvertCamelCaseToSnakeCase(string $input, string $expectation) |
43
|
|
|
{ |
44
|
|
|
Assert::assertEquals($expectation, Strings::camelToSnake($input)); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param string $input |
49
|
|
|
* @param string $expectation |
50
|
|
|
* |
51
|
|
|
* @dataProvider snakeToCamelDataProvider |
52
|
|
|
* @test |
53
|
|
|
*/ |
54
|
|
|
public function shouldConvertSnakeCaseToCamelCase(string $input, string $expectation) |
55
|
|
|
{ |
56
|
|
|
Assert::assertEquals($expectation, Strings::snakeToCamel($input)); |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|