Passed
Push — master ( 356755...14835f )
by Gerrit
04:25
created

NullableMappingTest::shouldHaveOrigin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
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;
12
13
use PHPUnit\Framework\TestCase;
14
use Addiks\RDMBundle\Mapping\NullableMapping;
15
use Doctrine\DBAL\Schema\Column;
16
use Addiks\RDMBundle\Mapping\MappingInterface;
17
18
final class NullableMappingTest extends TestCase
19
{
20
21
    /**
22
     * @var NullableMapping
23
     */
24
    private $mapping;
25
26
    /**
27
     * @var MappingInterface
28
     */
29
    private $innerMapping;
30
31
    /**
32
     * @var Column
33
     */
34
    private $dbalColumn;
35
36
    public function setUp()
37
    {
38
        $this->innerMapping = $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 $innerMapping.

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...
39
        $this->dbalColumn = $this->createMock(Column::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Doctr...L\Schema\Column::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Doctrine\DBAL\Schema\Column> of property $dbalColumn.

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
41
        $this->mapping = new NullableMapping($this->innerMapping, $this->dbalColumn, "some origin");
0 ignored issues
show
Documentation introduced by
$this->innerMapping is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Addiks\RDMBundle\Mapping\MappingInterface>.

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...
Documentation introduced by
$this->dbalColumn is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a null|object<Doctrine\DBAL\Schema\Column>.

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...
42
    }
43
44
    /**
45
     * @test
46
     */
47
    public function shouldHaveDBALColumn()
48
    {
49
        $this->assertSame($this->dbalColumn, $this->mapping->getDBALColumn());
50
    }
51
52
    /**
53
     * @test
54
     */
55
    public function shouldHaveDeterminatorColumnName()
56
    {
57
        $this->dbalColumn->method('getName')->willReturn("some_column");
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Doctrine\DBAL\Schema\Column>.

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...
58
        $this->assertSame("some_column", $this->mapping->getDeterminatorColumnName());
59
    }
60
61
    /**
62
     * @test
63
     */
64
    public function shouldHaveInnerMapping()
65
    {
66
        $this->assertSame($this->innerMapping, $this->mapping->getInnerMapping());
67
    }
68
69
    /**
70
     * @test
71
     */
72
    public function shouldHaveOrigin()
73
    {
74
        $this->assertSame("some origin", $this->mapping->describeOrigin());
75
    }
76
77
    /**
78
     * @test
79
     */
80
    public function shouldCollectDBALColumns()
81
    {
82
        /** @var Column $innerColumn */
83
        $innerColumn = $this->createMock(Column::class);
84
85
        $this->innerMapping->method('collectDBALColumns')->willReturn([$innerColumn]);
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...
86
87
        /** @var mixed $expectedColumns */
88
        $expectedColumns = array(
89
            $innerColumn,
90
            $this->dbalColumn
91
        );
92
93
        /** @var mixed $actualColumns */
94
        $actualColumns = $this->mapping->collectDBALColumns();
95
96
        $this->assertSame($expectedColumns, $actualColumns);
97
    }
98
99
}
100