1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mado\QueryBundle\Tests\Services; |
4
|
|
|
|
5
|
|
|
use Mado\QueryBundle\Services\StringParser; |
6
|
|
|
use PHPUnit\Framework\TestCase; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* @coversDefaultClass \Mado\QueryBundle\Services\StringParser |
10
|
|
|
*/ |
11
|
|
|
class StringParserTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
public function setUp() |
14
|
|
|
{ |
15
|
|
|
$this->parser = new StringParser(); |
16
|
|
|
} |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @covers \Mado\QueryBundle\Services\StringParser::numberOfTokens |
20
|
|
|
* @covers \Mado\QueryBundle\Services\StringParser::exploded |
21
|
|
|
* @covers Mado\QueryBundle\Services\StringParser::numberOfTokens |
22
|
|
|
* @covers Mado\QueryBundle\Services\StringParser::tokenize |
23
|
|
|
* @dataProvider tokens |
24
|
|
|
*/ |
25
|
|
|
public function testSplitStringInTokenViaUnderscore( |
26
|
|
|
int $numberOfTokens, |
27
|
|
|
string $string |
28
|
|
|
) { |
29
|
|
|
$this->assertEquals( |
30
|
|
|
$numberOfTokens, |
31
|
|
|
$this->parser->numberOfTokens($string) |
32
|
|
|
); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @covers \Mado\QueryBundle\Services\StringParser::tokenize |
37
|
|
|
* @covers \Mado\QueryBundle\Services\StringParser::exploded |
38
|
|
|
* @covers Mado\QueryBundle\Services\StringParser::numberOfTokens |
39
|
|
|
* @covers Mado\QueryBundle\Services\StringParser::tokenize |
40
|
|
|
* @dataProvider tokens |
41
|
|
|
*/ |
42
|
|
|
public function testTo( |
43
|
|
|
int $numberOfTokens, |
44
|
|
|
string $string, |
45
|
|
|
int $tokenPosition, |
46
|
|
|
string $token |
47
|
|
|
) { |
48
|
|
|
$this->assertEquals( |
49
|
|
|
$token, |
50
|
|
|
$this->parser->tokenize($string, $tokenPosition) |
51
|
|
|
); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function tokens() |
55
|
|
|
{ |
56
|
|
|
return [ |
57
|
|
|
[1, 'foo', 0, 'foo'], |
58
|
|
|
[2, 'foo_bar', 0, 'foo'], |
59
|
|
|
[2, 'foo_bar', 1, 'bar'], |
60
|
|
|
]; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @covers \Mado\QueryBundle\Services\StringParser::camelize |
65
|
|
|
* @covers \Mado\QueryBundle\Services\StringParser::exploded |
66
|
|
|
* @covers Mado\QueryBundle\Services\StringParser::numberOfTokens |
67
|
|
|
* @covers Mado\QueryBundle\Services\StringParser::tokenize |
68
|
|
|
* @dataProvider tokens |
69
|
|
|
*/ |
70
|
|
|
public function testCamelizeSnakeCaseToCamelCase() |
71
|
|
|
{ |
72
|
|
|
$this->assertEquals( |
73
|
|
|
'lowerCamelCase', |
74
|
|
|
$this->parser->camelize('lower_camel_case') |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|