Completed
Push — master ( 203e38...2cdd54 )
by Gerrit
13:04
created

ChoiceMappingTest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 103
rs 10
c 1
b 1
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 17 1
A shouldHaveChoices() 0 4 1
A shouldDescribeOrigin() 0 4 1
B shouldCollectColumns() 0 25 1
A shouldHaveDeterminatorColumn() 0 9 1
A shouldHaveADeterminatorColumnName() 0 4 1
1
<?php
2
/**
3
 * Copyright (C) 2017  Gerrit Addiks.
4
 * This package (including this file) was released under the terms of the GPL-3.0.
5
 * You should have received a copy of the GNU General Public License along with this program.
6
 * If not, see <http://www.gnu.org/licenses/> or send me a mail so i can send you a copy.
7
 * @license GPL-3.0
8
 * @author Gerrit Addiks <[email protected]>
9
 */
10
11
namespace Addiks\RDMBundle\Tests\Mapping;
12
13
use PHPUnit\Framework\TestCase;
14
use Addiks\RDMBundle\Mapping\ChoiceMapping;
15
use Doctrine\DBAL\Schema\Column;
16
use Doctrine\DBAL\Types\Type;
17
use Addiks\RDMBundle\Mapping\MappingInterface;
18
19
final class ChoiceMappingTest extends TestCase
20
{
21
22
    /**
23
     * @var ChoiceMapping
24
     */
25
    private $choiceMapping;
26
27
    /**
28
     * @var MappingInterface
29
     */
30
    private $optionMappingA;
31
32
    /**
33
     * @var MappingInterface
34
     */
35
    private $optionMappingB;
36
37
    public function setUp()
38
    {
39
        $this->optionMappingA = $this->createMock(MappingInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Addik...appingInterface::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Addiks\RDMBundle\Mapping\MappingInterface> of property $optionMappingA.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
40
        $this->optionMappingB = $this->createMock(MappingInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Addik...appingInterface::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Addiks\RDMBundle\Mapping\MappingInterface> of property $optionMappingB.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
41
42
        $this->choiceMapping = new ChoiceMapping(
43
            new Column("some_column_name", Type::getType('string'), [
44
                'notnull' => false,
45
                'length' => 255
46
            ]),
47
            [
48
                $this->optionMappingA,
49
                $this->optionMappingB,
50
            ],
51
            "in foo_file at bar_line!"
52
        );
53
    }
54
55
    /**
56
     * @test
57
     */
58
    public function shouldHaveChoices()
59
    {
60
        $this->assertEquals([$this->optionMappingA, $this->optionMappingB], $this->choiceMapping->getChoices());
61
    }
62
63
    /**
64
     * @test
65
     */
66
    public function shouldDescribeOrigin()
67
    {
68
        $this->assertEquals("in foo_file at bar_line!", $this->choiceMapping->describeOrigin());
69
    }
70
71
    /**
72
     * @test
73
     */
74
    public function shouldCollectColumns()
75
    {
76
        $choiceColumn = new Column("some_column_name", Type::getType('string'), [
77
            'notnull' => false,
78
            'length' => 255
79
        ]);
80
81
        $columnA = new Column("foo_column", Type::getType('integer'), []);
82
        $columnB = new Column("bar_column", Type::getType('date'), []);
83
84
        /** @var array<Column> $expectedColumns */
85
        $expectedColumns = array(
86
            $choiceColumn,
87
            $columnA,
88
            $columnB,
89
        );
90
91
        $this->optionMappingA->method('collectDBALColumns')->willReturn([$columnA]);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\RDMBundle\Mapping\MappingInterface>.

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.

Loading history...
92
        $this->optionMappingB->method('collectDBALColumns')->willReturn([$columnB]);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\RDMBundle\Mapping\MappingInterface>.

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.

Loading history...
93
94
        /** @var array<Column> $actualColumns */
95
        $actualColumns = $this->choiceMapping->collectDBALColumns();
96
97
        $this->assertEquals($expectedColumns, $actualColumns);
98
    }
99
100
    /**
101
     * @test
102
     */
103
    public function shouldHaveDeterminatorColumn()
104
    {
105
        $expectedColumn = new Column("some_column_name", Type::getType('string'), [
106
            'notnull' => false,
107
            'length' => 255
108
        ]);
109
110
        $this->assertEquals($expectedColumn, $this->choiceMapping->getDeterminatorColumn());
111
    }
112
113
    /**
114
     * @test
115
     */
116
    public function shouldHaveADeterminatorColumnName()
117
    {
118
        $this->assertEquals("some_column_name", $this->choiceMapping->getDeterminatorColumnName());
119
    }
120
121
}
122