Passed
Pull Request — master (#394)
by
unknown
03:19 queued 32s
created

ContextGeneratorTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 33
c 4
b 0
f 0
dl 0
loc 52
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testReadWords() 0 12 1
A testGenerate() 0 14 1
A testFormatName() 0 10 1
A testSortWords() 0 8 1
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 => [8 => ['RESERVED']],
44
            Token::TYPE_KEYWORD | Token::FLAG_KEYWORD_FUNCTION => [8 => ['FUNCTION']],
45
            Token::TYPE_KEYWORD | Token::FLAG_KEYWORD_DATA_TYPE => [8 => ['DATATYPE']],
46
            Token::TYPE_KEYWORD | Token::FLAG_KEYWORD_KEY => [7 => ['KEYWORD']],
47
            Token::TYPE_KEYWORD => [7 => ['NO_FLAG']],
48
            Token::TYPE_KEYWORD | Token::FLAG_KEYWORD_RESERVED | 4 => [16 => ['COMPOSED KEYWORD']],
49
        ], $readWords);
50
    }
51
52
    public function testGenerate(): void
53
    {
54
        $testFiles = [getcwd() . '/tests/Tools/contexts/testContext.txt'];
55
        $readWords = ContextGenerator::readWords($testFiles);
56
        ContextGenerator::printWords($readWords);
57
        $options = [
58
            'keywords' => $readWords,
59
            'name' => 'MYSQL TEST',
60
            'class' => 'ContextTest',
61
            'link' => 'https://www.phpmyadmin.net/contribute',
62
        ];
63
        $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

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