LexerTest::provideValidStringAndToken()   B
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 37
Code Lines 34

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 37
c 0
b 0
f 0
rs 8.8571
cc 1
eloc 34
nc 1
nop 0
1
<?php
2
3
namespace Netdudes\DataSourceryBundle\Tests\UQL;
4
5
use Netdudes\DataSourceryBundle\UQL\Lexer;
6
use PHPUnit\Framework\TestCase;
7
8
class LexerTest extends TestCase
9
{
10
    /**
11
     * @dataProvider provideValidStringAndToken
12
     */
13
    public function testTokenMatching($string, $token)
14
    {
15
        $tokenResult = Lexer::matchToken($string, 0);
16
        $this->assertEquals($token, $tokenResult['token'], "Failed to match '$string' to token $token");
17
    }
18
19
    /**
20
     * @dataProvider provideValidStringAndToken
21
     */
22
    public function testTokenMatchingInUppercase($string, $token)
23
    {
24
        $string = strtoupper($string);
25
26
        $tokenResult = Lexer::matchToken($string, 0);
27
        $this->assertEquals($token, $tokenResult['token'], "Failed to match '$string' to token $token");
28
    }
29
30
    public function testTokenNotMatching()
31
    {
32
        $string = '\'this literal has mismatching quotes"';
33
34
        $this->assertFalse(Lexer::matchToken($string, 0), "Lexer should return false for string [$string]");
0 ignored issues
show
Bug introduced by
It seems like \Netdudes\DataSourceryBu...:matchToken($string, 0) targeting Netdudes\DataSourceryBun...UQL\Lexer::matchToken() can also be of type array<string,?,{"match":"string","token":"?"}>; however, PHPUnit\Framework\Assert::assertFalse() does only seem to accept boolean, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
35
    }
36
37
    /**
38
     * @return array
39
     */
40
    public function provideValidStringAndToken()
41
    {
42
        return [
43
            ['(', 'T_BRACKET_OPEN'],
44
            [')', 'T_BRACKET_CLOSE'],
45
            ["!=", 'T_OP_NEQ'],
46
            ["not", 'T_OP_NEQ'],
47
            ["is not", 'T_OP_NEQ'],
48
            ["<=", 'T_OP_LTE'],
49
            [">=", 'T_OP_GTE'],
50
            ["<", 'T_OP_LT'],
51
            ["less than", 'T_OP_LT'],
52
            ["before", 'T_OP_LT'],
53
            ["=", 'T_OP_EQ'],
54
            ["equals", 'T_OP_EQ'],
55
            ["on", 'T_OP_EQ'],
56
            ["is", 'T_OP_EQ'],
57
            [">", 'T_OP_GT'],
58
            ["more than", 'T_OP_GT'],
59
            ["after", 'T_OP_GT'],
60
            ["in", 'T_OP_IN'],
61
            ["not in", 'T_OP_NIN'],
62
            ["and", 'T_LOGIC_AND'],
63
            ["or", 'T_LOGIC_OR'],
64
            ["xor", 'T_LOGIC_XOR'],
65
            ["'hello there 123 {}'", 'T_LITERAL'],
66
            ['"this is a random . = string"', 'T_LITERAL'],
67
            ["someIndentifier", 'T_IDENTIFIER'],
68
            ["aRandomThingWith_underscores", 'T_IDENTIFIER'],
69
            ["isNotAnEqualsOperator", 'T_IDENTIFIER'],
70
            ["falseIsNotActuallyFalse", 'T_IDENTIFIER'],
71
            [" ", 'T_WHITESPACE'],
72
            ["      ", 'T_WHITESPACE'],
73
            ["\n", 'T_WHITESPACE'],
74
            ["\t", 'T_WHITESPACE'],
75
        ];
76
    }
77
}
78