Passed
Push — master ( 8b21d0...6a3b4a )
by Gerrit
03:23
created

MappingProxyTest::shouldPrefixCollectedColumns()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 23
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 23
rs 9.0856
c 1
b 0
f 1
cc 1
eloc 14
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\MappingProxy;
15
use Addiks\RDMBundle\Mapping\MappingInterface;
16
use Doctrine\DBAL\Schema\Column;
17
use Addiks\RDMBundle\Hydration\HydrationContextInterface;
18
use Symfony\Component\DependencyInjection\ContainerInterface;
19
use Doctrine\DBAL\Types\Type;
20
21
final class MappingProxyTest extends TestCase
22
{
23
24
    /**
25
     * @var MappingProxy
26
     */
27
    private $proxy;
28
29
    /**
30
     * @var MappingInterface
31
     */
32
    private $innerMapping;
33
34
    public function setUp()
35
    {
36
        $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...
37
38
        $this->proxy = new MappingProxy($this->innerMapping, "prefix_");
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...
39
    }
40
41
    /**
42
     * @test
43
     */
44
    public function shouldForwardOrigin()
45
    {
46
        /** @var string $origin */
47
        $origin = "some origin!";
48
49
        $this->innerMapping->method("describeOrigin")->willReturn($origin);
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...
50
51
        $this->assertEquals($origin, $this->proxy->describeOrigin());
52
    }
53
54
    /**
55
     * @test
56
     */
57
    public function shouldPrefixCollectedColumns()
58
    {
59
        /** @var Column $column */
60
        $column = $this->createMock(Column::class);
61
        $column->method("getName")->willReturn("some_name");
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...
62
        $column->method("getType")->willReturn(Type::getType("string"));
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...
63
        $column->method("toArray")->willReturn([
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...
64
            'notnull' => true,
65
            'length' => 32
66
        ]);
67
68
        /** @var array<Column> $columns */
69
        $columns = [$column];
70
71
        $this->innerMapping->method("collectDBALColumns")->willReturn($columns);
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...
72
73
        $this->assertEquals([
74
            new Column("prefix_some_name", Type::getType("string"), [
75
                'notnull' => true,
76
                'length' => 32
77
            ])
78
        ], $this->proxy->collectDBALColumns());
79
    }
80
81
    /**
82
     * @test
83
     */
84 View Code Duplication
    public function shouldForwardValueResolving()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
85
    {
86
        /** @var string $value */
87
        $value = "Lorem ipsum";
88
89
        /** @var HydrationContextInterface $context */
90
        $context = $this->createMock(HydrationContextInterface::class);
91
92
        $this->innerMapping->method("resolveValue")->willReturn($value);
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
        $this->assertEquals($value, $this->proxy->resolveValue($context, []));
95
    }
96
97
    /**
98
     * @test
99
     */
100 View Code Duplication
    public function shouldForwardValueReverting()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
101
    {
102
        /** @var array<string, string> $data */
103
        $data = ["column" => "Lorem ipsum"];
104
105
        /** @var HydrationContextInterface $context */
106
        $context = $this->createMock(HydrationContextInterface::class);
107
108
        $this->innerMapping->method("revertValue")->willReturn($data);
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
110
        $this->assertEquals($data, $this->proxy->revertValue($context, []));
111
    }
112
113
    /**
114
     * @test
115
     */
116
    public function shouldForwardValueAssertion()
117
    {
118
        /** @var array<string, string> $data */
119
        $data = ["column" => "Lorem ipsum"];
0 ignored issues
show
Unused Code introduced by
$data is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
120
121
        /** @var HydrationContextInterface $context */
122
        $context = $this->createMock(HydrationContextInterface::class);
123
124
        $this->innerMapping->expects($this->once())->method("assertValue")->with(
0 ignored issues
show
Bug introduced by
The method expects() 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...
125
            $this->equalTo($context),
126
            $this->equalTo([]),
127
            $this->equalTo("Lorem ipsum")
128
        );
129
130
        $this->proxy->assertValue($context, [], 'Lorem ipsum');
131
    }
132
133
    /**
134
     * @test
135
     */
136 View Code Duplication
    public function shouldForwardWakeUp()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
137
    {
138
        /** @var ContainerInterface $context */
139
        $container = $this->createMock(ContainerInterface::class);
140
141
        $this->innerMapping->expects($this->once())->method("wakeUpMapping")->with(
0 ignored issues
show
Bug introduced by
The method expects() 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...
142
            $this->equalTo($container)
143
        );
144
145
        $this->proxy->wakeUpMapping($container);
0 ignored issues
show
Documentation introduced by
$container is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...ion\ContainerInterface>.

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...
146
    }
147
148
}
149