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'); |
|
|
|
|
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']); |
|
|
|
|
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); |
|
|
|
|
43
|
|
|
$classPage = $factory->getMetadataFor(File::class); |
44
|
|
|
$this->assertEquals(File::class, $classPage->associationMappings['parentDirectory']['sourceEntity']); |
|
|
|
|
45
|
|
|
|
46
|
|
|
$classDirectory = new ClassMetadata(Directory::class); |
|
|
|
|
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
|
|
|
|