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
|
|
|
|