Passed
Push — master ( 9aa859...1456e8 )
by Maurício
08:29 queued 12s
created

ParseAnalyzeTest::testSqlQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 14
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 20
rs 9.7998
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpMyAdmin\Tests;
6
7
use PhpMyAdmin\ParseAnalyze;
8
use PhpMyAdmin\ResponseRenderer;
9
use PhpMyAdmin\StatementInfo;
10
11
/**
12
 * @covers \PhpMyAdmin\ParseAnalyze
13
 */
14
class ParseAnalyzeTest extends AbstractTestCase
15
{
16
    public function testSqlQuery(): void
17
    {
18
        $GLOBALS['lang'] = 'en';
19
        ResponseRenderer::getInstance()->setAjax(false);
20
21
        $GLOBALS['unparsed_sql'] = '';
22
23
        $actual = ParseAnalyze::sqlQuery('SELECT * FROM `sakila`.`actor`', 'sakila_test');
24
25
        /** @psalm-suppress TypeDoesNotContainType */
26
        $this->assertSame('SELECT * FROM `sakila`.`actor`', $GLOBALS['unparsed_sql']);
27
        $this->assertCount(3, $actual);
28
        $this->assertInstanceOf(StatementInfo::class, $actual[0]);
29
        $this->assertSame('sakila', $actual[1]);
30
        $this->assertSame('actor', $actual[2]);
31
        $this->assertTrue($actual[0]->reload);
32
        $this->assertNotEmpty($actual[0]->selectTables);
33
        $this->assertSame([['actor', 'sakila']], $actual[0]->selectTables);
34
        $this->assertNotEmpty($actual[0]->selectExpression);
35
        $this->assertSame(['*'], $actual[0]->selectExpression);
36
    }
37
38
    public function testSqlQuery2(): void
39
    {
40
        $GLOBALS['lang'] = 'en';
41
        ResponseRenderer::getInstance()->setAjax(false);
42
43
        $GLOBALS['unparsed_sql'] = '';
44
45
        $actual = ParseAnalyze::sqlQuery('SELECT `first_name`, `title` FROM `actor`, `film`', 'sakila');
46
47
        /** @psalm-suppress TypeDoesNotContainType */
48
        $this->assertSame('SELECT `first_name`, `title` FROM `actor`, `film`', $GLOBALS['unparsed_sql']);
49
        $this->assertCount(3, $actual);
50
        $this->assertInstanceOf(StatementInfo::class, $actual[0]);
51
        $this->assertSame('sakila', $actual[1]);
52
        $this->assertSame('', $actual[2]);
53
        $this->assertFalse($actual[0]->reload);
54
        $this->assertNotEmpty($actual[0]->selectTables);
55
        $this->assertSame([['actor', null], ['film', null]], $actual[0]->selectTables);
56
        $this->assertNotEmpty($actual[0]->selectExpression);
57
        $this->assertSame(['`first_name`', '`title`'], $actual[0]->selectExpression);
58
    }
59
}
60