Passed
Pull Request — master (#311)
by William
12:43
created

JoinKeywordTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testParseIncompleteUsing() 0 7 1
A testBuild() 0 13 1
A testParseIncomplete() 0 7 1
1
<?php
2
3
namespace PhpMyAdmin\SqlParser\Tests\Components;
4
5
use PhpMyAdmin\SqlParser\Components\JoinKeyword;
6
use PhpMyAdmin\SqlParser\Parser;
7
use PhpMyAdmin\SqlParser\Tests\TestCase;
8
9
class JoinKeywordTest extends TestCase
10
{
11
    public function testParseIncomplete()
12
    {
13
        $component = JoinKeyword::parse(new Parser(), $this->getTokensList('JOIN a'));
14
        $this->assertCount(1, $component);
15
        $this->assertEquals('a', $component[0]->expr->expr);
16
        $this->assertNull($component[0]->on);
17
        $this->assertNull($component[0]->using);
18
    }
19
20
    public function testParseIncompleteUsing()
21
    {
22
        $component = JoinKeyword::parse(new Parser(), $this->getTokensList('JOIN table2 USING (id)'));
23
        $this->assertCount(1, $component);
24
        $this->assertEquals('table2', $component[0]->expr->expr);
25
        $this->assertNull($component[0]->on);
26
        $this->assertEquals(array('id'), $component[0]->using->values);
27
    }
28
29
    public function testBuild()
30
    {
31
        $component = JoinKeyword::parse(
32
            new Parser(),
33
            $this->getTokensList(
34
                'LEFT JOIN (t2 CROSS JOIN t3 CROSS JOIN t4) ' .
35
                'ON (t2.a=t1.a AND t3.b=t1.b AND t4.c=t1.c)'
36
            )
37
        );
38
        $this->assertEquals(
39
            'LEFT JOIN (t2 CROSS JOIN t3 CROSS JOIN t4) ' .
40
            'ON (t2.a=t1.a AND t3.b=t1.b AND t4.c=t1.c)',
41
            JoinKeyword::build($component)
42
        );
43
    }
44
}
45