|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Janisbiz\LightOrm\Tests\Unit\Dms\MySQL\QueryBuilder\Traits; |
|
4
|
|
|
|
|
5
|
|
|
use Janisbiz\LightOrm\Dms\MySQL\QueryBuilder\QueryBuilderException; |
|
6
|
|
|
use Janisbiz\LightOrm\Dms\MySQL\QueryBuilder\Traits\ColumnTrait; |
|
7
|
|
|
|
|
8
|
|
|
class ColumnTraitTest extends AbstractTraitTestCase |
|
9
|
|
|
{ |
|
10
|
|
|
const COLUMN_DEFAULT = [ |
|
11
|
|
|
'column1', |
|
12
|
|
|
'column2', |
|
13
|
|
|
]; |
|
14
|
|
|
const COLUMN_ARRAY = [ |
|
15
|
|
|
'column3', |
|
16
|
|
|
'column4', |
|
17
|
|
|
]; |
|
18
|
|
|
const COLUMN_EMPTY = ''; |
|
19
|
|
|
const COLUMN = 'column5'; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var ColumnTrait |
|
23
|
|
|
*/ |
|
24
|
|
|
private $columnTraitClass; |
|
25
|
|
|
|
|
26
|
|
|
public function setUp() |
|
27
|
|
|
{ |
|
28
|
|
|
$this->columnTraitClass = new class (ColumnTraitTest::COLUMN_DEFAULT) |
|
29
|
|
|
{ |
|
30
|
|
|
use ColumnTrait; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param array $columnDefault |
|
34
|
|
|
*/ |
|
35
|
|
|
public function __construct(array $columnDefault) |
|
36
|
|
|
{ |
|
37
|
|
|
$this->column = $columnDefault; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @return array |
|
42
|
|
|
*/ |
|
43
|
|
|
public function columnData(): array |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->column; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function clearColumnData() |
|
49
|
|
|
{ |
|
50
|
|
|
$this->column = []; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @return string |
|
55
|
|
|
*/ |
|
56
|
|
|
public function buildColumnQueryPartPublic(): string |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->buildColumnQueryPart(); |
|
59
|
|
|
} |
|
60
|
|
|
}; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function testColumn() |
|
64
|
|
|
{ |
|
65
|
|
|
$this->assertEquals(static::COLUMN_DEFAULT, $this->columnTraitClass->columnData()); |
|
|
|
|
|
|
66
|
|
|
|
|
67
|
|
|
$object = $this->columnTraitClass->column(static::COLUMN_ARRAY); |
|
68
|
|
|
$this->assertObjectUsesTrait(ColumnTrait::class, $object); |
|
69
|
|
|
$this->assertEquals( |
|
70
|
|
|
\array_merge(static::COLUMN_DEFAULT, static::COLUMN_ARRAY), |
|
71
|
|
|
$this->columnTraitClass->columnData() |
|
72
|
|
|
); |
|
73
|
|
|
|
|
74
|
|
|
$object = $this->columnTraitClass->column(static::COLUMN); |
|
75
|
|
|
$this->assertObjectUsesTrait(ColumnTrait::class, $object); |
|
76
|
|
|
$this->assertEquals( |
|
77
|
|
|
\array_merge(static::COLUMN_DEFAULT, static::COLUMN_ARRAY, [static::COLUMN]), |
|
78
|
|
|
$this->columnTraitClass->columnData() |
|
79
|
|
|
); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
public function testColumnClearAll() |
|
83
|
|
|
{ |
|
84
|
|
|
$this->columnTraitClass->column(static::COLUMN, true); |
|
85
|
|
|
$this->assertEquals([static::COLUMN], $this->columnTraitClass->columnData()); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
public function testColumnWhenEmpty() |
|
89
|
|
|
{ |
|
90
|
|
|
$this->expectException(QueryBuilderException::class); |
|
91
|
|
|
$this->expectExceptionMessage('You must pass $column to column method!'); |
|
92
|
|
|
|
|
93
|
|
|
$this->columnTraitClass->column(static::COLUMN_EMPTY); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
public function testBuildColumnQueryPart() |
|
97
|
|
|
{ |
|
98
|
|
|
$this->columnTraitClass->column(static::COLUMN); |
|
99
|
|
|
|
|
100
|
|
|
$this->assertEquals( |
|
101
|
|
|
\implode(', ', $this->columnTraitClass->columnData()), |
|
102
|
|
|
$this->columnTraitClass->buildColumnQueryPartPublic() |
|
|
|
|
|
|
103
|
|
|
); |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
public function testBuildColumnQueryPartWhenEmpty() |
|
107
|
|
|
{ |
|
108
|
|
|
$this->columnTraitClass->clearColumnData(); |
|
|
|
|
|
|
109
|
|
|
|
|
110
|
|
|
$this->assertEquals('*', $this->columnTraitClass->buildColumnQueryPartPublic()); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.