Passed
Pull Request — master (#394)
by
unknown
05:43 queued 03:02
created

ContextGeneratorTest::testReadWords()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 10
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 12
rs 9.9332
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpMyAdmin\SqlParser\Tests\Tools;
6
7
use PhpMyAdmin\SqlParser\Tests\TestCase;
8
use PhpMyAdmin\SqlParser\Token;
9
use PhpMyAdmin\SqlParser\Tools\ContextGenerator;
10
11
use function file_get_contents;
12
use function getcwd;
13
14
class ContextGeneratorTest extends TestCase
15
{
16
    public function testFormatName(): void
17
    {
18
        $name = ContextGenerator::formatName('MySql');
19
        $this->assertEquals('MySQL ', $name);
20
21
        $name = ContextGenerator::formatName('MySql80000');
22
        $this->assertEquals('MySQL 8.0', $name);
23
24
        $name = ContextGenerator::formatName('MariaDB100200');
25
        $this->assertEquals('MariaDB 10.2', $name);
26
27
        $name = ContextGenerator::formatName('MariaDB100000');
28
        $this->assertEquals('MariaDB 10.0', $name);
29
    }
30
31
    public function testSortWords(): void
32
    {
33
        $wordsArray = ['41' => [['GEOMETRYCOLLECTION', 'DATE']], '35' => [['SCHEMA', 'REPEAT', 'VALUES']]];
34
        ContextGenerator::sortWords($wordsArray);
35
        $this->assertEquals([
36
            '41' => ['0' => ['DATE', 'GEOMETRYCOLLECTION']],
37
            '35' => ['0' => ['REPEAT', 'SCHEMA', 'VALUES']],
38
        ], $wordsArray);
39
    }
40
41
    public function testReadWords(): void
42
    {
43
        $testFiles = [getcwd() . '/tests/Tools/contexts/testContext.txt'];
44
        $readWords = ContextGenerator::readWords($testFiles);
45
        $this->assertEquals([
46
            Token::TYPE_KEYWORD | Token::FLAG_KEYWORD_RESERVED => [8 => ['RESERVED']],
47
            Token::TYPE_KEYWORD | Token::FLAG_KEYWORD_FUNCTION => [8 => ['FUNCTION']],
48
            Token::TYPE_KEYWORD | Token::FLAG_KEYWORD_DATA_TYPE => [8 => ['DATATYPE']],
49
            Token::TYPE_KEYWORD | Token::FLAG_KEYWORD_KEY => [7 => ['KEYWORD']],
50
            Token::TYPE_KEYWORD => [7 => ['NO_FLAG']],
51
            Token::TYPE_KEYWORD | Token::FLAG_KEYWORD_RESERVED | 4 => [16 => ['COMPOSED KEYWORD']],
52
        ], $readWords);
53
    }
54
55
    public function testGenerate(): void
56
    {
57
        $testFiles = [getcwd() . '/tests/Tools/contexts/testContext.txt'];
58
        $readWords = ContextGenerator::readWords($testFiles);
59
        ContextGenerator::printWords($readWords);
60
        $options = [
61
            'keywords' => $readWords,
62
            'name' => 'MYSQL TEST',
63
            'class' => 'ContextTest',
64
            'link' => 'https://www.phpmyadmin.net/contribute',
65
        ];
66
        $generatedTemplate = ContextGenerator::generate($options);
0 ignored issues
show
Bug introduced by
$options of type array<string,array<integ...teger,string>>>|string> is incompatible with the type array<string,array<integ...teger,string>>>|string> expected by parameter $options of PhpMyAdmin\SqlParser\Too...xtGenerator::generate(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

66
        $generatedTemplate = ContextGenerator::generate(/** @scrutinizer ignore-type */ $options);
Loading history...
67
        $expectedTemplate = file_get_contents(getcwd() . '/tests/Tools/templates/ContextTest.php');
68
        $this->assertEquals($expectedTemplate, $generatedTemplate);
69
    }
70
}
71