Passed
Pull Request — master (#6869)
by Michael
09:57
created

YamlMappingDriverTest::testDeprecation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 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 Symfony\Component\Yaml\Yaml;
12
13
/**
14
 * @group legacy
15
 */
16
class YamlMappingDriverTest extends AbstractMappingDriverTest
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');
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
    }
50
51
    /**
52
     * @group DDC-1468
53
     *
54
     * @expectedException Doctrine\Common\Persistence\Mapping\MappingException
55
     * @expectedExceptionMessage Invalid mapping file 'Doctrine.Tests.Models.Generic.SerializationModel.dcm.yml' for class 'Doctrine\Tests\Models\Generic\SerializationModel'.
56
     */
57
    public function testInvalidMappingFileException()
58
    {
59
        $this->createClassMetadata(SerializationModel::class);
60
    }
61
62
    /**
63
     * @group DDC-2069
64
     */
65
    public function testSpacesShouldBeIgnoredWhenUseExplode()
66
    {
67
        $metadata = $this->createClassMetadata(DDC2069Entity::class);
68
        $unique   = $metadata->table['uniqueConstraints'][0]['columns'];
69
        $indexes  = $metadata->table['indexes'][0]['columns'];
70
71
        $nameField  = $metadata->fieldMappings['name'];
72
        $valueField = $metadata->fieldMappings['value'];
73
74
        $this->assertEquals('name', $unique[0]);
75
        $this->assertEquals('value', $unique[1]);
76
77
        $this->assertEquals('value', $indexes[0]);
78
        $this->assertEquals('name', $indexes[1]);
79
80
        $this->assertEquals(255, $nameField['length']);
81
        $this->assertEquals(255, $valueField['length']);
82
    }
83
84
    /**
85
     * @expectedDeprecation YAML mapping driver is deprecated and will be removed in Doctrine 3.0, please migrate to annotation or XML driver.
86
     */
87
    public function testDeprecation() : void
88
    {
89
        $this->createClassMetadata(DDC2069Entity::class);
90
    }
91
92
}
93
94
class DDC2069Entity
95
{
96
    public $id;
97
98
    public $name;
99
100
    public $value;
101
}
102