Passed
Push — master ( fd9e59...dec0a2 )
by William
12:38 queued 11s
created

ContextGeneratorTest::testFormatName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 3
b 0
f 0
nc 1
nop 0
dl 0
loc 10
rs 10
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('MySql80000');
19
        $this->assertEquals('MySQL 8.0', $name);
20
21
        $name = ContextGenerator::formatName('MariaDb100200');
22
        $this->assertEquals('MariaDB 10.2', $name);
23
24
        $name = ContextGenerator::formatName('MariaDb100000');
25
        $this->assertEquals('MariaDB 10.0', $name);
26
    }
27
28
    public function testSortWords(): void
29
    {
30
        $wordsArray = ['41' => [['GEOMETRYCOLLECTION', 'DATE']], '35' => [['SCHEMA', 'REPEAT', 'VALUES']]];
31
        ContextGenerator::sortWords($wordsArray);
32
        $this->assertEquals([
33
            '41' => ['0' => ['DATE', 'GEOMETRYCOLLECTION']],
34
            '35' => ['0' => ['REPEAT', 'SCHEMA', 'VALUES']],
35
        ], $wordsArray);
36
    }
37
38
    public function testReadWords(): void
39
    {
40
        $testFiles = [getcwd() . '/tests/Tools/contexts/testContext.txt'];
41
        $readWords = ContextGenerator::readWords($testFiles);
42
        $this->assertEquals([
43
            Token::TYPE_KEYWORD | Token::FLAG_KEYWORD_RESERVED => [
44
                8 => ['RESERVED'],
45
                9 => ['RESERVED2','RESERVED3','RESERVED4','RESERVED5'],
46
            ],
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