|
1
|
|
|
<?php |
|
2
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
|
|
3
|
|
|
use HexMakina\Crudites\Grammar\Predicate; |
|
4
|
|
|
|
|
5
|
|
|
class PredicateTest extends TestCase |
|
6
|
|
|
{ |
|
7
|
|
|
public function testConstructorWithStrings() |
|
8
|
|
|
{ |
|
9
|
|
|
$predicate = new Predicate('expression'); |
|
10
|
|
|
$this->assertEquals('expression', (string)$predicate); |
|
11
|
|
|
$this->assertEquals([], $predicate->bindings()); |
|
12
|
|
|
|
|
13
|
|
|
$predicate = new Predicate('expression', 'IS NULL'); |
|
14
|
|
|
$this->assertEquals('expression IS NULL', (string)$predicate); |
|
15
|
|
|
$this->assertEquals([], $predicate->bindings()); |
|
16
|
|
|
|
|
17
|
|
|
$predicate = new Predicate('expression', '=', 'other_expression'); |
|
18
|
|
|
$this->assertEquals('expression = other_expression', (string)$predicate); |
|
19
|
|
|
$this->assertEquals([], $predicate->bindings()); |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
public function testConstructorWithArray() |
|
23
|
|
|
{ |
|
24
|
|
|
$predicate = new Predicate(['column']); |
|
25
|
|
|
$this->assertEquals('`column`', (string)$predicate); |
|
26
|
|
|
$this->assertEquals([], $predicate->bindings()); |
|
27
|
|
|
|
|
28
|
|
|
|
|
29
|
|
|
$predicate = new Predicate(['column'], '=', 'expression'); |
|
30
|
|
|
$this->assertEquals('`column` = expression', (string)$predicate); |
|
31
|
|
|
$this->assertEquals([], $predicate->bindings()); |
|
32
|
|
|
|
|
33
|
|
|
|
|
34
|
|
|
$predicate = new Predicate(['table', 'column'], '=', 'expression'); |
|
35
|
|
|
$this->assertEquals('`table`.`column` = expression', (string)$predicate); |
|
36
|
|
|
$this->assertEquals([], $predicate->bindings()); |
|
37
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
$predicate = new Predicate(['column'], '=', ['column_2']); |
|
40
|
|
|
$this->assertEquals('`column` = `column_2`', (string)$predicate); |
|
41
|
|
|
$this->assertEquals([], $predicate->bindings()); |
|
42
|
|
|
|
|
43
|
|
|
|
|
44
|
|
|
$predicate = new Predicate(['table', 'column'], '=', ['table_2', 'column_2']); |
|
45
|
|
|
$this->assertEquals('`table`.`column` = `table_2`.`column_2`', (string)$predicate); |
|
46
|
|
|
$this->assertEquals([], $predicate->bindings()); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
public function testWithValue() |
|
50
|
|
|
{ |
|
51
|
|
|
$predicate = new Predicate(['table', 'column'], '=', 'placeholder'); |
|
52
|
|
|
$predicate->withValue(3); |
|
53
|
|
|
$this->assertEquals('`table`.`column` = :placeholder', (string)$predicate); |
|
54
|
|
|
$this->assertEquals(['placeholder' => 3], $predicate->bindings()); |
|
55
|
|
|
|
|
56
|
|
|
$predicate = new Predicate(['table', 'column'], '=', 'placeholder'); |
|
57
|
|
|
$predicate->withValue(3, 'prefix'); |
|
58
|
|
|
$this->assertEquals('`table`.`column` = :prefix_placeholder', (string)$predicate); |
|
59
|
|
|
$this->assertEquals(['prefix_placeholder' => 3], $predicate->bindings()); |
|
60
|
|
|
|
|
61
|
|
|
$predicate = new Predicate(['table', 'column'], '='); |
|
62
|
|
|
$predicate->withValue(3, 'prefix'); |
|
63
|
|
|
$this->assertEquals('`table`.`column` = :prefix_table_column', (string)$predicate); |
|
64
|
|
|
$this->assertEquals(['prefix_table_column' => 3], $predicate->bindings()); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function testWithValues() |
|
68
|
|
|
{ |
|
69
|
|
|
$predicate = new Predicate('column'); |
|
70
|
|
|
$predicate->withValues(['value1', 'value2'], 'prefix'); |
|
71
|
|
|
|
|
72
|
|
|
$this->assertEquals('column IN (:prefix_column_0,:prefix_column_1)', (string)$predicate); |
|
73
|
|
|
$this->assertEquals(['prefix_column_0' => 'value1', 'prefix_column_1' => 'value2'], $predicate->bindings()); |
|
74
|
|
|
|
|
75
|
|
|
$predicate = new Predicate('column', 'IN', 'placeholder'); |
|
76
|
|
|
$predicate->withValues(['value1', 'value2'], 'prefix'); |
|
77
|
|
|
$this->assertEquals('column IN (:prefix_placeholder_0,:prefix_placeholder_1)', (string)$predicate); |
|
78
|
|
|
$this->assertEquals(['prefix_placeholder_0' => 'value1', 'prefix_placeholder_1' => 'value2'], $predicate->bindings()); |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
public function testIsNotEmpty() |
|
82
|
|
|
{ |
|
83
|
|
|
$expected = '(expression IS NOT NULL AND expression <> \'\')'; |
|
84
|
|
|
|
|
85
|
|
|
$predicate = new Predicate('expression'); |
|
86
|
|
|
$predicate->isNotEmpty(); |
|
87
|
|
|
$this->assertEquals($expected, (string)$predicate); |
|
88
|
|
|
|
|
89
|
|
|
$predicate = new Predicate('expression', '='); |
|
90
|
|
|
$predicate->isNotEmpty(); |
|
91
|
|
|
$this->assertEquals($expected, (string)$predicate); |
|
92
|
|
|
|
|
93
|
|
|
$predicate = new Predicate('expression', '=', 'something'); |
|
94
|
|
|
$predicate->isNotEmpty(); |
|
95
|
|
|
$this->assertEquals($expected, (string)$predicate); |
|
96
|
|
|
|
|
97
|
|
|
|
|
98
|
|
|
$predicate = new Predicate(['column']); |
|
99
|
|
|
$predicate->isNotEmpty(); |
|
100
|
|
|
$this->assertEquals('(`column` IS NOT NULL AND `column` <> \'\')', (string)$predicate); |
|
101
|
|
|
|
|
102
|
|
|
$predicate = new Predicate(['table', 'column']); |
|
103
|
|
|
$predicate->isNotEmpty(); |
|
104
|
|
|
$this->assertEquals('(`table`.`column` IS NOT NULL AND `table`.`column` <> \'\')', (string)$predicate); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function testIsEmpty() |
|
108
|
|
|
{ |
|
109
|
|
|
$expected = '(expression IS NULL OR expression = \'\')'; |
|
110
|
|
|
|
|
111
|
|
|
$predicate = new Predicate('expression'); |
|
112
|
|
|
$predicate->isEmpty(); |
|
113
|
|
|
$this->assertEquals($expected, (string)$predicate); |
|
114
|
|
|
|
|
115
|
|
|
$predicate = new Predicate('expression', '='); |
|
116
|
|
|
$predicate->isEmpty(); |
|
117
|
|
|
$this->assertEquals($expected, (string)$predicate); |
|
118
|
|
|
|
|
119
|
|
|
$predicate = new Predicate('expression', '=', 'something'); |
|
120
|
|
|
$predicate->isEmpty(); |
|
121
|
|
|
$this->assertEquals($expected, (string)$predicate); |
|
122
|
|
|
} |
|
123
|
|
|
} |
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:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths