Completed
Push — master ( eac9aa...0638ff )
by
unknown
03:01
created

LexerTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 5
Bugs 2 Features 1
Metric Value
wmc 4
c 5
b 2
f 1
lcom 0
cbo 2
dl 0
loc 70
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testTokenMatching() 0 5 1
A testTokenMatchingInUppercase() 0 7 1
A testTokenNotMatching() 0 6 1
B provideValidStringAndToken() 0 37 1
1
<?php
2
3
namespace Netdudes\DataSourceryBundle\Tests\UQL;
4
5
use Netdudes\DataSourceryBundle\UQL\Lexer;
6
7
class LexerTest extends \PHPUnit_Framework_TestCase
8
{
9
    /**
10
     * @dataProvider provideValidStringAndToken
11
     */
12
    public function testTokenMatching($string, $token)
13
    {
14
        $tokenResult = Lexer::matchToken($string, 0);
15
        $this->assertEquals($token, $tokenResult['token'], "Failed to match '$string' to token $token");
16
    }
17
18
    /**
19
     * @dataProvider provideValidStringAndToken
20
     */
21
    public function testTokenMatchingInUppercase($string, $token)
22
    {
23
        $string = strtoupper($string);
24
25
        $tokenResult = Lexer::matchToken($string, 0);
26
        $this->assertEquals($token, $tokenResult['token'], "Failed to match '$string' to token $token");
27
    }
28
29
    public function testTokenNotMatching()
30
    {
31
        $string = '\'this literal has mismatching quotes"';
32
33
        $this->assertFalse(Lexer::matchToken($string, 0), "Lexer should return false for string [$string]");
34
    }
35
36
    /**
37
     * @return array
38
     */
39
    public function provideValidStringAndToken()
40
    {
41
        return [
42
            ['(', 'T_BRACKET_OPEN'],
43
            [')', 'T_BRACKET_CLOSE'],
44
            ["!=", 'T_OP_NEQ'],
45
            ["not", 'T_OP_NEQ'],
46
            ["is not", 'T_OP_NEQ'],
47
            ["<=", 'T_OP_LTE'],
48
            [">=", 'T_OP_GTE'],
49
            ["<", 'T_OP_LT'],
50
            ["less than", 'T_OP_LT'],
51
            ["before", 'T_OP_LT'],
52
            ["=", 'T_OP_EQ'],
53
            ["equals", 'T_OP_EQ'],
54
            ["on", 'T_OP_EQ'],
55
            ["is", 'T_OP_EQ'],
56
            [">", 'T_OP_GT'],
57
            ["more than", 'T_OP_GT'],
58
            ["after", 'T_OP_GT'],
59
            ["in", 'T_OP_IN'],
60
            ["not in", 'T_OP_NIN'],
61
            ["and", 'T_LOGIC_AND'],
62
            ["or", 'T_LOGIC_OR'],
63
            ["xor", 'T_LOGIC_XOR'],
64
            ["'hello there 123 {}'", 'T_LITERAL'],
65
            ['"this is a random . = string"', 'T_LITERAL'],
66
            ["someIndentifier", 'T_IDENTIFIER'],
67
            ["aRandomThingWith_underscores", 'T_IDENTIFIER'],
68
            ["isNotAnEqualsOperator", 'T_IDENTIFIER'],
69
            ["falseIsNotActuallyFalse", 'T_IDENTIFIER'],
70
            [" ", 'T_WHITESPACE'],
71
            ["      ", 'T_WHITESPACE'],
72
            ["\n", 'T_WHITESPACE'],
73
            ["\t", 'T_WHITESPACE'],
74
        ];
75
    }
76
}
77