MappingPHPDriverTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A shouldReadMappingData() 0 18 1
A setUp() 0 5 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\Drivers\MappingDriverInterface;
16
use Addiks\RDMBundle\Mapping\Drivers\MappingPHPDriver;
17
use Doctrine\Persistence\Mapping\Driver\FileLocator;
18
use Addiks\RDMBundle\Mapping\EntityMapping;
19
use Addiks\RDMBundle\Mapping\ServiceMapping;
20
use Symfony\Component\DependencyInjection\ContainerInterface;
21
22
final class MappingPHPDriverTest extends TestCase
23
{
24
25
    /**
26
     * @var MappingPHPDriver
27
     */
28
    private $mappingDriver;
29
30
    /**
31
     * @var MappingDriverInterface
32
     */
33
    private $fileLocator;
34
35
    public function setUp(): void
36
    {
37
        $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...
38
39
        $this->mappingDriver = new MappingPHPDriver($this->fileLocator);
40
    }
41
42
    /**
43
     * @test
44
     */
45
    public function shouldReadMappingData()
46
    {
47
        /** @var EntityMapping $expectedAnnotations */
48
        $expectedAnnotations = new EntityMapping(EntityExample::class, [
49
            'foo' => new ServiceMapping($this->createMock(ContainerInterface::class), 'some_service'),
50
            'bar' => new ServiceMapping($this->createMock(ContainerInterface::class), 'other_service')
51
        ]);
52
53
        # The mock-file just returns this global-variable.
54
        $GLOBALS['addiks_symfony_rdm_tests_mapping_driver_php_mapping'] = $expectedAnnotations;
55
56
        $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

56
        $this->fileLocator->/** @scrutinizer ignore-call */ 
57
                            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...
57
        $this->fileLocator->method('findMappingFile')->willReturn(__DIR__ . "/phpMappingMock.php");
58
59
        /** @var EntityMapping $actualAnnotations */
60
        $actualAnnotations = $this->mappingDriver->loadRDMMetadataForClass(EntityExample::class);
61
62
        $this->assertEquals($expectedAnnotations, $actualAnnotations);
63
    }
64
65
}
66