MappingYamlDriverTest::setUp()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 8
rs 10
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\Drivers\MappingDriverInterface;
16
use Addiks\RDMBundle\Mapping\Drivers\MappingYamlDriver;
17
use Addiks\RDMBundle\Mapping\EntityMapping;
18
use Addiks\RDMBundle\Mapping\ServiceMapping;
19
use Addiks\RDMBundle\Mapping\ChoiceMapping;
20
use Symfony\Component\DependencyInjection\ContainerInterface;
21
use Doctrine\Persistence\Mapping\Driver\FileLocator;
22
23
final class MappingYamlDriverTest extends TestCase
24
{
25
26
    /**
27
     * @var MappingYamlDriver
28
     */
29
    private $mappingDriver;
30
31
    /**
32
     * @var MappingDriverInterface
33
     */
34
    private $fileLocator;
35
36
    /**
37
     * @var ContainerInterface
38
     */
39
    private $container;
40
41
    public function setUp(): void
42
    {
43
        $this->fileLocator = $this->createMock(FileLocator::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(Doctri...ver\FileLocator::class) of type PHPUnit\Framework\MockObject\MockObject is incompatible with the declared type Addiks\RDMBundle\Mapping...\MappingDriverInterface of property $fileLocator.

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->container = $this->createMock(ContainerInterface::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(Symfon...tainerInterface::class) of type PHPUnit\Framework\MockObject\MockObject is incompatible with the declared type Symfony\Component\Depend...tion\ContainerInterface of property $container.

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 MappingYamlDriver(
47
            $this->container,
48
            $this->fileLocator
49
        );
50
    }
51
52
    /**
53
     * @test
54
     */
55
    public function shouldReadMappingData()
56
    {
57
        /** @var string $mappingFilePath */
58
        $mappingFilePath = __DIR__ . "/EntityExample.orm.yml";
59
60
        $expectedMapping = new EntityMapping(EntityExample::class, [
61
            'foo' => new ServiceMapping($this->container, 'some_service', false, "in file '{$mappingFilePath}'"),
62
            'bar' => new ServiceMapping($this->container, 'other_service', false, "in file '{$mappingFilePath}'"),
63
            'baz' => new ChoiceMapping('baz_column', [
64
                'lorem' => new ServiceMapping($this->container, "lorem_service", false, "in file '{$mappingFilePath}'"),
65
                'ipsum' => new ServiceMapping($this->container, "ipsum_service", true, "in file '{$mappingFilePath}'"),
66
            ], "in file '{$mappingFilePath}'"),
67
        ]);
68
69
        $this->fileLocator->method('fileExists')->willReturn(true);
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

69
        $this->fileLocator->/** @scrutinizer ignore-call */ 
70
                            method('fileExists')->willReturn(true);

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...
70
        $this->fileLocator->method('findMappingFile')->willReturn($mappingFilePath);
71
72
        /** @var EntityMapping $actualMapping */
73
        $actualMapping = $this->mappingDriver->loadRDMMetadataForClass(EntityExample::class);
74
75
        $this->assertEquals($expectedMapping, $actualMapping);
76
    }
77
78
    /**
79
     * @test
80
     */
81
    public function shouldNotReadOtherEntitiesMappingData()
82
    {
83
        /** @var string $mappingFilePath */
84
        $mappingFilePath = __DIR__ . "/EntityExample.orm.yml";
85
86
        $this->fileLocator->method('fileExists')->willReturn(true);
87
        $this->fileLocator->method('findMappingFile')->willReturn($mappingFilePath);
88
89
        /** @var EntityMapping $actualMapping */
90
        $actualMapping = $this->mappingDriver->loadRDMMetadataForClass(
91
            get_class($this->createMock(EntityExample::class))
92
        );
93
94
        $this->assertNull($actualMapping);
95
    }
96
97
}
98