|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Povs\ListerBundle\Mapper; |
|
4
|
|
|
|
|
5
|
|
|
use Povs\ListerBundle\Exception\ListFieldException; |
|
6
|
|
|
|
|
7
|
|
|
/** |
|
8
|
|
|
* @author Povilas Margaiatis <[email protected]> |
|
9
|
|
|
*/ |
|
10
|
|
|
class JoinFieldTest extends AbstractFieldTest |
|
11
|
|
|
{ |
|
12
|
|
|
private static $passedOptions = []; |
|
13
|
|
|
|
|
14
|
|
|
private static $expectedOptions = [ |
|
15
|
|
|
'join_type' => 'INNER', |
|
16
|
|
|
'lazy' => false |
|
17
|
|
|
]; |
|
18
|
|
|
|
|
19
|
|
|
public function testGetJoinPath(): void |
|
20
|
|
|
{ |
|
21
|
|
|
$parent = new JoinField('parent_path', 'parent_prop', 'parent_alias', [], null); |
|
22
|
|
|
$child = new JoinField('child_path', 'child_prop', 'child_alias', [], $parent); |
|
23
|
|
|
|
|
24
|
|
|
$this->assertEquals('alias.parent_prop', $parent->getJoinPath('alias')); |
|
25
|
|
|
$this->assertEquals('parent_alias.child_prop', $child->getJoinPath('alias')); |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public function testGetProperty(): void |
|
29
|
|
|
{ |
|
30
|
|
|
$field = new JoinField('path', 'prop', 'alias', [], null); |
|
31
|
|
|
$this->assertEquals('prop', $field->getProperty()); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function testGetAlias(): void |
|
35
|
|
|
{ |
|
36
|
|
|
$field = new JoinField('path', 'prop', 'alias', [], null); |
|
37
|
|
|
$this->assertEquals('alias', $field->getAlias()); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function testSetAlias(): void |
|
41
|
|
|
{ |
|
42
|
|
|
$field = new JoinField('path', 'prop', 'alias', [], null); |
|
43
|
|
|
$field->setAlias('new_alias'); |
|
44
|
|
|
$this->assertEquals('new_alias', $field->getAlias()); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testOptions(): void |
|
48
|
|
|
{ |
|
49
|
|
|
$field = new JoinField('path', 'prop', 'alias', self::$passedOptions, null); |
|
50
|
|
|
|
|
51
|
|
|
foreach (self::$expectedOptions as $option => $value) { |
|
52
|
|
|
$this->assertEquals($value, $field->getOption($option)); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function testInvalidOptionsThrowsException(): void |
|
57
|
|
|
{ |
|
58
|
|
|
$this->expectException(ListFieldException::class); |
|
59
|
|
|
$this->getField(['id', 'id', 'id', ['invalid_option' => true], null]); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @return array [data[], expectedId] |
|
64
|
|
|
*/ |
|
65
|
|
|
public function idProvider(): array |
|
66
|
|
|
{ |
|
67
|
|
|
return [ |
|
68
|
|
|
[['id', 'id', 'id', [], null], 'id'], |
|
69
|
|
|
[['test.dot.conversion', 'id', 'id', [], null], 'test_dot_conversion'] |
|
70
|
|
|
]; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* @return array [data[], expectedPaths[], exception] |
|
75
|
|
|
*/ |
|
76
|
|
|
public function pathsProvider(): array |
|
77
|
|
|
{ |
|
78
|
|
|
return [ |
|
79
|
|
|
[['id', 'id', 'id', [], null], ['id'], null] |
|
80
|
|
|
]; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @param array $data |
|
85
|
|
|
* @return JoinField |
|
86
|
|
|
*/ |
|
87
|
|
|
protected function getField(array $data = null): AbstractField |
|
88
|
|
|
{ |
|
89
|
|
|
return new JoinField($data[0], $data[1], $data[2], $data[3], $data[4]); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @param AbstractField|JoinField $field |
|
94
|
|
|
* |
|
95
|
|
|
* @return array |
|
96
|
|
|
*/ |
|
97
|
|
|
protected function getPaths(AbstractField $field): array |
|
98
|
|
|
{ |
|
99
|
|
|
return [$field->getPath()]; |
|
100
|
|
|
} |
|
101
|
|
|
} |
|
102
|
|
|
|