MappingProxyTest   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 125
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
eloc 40
c 2
b 0
f 2
dl 0
loc 125
rs 10
wmc 7

7 Methods

Rating   Name   Duplication   Size   Complexity  
A shouldForwardWakeUp() 0 10 1
A shouldForwardValueReverting() 0 11 1
A shouldPrefixCollectedColumns() 0 22 1
A shouldForwardOrigin() 0 8 1
A setUp() 0 5 1
A shouldForwardValueResolving() 0 11 1
A shouldForwardValueAssertion() 0 15 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\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(): void
35
    {
36
        $this->innerMapping = $this->createMock(MappingInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(Addiks...appingInterface::class) of type PHPUnit\Framework\MockObject\MockObject is incompatible with the declared type 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_");
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 exist on Addiks\RDMBundle\Mapping\MappingInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

49
        $this->innerMapping->/** @scrutinizer ignore-call */ 
50
                             method("describeOrigin")->willReturn($origin);

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 exist on Doctrine\DBAL\Schema\Column. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

61
        $column->/** @scrutinizer ignore-call */ 
62
                 method("getName")->willReturn("some_name");

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"));
63
        $column->method("toArray")->willReturn([
64
            'notnull' => true,
65
            'length' => 32
66
        ]);
67
68
        /** @var array<Column> $columns */
69
        $columns = [$column];
70
71
        $this->innerMapping->method("collectDBALColumns")->willReturn($columns);
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
    public function shouldForwardValueResolving()
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);
93
94
        $this->assertEquals($value, $this->proxy->resolveValue($context, []));
95
    }
96
97
    /**
98
     * @test
99
     */
100
    public function shouldForwardValueReverting()
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);
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
The assignment to $data is dead and can be removed.
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 exist on Addiks\RDMBundle\Mapping\MappingInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

124
        $this->innerMapping->/** @scrutinizer ignore-call */ 
125
                             expects($this->once())->method("assertValue")->with(

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
    public function shouldForwardWakeUp()
137
    {
138
        /** @var ContainerInterface $context */
139
        $container = $this->createMock(ContainerInterface::class);
140
141
        $this->innerMapping->expects($this->once())->method("wakeUpMapping")->with(
142
            $this->equalTo($container)
143
        );
144
145
        $this->proxy->wakeUpMapping($container);
146
    }
147
148
}
149