Failed Conditions
Pull Request — 2.6 (#7506)
by
unknown
09:52
created

YamlMappingDriverTest::testDeprecation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Doctrine\Tests\ORM\Mapping;
4
5
use Doctrine\ORM\Mapping\ClassMetadata;
6
use Doctrine\ORM\Mapping\ClassMetadataFactory;
7
use Doctrine\ORM\Mapping\Driver\YamlDriver;
8
use Doctrine\Tests\Models\DirectoryTree\Directory;
9
use Doctrine\Tests\Models\DirectoryTree\File;
10
use Doctrine\Tests\Models\Generic\SerializationModel;
11
use Doctrine\Tests\VerifyDeprecations;
12
use Symfony\Component\Yaml\Yaml;
13
14
class YamlMappingDriverTest extends AbstractMappingDriverTest
15
{
16
    use VerifyDeprecations;
17
18
    protected function _loadDriver()
19
    {
20
        if (!class_exists(Yaml::class, true)) {
21
            $this->markTestSkipped('Please install Symfony YAML Component into the include path of your PHP installation.');
22
        }
23
24
        return new YamlDriver(__DIR__ . DIRECTORY_SEPARATOR . 'yaml');
0 ignored issues
show
Deprecated Code introduced by
The class Doctrine\ORM\Mapping\Driver\YamlDriver has been deprecated: 2.7 This class is being removed from the ORM and won't have any replacement ( Ignorable by Annotation )

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

24
        return /** @scrutinizer ignore-deprecated */ new YamlDriver(__DIR__ . DIRECTORY_SEPARATOR . 'yaml');
Loading history...
25
    }
26
27
    /**
28
     * @group DDC-671
29
     *
30
     * Entities for this test are in AbstractMappingDriverTest
31
     */
32
    public function testJoinTablesWithMappedSuperclassForYamlDriver()
33
    {
34
        $yamlDriver = $this->_loadDriver();
35
        $yamlDriver->getLocator()->addPaths([__DIR__ . DIRECTORY_SEPARATOR . 'yaml']);
0 ignored issues
show
Bug introduced by
The method addPaths() does not exist on Doctrine\Common\Persiste...ping\Driver\FileLocator. It seems like you code against a sub-type of Doctrine\Common\Persiste...ping\Driver\FileLocator such as Doctrine\Common\Persiste...iver\DefaultFileLocator. ( Ignorable by Annotation )

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

35
        $yamlDriver->getLocator()->/** @scrutinizer ignore-call */ addPaths([__DIR__ . DIRECTORY_SEPARATOR . 'yaml']);
Loading history...
36
37
        $em = $this->_getTestEntityManager();
38
        $em->getConfiguration()->setMetadataDriverImpl($yamlDriver);
39
        $factory = new ClassMetadataFactory();
40
        $factory->setEntityManager($em);
41
42
        $classPage = new ClassMetadata(File::class);
0 ignored issues
show
Unused Code introduced by
The assignment to $classPage is dead and can be removed.
Loading history...
43
        $classPage = $factory->getMetadataFor(File::class);
44
        $this->assertEquals(File::class, $classPage->associationMappings['parentDirectory']['sourceEntity']);
0 ignored issues
show
Bug introduced by
Accessing associationMappings on the interface Doctrine\Common\Persistence\Mapping\ClassMetadata suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
45
46
        $classDirectory = new ClassMetadata(Directory::class);
0 ignored issues
show
Unused Code introduced by
The assignment to $classDirectory is dead and can be removed.
Loading history...
47
        $classDirectory = $factory->getMetadataFor(Directory::class);
48
        $this->assertEquals(Directory::class, $classDirectory->associationMappings['parentDirectory']['sourceEntity']);
49
        $this->assertHasDeprecationMessages();
50
    }
51
52
    /**
53
     * @group DDC-1468
54
     *
55
     * @expectedException Doctrine\Common\Persistence\Mapping\MappingException
56
     * @expectedExceptionMessage Invalid mapping file 'Doctrine.Tests.Models.Generic.SerializationModel.dcm.yml' for class 'Doctrine\Tests\Models\Generic\SerializationModel'.
57
     */
58
    public function testInvalidMappingFileException()
59
    {
60
        $this->createClassMetadata(SerializationModel::class);
61
    }
62
63
    /**
64
     * @group DDC-2069
65
     */
66
    public function testSpacesShouldBeIgnoredWhenUseExplode()
67
    {
68
        $metadata = $this->createClassMetadata(DDC2069Entity::class);
69
        $unique   = $metadata->table['uniqueConstraints'][0]['columns'];
70
        $indexes  = $metadata->table['indexes'][0]['columns'];
71
72
        $nameField  = $metadata->fieldMappings['name'];
73
        $valueField = $metadata->fieldMappings['value'];
74
75
        $this->assertEquals('name', $unique[0]);
76
        $this->assertEquals('value', $unique[1]);
77
78
        $this->assertEquals('value', $indexes[0]);
79
        $this->assertEquals('name', $indexes[1]);
80
81
        $this->assertEquals(255, $nameField['length']);
82
        $this->assertEquals(255, $valueField['length']);
83
        $this->assertHasDeprecationMessages();
84
    }
85
86
    public function testDeprecation() : void
87
    {
88
        $this->createClassMetadata(DDC2069Entity::class);
89
        $this->expectDeprecationMessage('YAML mapping driver is deprecated and will be removed in Doctrine 3.0, please migrate to annotation or XML driver.');
90
    }
91
92
}
93
94
class DDC2069Entity
95
{
96
    public $id;
97
98
    public $name;
99
100
    public $value;
101
}
102