Completed
Push — master ( 840912...a35e08 )
by Gerrit
03:16
created

MappingProxyTest::setUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
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
20
final class MappingProxyTest extends TestCase
21
{
22
23
    /**
24
     * @var MappingProxy
25
     */
26
    private $proxy;
27
28
    /**
29
     * @var MappingInterface
30
     */
31
    private $innerMapping;
32
33
    public function setUp()
34
    {
35
        $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...
36
37
        $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...
38
    }
39
40
    /**
41
     * @test
42
     */
43
    public function shouldForwardOrigin()
44
    {
45
        /** @var string $origin */
46
        $origin = "some origin!";
47
48
        $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...
49
50
        $this->assertEquals($origin, $this->proxy->describeOrigin());
51
    }
52
53
    /**
54
     * @test
55
     */
56
    public function shouldForwardCollectedColumns()
57
    {
58
        /** @var array<Column> $columns */
59
        $columns = [$this->createMock(Column::class)];
60
61
        $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...
62
63
        $this->assertEquals($columns, $this->proxy->collectDBALColumns());
64
    }
65
66
    /**
67
     * @test
68
     */
69 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...
70
    {
71
        /** @var string $value */
72
        $value = "Lorem ipsum";
73
74
        /** @var HydrationContextInterface $context */
75
        $context = $this->createMock(HydrationContextInterface::class);
76
77
        $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...
78
79
        $this->assertEquals($value, $this->proxy->resolveValue($context, []));
80
    }
81
82
    /**
83
     * @test
84
     */
85 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...
86
    {
87
        /** @var array<string, string> $data */
88
        $data = ["column" => "Lorem ipsum"];
89
90
        /** @var HydrationContextInterface $context */
91
        $context = $this->createMock(HydrationContextInterface::class);
92
93
        $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...
94
95
        $this->assertEquals($data, $this->proxy->revertValue($context, []));
96
    }
97
98
    /**
99
     * @test
100
     */
101
    public function shouldForwardValueAssertion()
102
    {
103
        /** @var array<string, string> $data */
104
        $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...
105
106
        /** @var HydrationContextInterface $context */
107
        $context = $this->createMock(HydrationContextInterface::class);
108
109
        $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...
110
            $this->equalTo($context),
111
            $this->equalTo([]),
112
            $this->equalTo("Lorem ipsum")
113
        );
114
115
        $this->proxy->assertValue($context, [], 'Lorem ipsum');
116
    }
117
118
    /**
119
     * @test
120
     */
121 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...
122
    {
123
        /** @var ContainerInterface $context */
124
        $container = $this->createMock(ContainerInterface::class);
125
126
        $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...
127
            $this->equalTo($container)
128
        );
129
130
        $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...
131
    }
132
133
}
134