MappingDriverChainTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 59
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A shouldCollectMappingData() 0 27 1
A setUp() 0 8 1
1
<?php
2
/**
3
 * Copyright (C) 2018 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\Drivers;
12
13
use PHPUnit\Framework\TestCase;
14
use Addiks\RDMBundle\Tests\Hydration\EntityExample;
15
use Addiks\RDMBundle\Mapping\Annotation\Service;
16
use ReflectionProperty;
17
use Addiks\RDMBundle\Mapping\Drivers\MappingDriverChain;
18
use Addiks\RDMBundle\Mapping\Drivers\MappingDriverInterface;
19
use Addiks\RDMBundle\Mapping\EntityMapping;
20
use Addiks\RDMBundle\Mapping\ServiceMapping;
21
use Symfony\Component\DependencyInjection\ContainerInterface;
22
23
final class MappingDriverChainTest extends TestCase
24
{
25
26
    /**
27
     * @var MappingDriverChain
28
     */
29
    private $mappingDriver;
30
31
    /**
32
     * @var MappingDriverInterface
33
     */
34
    private $innerDriverA;
35
36
    /**
37
     * @var MappingDriverInterface
38
     */
39
    private $innerDriverB;
40
41
    public function setUp(): void
42
    {
43
        $this->innerDriverA = $this->createMock(MappingDriverInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(Addiks...DriverInterface::class) of type PHPUnit\Framework\MockObject\MockObject is incompatible with the declared type Addiks\RDMBundle\Mapping...\MappingDriverInterface of property $innerDriverA.

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
        $this->innerDriverB = $this->createMock(MappingDriverInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(Addiks...DriverInterface::class) of type PHPUnit\Framework\MockObject\MockObject is incompatible with the declared type Addiks\RDMBundle\Mapping...\MappingDriverInterface of property $innerDriverB.

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...
45
46
        $this->mappingDriver = new MappingDriverChain([
47
            $this->innerDriverA,
48
            $this->innerDriverB,
49
        ]);
50
    }
51
52
    /**
53
     * @test
54
     */
55
    public function shouldCollectMappingData()
56
    {
57
        $fieldMappingA = new ServiceMapping($this->createMock(ContainerInterface::class), "some_service");
58
        $fieldMappingB = new ServiceMapping($this->createMock(ContainerInterface::class), "other_service");
59
60
        /** @var array<Service> $expectedAnnotations */
61
        $expectedFieldMappings = [
62
            'foo' => $fieldMappingA,
63
            'bar' => $fieldMappingB
64
        ];
65
66
        $this->innerDriverA->method('loadRDMMetadataForClass')->willReturn(
0 ignored issues
show
Bug introduced by
The method method() does not exist on Addiks\RDMBundle\Mapping...\MappingDriverInterface. ( Ignorable by Annotation )

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

66
        $this->innerDriverA->/** @scrutinizer ignore-call */ 
67
                             method('loadRDMMetadataForClass')->willReturn(

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...
67
            new EntityMapping(EntityExample::class, [
68
                'foo' => $fieldMappingA
69
            ])
70
        );
71
72
        $this->innerDriverB->method('loadRDMMetadataForClass')->willReturn(
73
            new EntityMapping(EntityExample::class, [
74
                'bar' => $fieldMappingB
75
            ])
76
        );
77
78
        /** @var EntityMapping $actualMapping */
79
        $actualMapping = $this->mappingDriver->loadRDMMetadataForClass(EntityExample::class);
80
81
        $this->assertEquals($expectedFieldMappings, $actualMapping->getFieldMappings());
82
    }
83
84
}
85