Passed
Pull Request — master (#483)
by
unknown
03:28
created

JoinKeywordTest::testBuildAll()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 13
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpMyAdmin\SqlParser\Tests\Components;
6
7
use PhpMyAdmin\SqlParser\Components\JoinKeyword;
8
use PhpMyAdmin\SqlParser\Parser;
9
use PhpMyAdmin\SqlParser\Tests\TestCase;
10
11
class JoinKeywordTest extends TestCase
12
{
13
    public function testParseIncomplete(): void
14
    {
15
        $component = JoinKeyword::parse(new Parser(), $this->getTokensList('JOIN a'));
16
        $this->assertCount(1, $component);
17
        $this->assertEquals('a', $component[0]->expr->expr);
18
        $this->assertNull($component[0]->on);
19
        $this->assertNull($component[0]->using);
20
    }
21
22
    public function testParseIncompleteUsing(): void
23
    {
24
        $component = JoinKeyword::parse(new Parser(), $this->getTokensList('JOIN table2 USING (id)'));
25
        $this->assertCount(1, $component);
26
        $this->assertEquals('table2', $component[0]->expr->expr);
27
        $this->assertNull($component[0]->on);
28
        $this->assertEquals(['id'], $component[0]->using->values);
29
    }
30
31
    public function testBuildAll(): void
32
    {
33
        $component = JoinKeyword::parse(
34
            new Parser(),
35
            $this->getTokensList(
36
                'LEFT JOIN (t2 CROSS JOIN t3 CROSS JOIN t4) ' .
37
                'ON (t2.a=t1.a AND t3.b=t1.b AND t4.c=t1.c)'
38
            )
39
        );
40
        $this->assertEquals(
41
            'LEFT JOIN (t2 CROSS JOIN t3 CROSS JOIN t4) ' .
42
            'ON (t2.a=t1.a AND t3.b=t1.b AND t4.c=t1.c)',
43
            JoinKeyword::buildAll($component)
44
        );
45
    }
46
}
47