Issues (259)

Tests/Mapping/EntityMappingTest.php (10 issues)

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\EntityMapping;
15
use Addiks\RDMBundle\Tests\Hydration\EntityExample;
16
use Doctrine\DBAL\Schema\Column;
17
use Doctrine\DBAL\Types\Type;
18
use Addiks\RDMBundle\Mapping\MappingInterface;
19
use Symfony\Component\DependencyInjection\ContainerInterface;
20
use Addiks\RDMBundle\Hydration\HydrationContextInterface;
21
22
final class EntityMappingTest extends TestCase
23
{
24
25
    /**
26
     * @var EntityMapping
27
     */
28
    private $entityMapping;
29
30
    /**
31
     * @var MappingInterface
32
     */
33
    private $fieldMappingA;
34
35
    /**
36
     * @var MappingInterface
37
     */
38
    private $fieldMappingB;
39
40
    public function setUp(): void
41
    {
42
        $this->fieldMappingA = $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 $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...
43
        $this->fieldMappingB = $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 $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...
44
45
        $this->entityMapping = new EntityMapping(EntityExample::class, [
46
            'fieldA' => $this->fieldMappingA,
47
            'fieldB' => $this->fieldMappingB,
48
        ]);
49
    }
50
51
    /**
52
     * @test
53
     */
54
    public function shouldStoreEntityName()
55
    {
56
        $this->assertEquals(EntityExample::class, $this->entityMapping->getEntityClassName());
57
    }
58
59
    /**
60
     * @test
61
     */
62
    public function shouldStoreClassName()
63
    {
64
        $this->assertEquals(EntityExample::class, $this->entityMapping->getClassName());
65
    }
66
67
    /**
68
     * @test
69
     */
70
    public function shouldHaveNoFactoryOrSerializer()
71
    {
72
        $this->assertSame(null, $this->entityMapping->getFactory());
0 ignored issues
show
Are you sure the usage of $this->entityMapping->getFactory() targeting Addiks\RDMBundle\Mapping...tyMapping::getFactory() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
73
        $this->assertSame(null, $this->entityMapping->getSerializer());
0 ignored issues
show
Are you sure the usage of $this->entityMapping->getSerializer() targeting Addiks\RDMBundle\Mapping...apping::getSerializer() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
74
    }
75
76
    /**
77
     * @test
78
     */
79
    public function shouldStoreFieldMappings()
80
    {
81
        $this->assertEquals([
82
            'fieldA' => $this->fieldMappingA,
83
            'fieldB' => $this->fieldMappingB,
84
        ], $this->entityMapping->getFieldMappings());
85
    }
86
87
    /**
88
     * @test
89
     */
90
    public function shouldDescribeOrigin()
91
    {
92
        $this->assertEquals(EntityExample::class, $this->entityMapping->describeOrigin());
93
    }
94
95
    /**
96
     * @test
97
     */
98
    public function shouldCollectColumns()
99
    {
100
        $columnA = new Column("column_a", Type::getType("string"), []);
101
        $columnB = new Column("column_b", Type::getType("string"), []);
102
103
        /** @var array<Column> $expectedColumns */
104
        $expectedColumns = [$columnA, $columnB];
105
106
        $this->fieldMappingA->method('collectDBALColumns')->willReturn([$columnA]);
0 ignored issues
show
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

106
        $this->fieldMappingA->/** @scrutinizer ignore-call */ 
107
                              method('collectDBALColumns')->willReturn([$columnA]);

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...
107
        $this->fieldMappingB->method('collectDBALColumns')->willReturn([$columnB]);
108
109
        $this->assertEquals($expectedColumns, $this->entityMapping->collectDBALColumns());
110
    }
111
112
    /**
113
     * @test
114
     */
115
    public function shouldStoreDBALColumn()
116
    {
117
        $this->assertNull($this->entityMapping->getDBALColumn());
0 ignored issues
show
Are you sure the usage of $this->entityMapping->getDBALColumn() targeting Addiks\RDMBundle\Mapping...apping::getDBALColumn() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
118
    }
119
120
    /**
121
     * @test
122
     */
123
    public function shouldStoreId()
124
    {
125
        $this->assertNull($this->entityMapping->getId());
0 ignored issues
show
Are you sure the usage of $this->entityMapping->getId() targeting Addiks\RDMBundle\Mapping\EntityMapping::getId() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
126
    }
127
128
    /**
129
     * @test
130
     */
131
    public function shouldStoreReferenceId()
132
    {
133
        $this->assertNull($this->entityMapping->getReferencedId());
0 ignored issues
show
Are you sure the usage of $this->entityMapping->getReferencedId() targeting Addiks\RDMBundle\Mapping...ping::getReferencedId() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
134
    }
135
136
    /**
137
     * @test
138
     */
139
    public function shouldNotResolveValue()
140
    {
141
        $this->assertEquals(
142
            [
143
                'fieldA' => null,
144
                'fieldB' => null
145
            ],
146
            $this->entityMapping->resolveValue(
147
                $this->createMock(HydrationContextInterface::class),
148
                []
149
            )
150
        );
151
    }
152
153
    /**
154
     * @test
155
     */
156
    public function shouldNotRevertValue()
157
    {
158
        $this->assertEmpty($this->entityMapping->revertValue(
159
            $this->createMock(HydrationContextInterface::class),
160
            null
161
        ));
162
    }
163
164
    /**
165
     * @test
166
     */
167
    public function shouldNotAssertValue()
168
    {
169
        $this->assertNull($this->entityMapping->assertValue(
0 ignored issues
show
Are you sure the usage of $this->entityMapping->as...:class), array(), null) targeting Addiks\RDMBundle\Mapping...yMapping::assertValue() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

The method getObject() can return nothing but null, so it makes no sense to use the return value.

The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.

Loading history...
170
            $this->createMock(HydrationContextInterface::class),
171
            [],
172
            null
173
        ));
174
    }
175
176
    /**
177
     * @test
178
     */
179
    public function shouldWakeUpInnerMapping()
180
    {
181
        /** @var ContainerInterface $container */
182
        $container = $this->createMock(ContainerInterface::class);
183
184
        $this->fieldMappingA->expects($this->once())->method("wakeUpMapping")->with(
0 ignored issues
show
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

184
        $this->fieldMappingA->/** @scrutinizer ignore-call */ 
185
                              expects($this->once())->method("wakeUpMapping")->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...
185
            $this->equalTo($container)
186
        );
187
188
        $this->fieldMappingB->expects($this->once())->method("wakeUpMapping")->with(
189
            $this->equalTo($container)
190
        );
191
192
        $this->entityMapping->wakeUpMapping($container);
193
    }
194
195
}
196