Completed
Push — master ( d70e65...52ffc4 )
by Maurício
21s queued 15s
created

JoinKeywordTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 20
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testParseIncompleteUsing() 0 7 1
A testParseIncomplete() 0 7 1
A testBuildAll() 0 13 1
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