Passed
Push — master ( 23152a...a65783 )
by Povilas
02:36
created

JoinFieldTest   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 11
eloc 28
dl 0
loc 90
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A testGetAlias() 0 4 1
A testInvalidOptionsThrowsException() 0 4 1
A testGetJoinPath() 0 7 1
A testOptions() 0 6 2
A idProvider() 0 5 1
A testGetProperty() 0 4 1
A pathsProvider() 0 4 1
A getPaths() 0 3 1
A getField() 0 3 1
A testSetAlias() 0 5 1
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()];
0 ignored issues
show
Bug introduced by
The method getPath() does not exist on Povs\ListerBundle\Mapper\AbstractField. It seems like you code against a sub-type of Povs\ListerBundle\Mapper\AbstractField such as Povs\ListerBundle\Mapper\JoinField. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

99
        return [$field->/** @scrutinizer ignore-call */ getPath()];
Loading history...
100
    }
101
}
102