MappingDriverChainFactoryTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A shouldCreatedChainedMappingDriver() 0 36 1
A setUp() 0 6 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\DriverFactories;
12
13
use PHPUnit\Framework\TestCase;
14
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
15
use Doctrine\Persistence\Mapping\Driver\MappingDriverChain as DoctrineMappingDriverChain;
16
use Addiks\RDMBundle\Mapping\DriverFactories\MappingDriverFactoryInterface;
17
use Addiks\RDMBundle\Mapping\DriverFactories\MappingDriverChainFactory;
18
use Addiks\RDMBundle\Mapping\Drivers\MappingDriverInterface;
19
use Addiks\RDMBundle\Mapping\Drivers\MappingDriverChain as RdmMappingDriverChain;
20
use Addiks\RDMBundle\Tests\Hydration\EntityExample;
21
22
final class MappingDriverChainFactoryTest extends TestCase
23
{
24
25
    /**
26
     * @var MappingDriverChainFactory
27
     */
28
    private $driverFactory;
29
30
    /**
31
     * @var MappingDriverFactoryInterface
32
     */
33
    private $rootMetadataDriverFactory;
34
35
    public function setUp(): void
36
    {
37
        $this->rootMetadataDriverFactory = $this->createMock(MappingDriverFactoryInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(Addiks...actoryInterface::class) of type PHPUnit\Framework\MockObject\MockObject is incompatible with the declared type Addiks\RDMBundle\Mapping...gDriverFactoryInterface of property $rootMetadataDriverFactory.

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...
38
39
        $this->driverFactory = new MappingDriverChainFactory(
40
            $this->rootMetadataDriverFactory
41
        );
42
    }
43
44
    /**
45
     * @test
46
     */
47
    public function shouldCreatedChainedMappingDriver()
48
    {
49
        /** @var DoctrineMappingDriverChain $mappingDriver */
50
        $mappingDriver = $this->createMock(DoctrineMappingDriverChain::class);
51
52
        /** @var MappingDriver $innerDriverA */
53
        $innerDriverA = $this->createMock(MappingDriver::class);
54
55
        /** @var MappingDriver $innerDriverB */
56
        $innerDriverB = $this->createMock(MappingDriver::class);
57
58
        /** @var MappingDriverInterface $innerRdmMappingDriverA */
59
        $innerRdmMappingDriverA = $this->createMock(MappingDriverInterface::class);
60
61
        /** @var MappingDriverInterface $innerRdmMappingDriverB */
62
        $innerRdmMappingDriverB = $this->createMock(MappingDriverInterface::class);
63
64
        $innerRdmMappingDriverA->expects($this->once())->method('loadRDMMetadataForClass');
0 ignored issues
show
Bug introduced by
The method expects() 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

64
        $innerRdmMappingDriverA->/** @scrutinizer ignore-call */ 
65
                                 expects($this->once())->method('loadRDMMetadataForClass');

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...
65
        $innerRdmMappingDriverB->expects($this->once())->method('loadRDMMetadataForClass');
66
67
        $this->rootMetadataDriverFactory->method('createRDMMappingDriver')->will($this->returnValueMap([
0 ignored issues
show
Bug introduced by
The method method() does not exist on Addiks\RDMBundle\Mapping...gDriverFactoryInterface. ( Ignorable by Annotation )

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

67
        $this->rootMetadataDriverFactory->/** @scrutinizer ignore-call */ 
68
                                          method('createRDMMappingDriver')->will($this->returnValueMap([

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...
68
            [$innerDriverA, $innerRdmMappingDriverA],
69
            [$innerDriverB, $innerRdmMappingDriverB],
70
        ]));
71
72
        $mappingDriver->method('getDrivers')->willReturn([
0 ignored issues
show
Bug introduced by
The method method() does not exist on Doctrine\Persistence\Map...iver\MappingDriverChain. ( Ignorable by Annotation )

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

72
        $mappingDriver->/** @scrutinizer ignore-call */ 
73
                        method('getDrivers')->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...
73
            $innerDriverA,
74
            $innerDriverB
75
        ]);
76
77
        /** @var RdmMappingDriverChain $rdmMappingDriver */
78
        $rdmMappingDriver = $this->driverFactory->createRDMMappingDriver($mappingDriver);
79
80
        $this->assertInstanceOf(RdmMappingDriverChain::class, $rdmMappingDriver);
81
82
        $rdmMappingDriver->loadRDMMetadataForClass(EntityExample::class);
83
    }
84
85
}
86