|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\ORM\Tools\ToolsException; |
|
6
|
|
|
use Doctrine\Tests\Models\DDC2825\ExplicitSchemaAndTable; |
|
7
|
|
|
use Doctrine\Tests\Models\DDC2825\SchemaAndTableInTableName; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* This class makes tests on the correct use of a database schema when entities are stored |
|
11
|
|
|
* |
|
12
|
|
|
* @group DDC-2825 |
|
13
|
|
|
*/ |
|
14
|
|
|
class DDC2825Test extends \Doctrine\Tests\OrmFunctionalTestCase |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* {@inheritDoc} |
|
18
|
|
|
*/ |
|
19
|
|
|
protected function setUp() |
|
20
|
|
|
{ |
|
21
|
|
|
parent::setUp(); |
|
22
|
|
|
|
|
23
|
|
|
$platform = $this->_em->getConnection()->getDatabasePlatform(); |
|
24
|
|
|
|
|
25
|
|
|
if ( ! $platform->supportsSchemas() && ! $platform->canEmulateSchemas()) { |
|
26
|
|
|
$this->markTestSkipped("This test is only useful for databases that support schemas or can emulate them."); |
|
27
|
|
|
} |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @dataProvider getTestedClasses |
|
32
|
|
|
* |
|
33
|
|
|
* @param string $className |
|
34
|
|
|
* @param string $expectedSchemaName |
|
35
|
|
|
* @param string $expectedTableName |
|
36
|
|
|
*/ |
|
37
|
|
|
public function testClassSchemaMappingsValidity($className, $expectedSchemaName, $expectedTableName) |
|
38
|
|
|
{ |
|
39
|
|
|
$classMetadata = $this->_em->getClassMetadata($className); |
|
40
|
|
|
$platform = $this->_em->getConnection()->getDatabasePlatform(); |
|
41
|
|
|
$quotedTableName = $this->_em->getConfiguration()->getQuoteStrategy()->getTableName($classMetadata, $platform); |
|
42
|
|
|
|
|
43
|
|
|
// Check if table name and schema properties are defined in the class metadata |
|
44
|
|
|
$this->assertEquals($expectedTableName, $classMetadata->table['name']); |
|
45
|
|
|
$this->assertEquals($expectedSchemaName, $classMetadata->table['schema']); |
|
46
|
|
|
|
|
47
|
|
|
if ($this->_em->getConnection()->getDatabasePlatform()->supportsSchemas()) { |
|
48
|
|
|
$fullTableName = sprintf('%s.%s', $expectedSchemaName, $expectedTableName); |
|
49
|
|
|
} else { |
|
50
|
|
|
$fullTableName = sprintf('%s__%s', $expectedSchemaName, $expectedTableName); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
$this->assertEquals($fullTableName, $quotedTableName); |
|
54
|
|
|
|
|
55
|
|
|
// Checks sequence name validity |
|
56
|
|
|
$this->assertEquals( |
|
57
|
|
|
$fullTableName . '_' . $classMetadata->getSingleIdentifierColumnName() . '_seq', |
|
58
|
|
|
$classMetadata->getSequenceName($platform) |
|
59
|
|
|
); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* @dataProvider getTestedClasses |
|
64
|
|
|
* |
|
65
|
|
|
* @param string $className |
|
66
|
|
|
*/ |
|
67
|
|
|
public function testPersistenceOfEntityWithSchemaMapping($className) |
|
68
|
|
|
{ |
|
69
|
|
|
try { |
|
70
|
|
|
$this->_schemaTool->createSchema(array($this->_em->getClassMetadata($className))); |
|
71
|
|
|
} catch (ToolsException $e) { |
|
72
|
|
|
// table already exists |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
$this->_em->persist(new $className()); |
|
76
|
|
|
$this->_em->flush(); |
|
77
|
|
|
$this->_em->clear(); |
|
78
|
|
|
|
|
79
|
|
|
$this->assertCount(1, $this->_em->getRepository($className)->findAll()); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Data provider |
|
84
|
|
|
* |
|
85
|
|
|
* @return string[][] |
|
86
|
|
|
*/ |
|
87
|
|
|
public function getTestedClasses() |
|
88
|
|
|
{ |
|
89
|
|
|
return array( |
|
90
|
|
|
array(ExplicitSchemaAndTable::CLASSNAME, 'explicit_schema', 'explicit_table'), |
|
91
|
|
|
array(SchemaAndTableInTableName::CLASSNAME, 'implicit_schema', 'implicit_table'), |
|
92
|
|
|
array(DDC2825ClassWithImplicitlyDefinedSchemaAndQuotedTableName::CLASSNAME, 'myschema', 'order'), |
|
93
|
|
|
); |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @Entity |
|
99
|
|
|
* @Table(name="myschema.order") |
|
100
|
|
|
*/ |
|
101
|
|
|
class DDC2825ClassWithImplicitlyDefinedSchemaAndQuotedTableName |
|
102
|
|
|
{ |
|
103
|
|
|
const CLASSNAME = __CLASS__; |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @Id @GeneratedValue |
|
107
|
|
|
* @Column(type="integer") |
|
108
|
|
|
* |
|
109
|
|
|
* @var integer |
|
110
|
|
|
*/ |
|
111
|
|
|
public $id; |
|
112
|
|
|
} |
|
113
|
|
|
|