|
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']); |
|
|
|
|
|
|
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
|
|
|
} |
|
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
|
|
|
|