Completed
Push — master ( 4a4bf4...63fe9e )
by Gerrit
02:30
created

shouldNotReadOtherEntitiesMappingData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 7
nc 1
nop 0
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\MappingDriverInterface;
18
use Doctrine\Common\Persistence\Mapping\Driver\FileLocator;
19
use Addiks\RDMBundle\Mapping\Drivers\MappingYamlDriver;
20
use Addiks\RDMBundle\Mapping\EntityMapping;
21
use Addiks\RDMBundle\Mapping\ServiceMapping;
22
use Addiks\RDMBundle\Mapping\ChoiceMapping;
23
24
final class MappingYamlDriverTest extends TestCase
25
{
26
27
    /**
28
     * @var MappingYamlDriver
29
     */
30
    private $mappingDriver;
31
32
    /**
33
     * @var MappingDriverInterface
34
     */
35
    private $fileLocator;
36
37
    public function setUp()
38
    {
39
        $this->fileLocator = $this->createMock(FileLocator::class);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->createMock(\Doctr...ver\FileLocator::class) of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<Addiks\RDMBundle\...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...
40
41
        $this->mappingDriver = new MappingYamlDriver(
42
            $this->fileLocator
0 ignored issues
show
Documentation introduced by
$this->fileLocator is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Doctrine\Common\P...ing\Driver\FileLocator>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
43
        );
44
    }
45
46
    /**
47
     * @test
48
     */
49
    public function shouldReadMappingData()
50
    {
51
        /** @var string $mappingFilePath */
52
        $mappingFilePath = __DIR__ . "/EntityExample.orm.yml";
53
54
        $expectedMapping = new EntityMapping(EntityExample::class, [
55
            'foo' => new ServiceMapping('some_service', false, "in file '{$mappingFilePath}'"),
56
            'bar' => new ServiceMapping('other_service', false, "in file '{$mappingFilePath}'"),
57
            'baz' => new ChoiceMapping('baz_column', [
58
                'lorem' => new ServiceMapping("lorem_service", false, "in file '{$mappingFilePath}'"),
59
                'ipsum' => new ServiceMapping("ipsum_service", false, "in file '{$mappingFilePath}'"),
60
            ], "in file '{$mappingFilePath}'"),
61
        ]);
62
63
        $this->fileLocator->method('fileExists')->willReturn(true);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\RDMBundle\...MappingDriverInterface>.

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...
64
        $this->fileLocator->method('findMappingFile')->willReturn($mappingFilePath);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\RDMBundle\...MappingDriverInterface>.

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
66
        /** @var EntityMapping $actualMapping */
67
        $actualMapping = $this->mappingDriver->loadRDMMetadataForClass(EntityExample::class);
68
69
        $this->assertEquals($expectedMapping, $actualMapping);
70
    }
71
72
    /**
73
     * @test
74
     */
75
    public function shouldNotReadOtherEntitiesMappingData()
76
    {
77
        /** @var string $mappingFilePath */
78
        $mappingFilePath = __DIR__ . "/EntityExample.orm.yml";
79
80
        $this->fileLocator->method('fileExists')->willReturn(true);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\RDMBundle\...MappingDriverInterface>.

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...
81
        $this->fileLocator->method('findMappingFile')->willReturn($mappingFilePath);
0 ignored issues
show
Bug introduced by
The method method() does not seem to exist on object<Addiks\RDMBundle\...MappingDriverInterface>.

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...
82
83
        /** @var EntityMapping $actualMapping */
84
        $actualMapping = $this->mappingDriver->loadRDMMetadataForClass(
85
            get_class($this->createMock(EntityExample::class))
86
        );
87
88
        $this->assertNull($actualMapping);
89
    }
90
91
}
92