Passed
Push — main ( b49db2...9f0690 )
by Sammy
08:20
created

WhereTest::testConstructor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
1
<?php
2
use PHPUnit\Framework\TestCase;
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
3
use HexMakina\Crudites\Grammar\Clause\Where;
4
use HexMakina\Crudites\Grammar\Predicate;
5
6
class WhereTest extends TestCase
7
{
8
    public function testConstructor()
9
    {
10
        $where = new Where('default_table');
11
        $this->assertInstanceOf(Where::class, $where);
12
    }
13
14
    public function testBindings()
15
    {
16
        $where = new Where('default_table');
17
        $this->assertIsArray($where->bindings());
18
        $this->assertEmpty($where->bindings());
19
20
        $where->andPredicate((new Predicate(['table', 'field'], '='))->withValue(3));
21
        $this->assertNotEmpty($where->bindings());
22
        $this->assertArrayHasKey('table_field', $where->bindings());
23
    }
24
25
    public function testToString()
26
    {
27
        $where = new Where('default_table');
28
        $this->assertEquals('', $where->__toString());
29
30
        $predicate = new Predicate('1', '=', '1');
31
        $where->andPredicate($predicate);
32
        $this->assertEquals('WHERE 1 = 1', $where->__toString());
33
    }
34
35
    public function testAndRaw()
36
    {
37
        $where = new Where('default_table');
38
        $where->andRaw('1=1');
39
        $this->assertEquals('WHERE 1=1', $where->__toString());
40
    }
41
42
    public function testAndPredicate()
43
    {
44
        $where = new Where('default_table');
45
        $where->andPredicate(new Predicate('1', '=', '1'));
46
47
        $this->assertEquals('WHERE 1 = 1', (string)$where);
48
        $this->assertEquals([], $where->bindings());
49
    }
50
51
    public function testAndIsNull()
52
    {
53
        $where = new Where('default_table');
54
        $where->andIsNull('field');
55
        $this->assertStringContainsString('IS NULL', $where->__toString());
56
    }
57
58
    public function testAndFields()
59
    {
60
        $where = new Where('default_table');
61
        $where->andFields(['field' => 'value']);
62
        $this->assertStringContainsString('=', $where->__toString());
63
    }
64
65
    public function testAndIn()
66
    {
67
        $where = new Where('default_table');
68
        $where->andIn('field', ['value1', 'value2']);
69
        $this->assertStringContainsString('IN', $where->__toString());
70
    }
71
}