JoinTest   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 19
c 2
b 0
f 1
dl 0
loc 42
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A testType() 0 5 1
A testConstructor() 0 5 1
A testConstructorWithDefaultAlias() 0 5 1
A testName() 0 4 1
A testChainingTypeAndOn() 0 6 1
A testOn() 0 5 1
1
<?php
2
3
use PHPUnit\Framework\TestCase;
4
use HexMakina\Crudites\Grammar\Clause\Join;
5
use HexMakina\Crudites\Grammar\Predicate;
6
7
class JoinTest extends TestCase
8
{
9
    public function testConstructor()
10
    {
11
        $join = new Join('cbx_order', 'Orders');
12
        $this->assertEquals('cbx_order', $join->table());
13
        $this->assertEquals('Orders', $join->alias());
14
    }
15
16
    public function testConstructorWithDefaultAlias()
17
    {
18
        $join = new Join('cbx_order');
19
        $this->assertEquals('cbx_order', $join->table());
20
        $this->assertEquals('cbx_order', $join->alias());
21
    }
22
23
    public function testType()
24
    {
25
        $join = new Join('cbx_order', 'Orders');
26
        $join->type('LEFT');
27
        $this->assertEquals('LEFT JOIN `cbx_order` `Orders` ON', (string)$join);
28
    }
29
30
    public function testOn()
31
    {
32
        $join = new Join('cbx_order', 'Orders');
33
        $join->on('user_id', 'User', 'id');
34
        $this->assertEquals('JOIN `cbx_order` `Orders` ON `Orders`.`user_id` = `User`.`id`', (string)$join);
35
    }
36
37
    public function testChainingTypeAndOn()
38
    {
39
        $join = new Join('cbx_order', 'Orders');
40
        $join->type('LEFT')->on('user_id', 'User', 'id');
41
        $expectedString = sprintf('LEFT JOIN `%s` `%s` ON `Orders`.`user_id` = `User`.`id`', 'cbx_order', 'Orders');
42
        $this->assertEquals($expectedString, (string)$join);
43
    }
44
45
    public function testName()
46
    {
47
        $join = new Join('cbx_order', 'Orders');
48
        $this->assertEquals('JOIN', $join->name());
49
    }
50
}
51