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

ObjectMappingTest::shouldCollectDBALColumns()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
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\ObjectMapping;
15
use Addiks\RDMBundle\Mapping\CallDefinitionInterface;
16
use Addiks\RDMBundle\Tests\ValueObjectExample;
17
use Addiks\RDMBundle\Mapping\MappingInterface;
18
use Doctrine\DBAL\Schema\Column;
19
20
final class ObjectMappingTest extends TestCase
21
{
22
23
    /**
24
     * @var ObjectMapping
25
     */
26
    private $subject;
27
28
    /**
29
     * @var CallDefinitionInterface
30
     */
31
    private $factory;
32
33
    /**
34
     * @var CallDefinitionInterface
35
     */
36
    private $serializer;
37
38
    /**
39
     * @var MappingInterface
40
     */
41
    private $fieldMappingA;
42
43
    /**
44
     * @var MappingInterface
45
     */
46
    private $fieldMappingB;
47
48
    public function setUp()
49
    {
50
        $this->factory = $this->createMock(CallDefinitionInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Addik...nitionInterface::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Addiks\RDMBundle\...allDefinitionInterface> of property $factory.

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...
51
        $this->serializer = $this->createMock(CallDefinitionInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Addik...nitionInterface::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Addiks\RDMBundle\...allDefinitionInterface> of property $serializer.

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...
52
        $this->fieldMappingA = $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 $fieldMappingA.

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...
53
        $this->fieldMappingB = $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 $fieldMappingB.

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...
54
55
        $this->subject = new ObjectMapping(
56
            ValueObjectExample::class,
57
            [
58
                $this->fieldMappingA,
59
                $this->fieldMappingB,
60
            ],
61
            "some cool origin",
62
            $this->factory,
0 ignored issues
show
Documentation introduced by
$this->factory is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a null|object<Addiks\RDMBu...allDefinitionInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
63
            $this->serializer
0 ignored issues
show
Documentation introduced by
$this->serializer is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a null|object<Addiks\RDMBu...allDefinitionInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
64
        );
65
    }
66
67
    /**
68
     * @test
69
     */
70
    public function shouldStoreClassName()
71
    {
72
        $this->assertEquals(ValueObjectExample::class, $this->subject->getClassName());
73
    }
74
75
    /**
76
     * @test
77
     */
78
    public function shouldStoreFieldMappings()
79
    {
80
        $this->assertEquals([
81
            $this->createMock(MappingInterface::class),
82
            $this->createMock(MappingInterface::class),
83
        ], $this->subject->getFieldMappings());
84
    }
85
86
    /**
87
     * @test
88
     */
89
    public function shouldStoreOrigin()
90
    {
91
        $this->assertEquals("some cool origin", $this->subject->describeOrigin());
92
    }
93
94
    /**
95
     * @test
96
     */
97
    public function shouldCollectDBALColumns()
98
    {
99
        /** @var Column $columnA */
100
        $columnA = $this->createMock(Column::class);
101
102
        /** @var Column $columnB */
103
        $columnB = $this->createMock(Column::class);
104
105
        /** @var array<Column> $expectedColumns */
106
        $expectedColumns = [$columnA, $columnB];
107
108
        $this->fieldMappingA->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...
109
        $this->fieldMappingB->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...
110
111
        $this->assertEquals($expectedColumns, $this->subject->collectDBALColumns());
112
    }
113
114
    /**
115
     * @test
116
     */
117
    public function shouldStoreFactory()
118
    {
119
        $this->assertSame($this->factory, $this->subject->getFactory());
120
    }
121
122
    /**
123
     * @test
124
     */
125
    public function shouldStoreSerializer()
126
    {
127
        $this->assertSame($this->serializer, $this->subject->getSerializer());
128
    }
129
130
}
131