2009-06-06 01:40:47 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Mapping;
|
|
|
|
|
2009-08-13 15:03:26 +04:00
|
|
|
use Doctrine\ORM\Mapping\ClassMetadata,
|
2010-04-24 00:16:16 +04:00
|
|
|
Doctrine\ORM\Mapping\ClassMetadataInfo,
|
2009-08-13 15:03:26 +04:00
|
|
|
Doctrine\ORM\Mapping\Driver\XmlDriver,
|
|
|
|
Doctrine\ORM\Mapping\Driver\YamlDriver;
|
2009-06-06 01:40:47 +04:00
|
|
|
|
|
|
|
require_once __DIR__ . '/../../TestInit.php';
|
2010-02-02 00:48:27 +03:00
|
|
|
|
|
|
|
abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
|
2009-06-06 01:40:47 +04:00
|
|
|
{
|
2010-02-02 00:48:27 +03:00
|
|
|
abstract protected function _loadDriver();
|
|
|
|
|
2010-09-24 01:10:31 +04:00
|
|
|
public function createClassMetadata($entityClassName)
|
2009-06-06 01:40:47 +04:00
|
|
|
{
|
2010-02-02 00:48:27 +03:00
|
|
|
$mappingDriver = $this->_loadDriver();
|
|
|
|
|
2010-09-24 01:10:31 +04:00
|
|
|
$class = new ClassMetadata($entityClassName);
|
|
|
|
$mappingDriver->loadMetadataForClass($entityClassName, $class);
|
2010-02-02 00:48:27 +03:00
|
|
|
|
|
|
|
return $class;
|
2009-08-13 15:03:26 +04:00
|
|
|
}
|
2010-02-02 00:48:27 +03:00
|
|
|
|
2010-09-24 01:10:31 +04:00
|
|
|
public function testLoadMapping()
|
|
|
|
{
|
|
|
|
$entityClassName = 'Doctrine\Tests\ORM\Mapping\User';
|
|
|
|
return $this->createClassMetadata($entityClassName);
|
|
|
|
}
|
|
|
|
|
2010-02-02 00:48:27 +03:00
|
|
|
/**
|
|
|
|
* @depends testLoadMapping
|
|
|
|
* @param ClassMetadata $class
|
|
|
|
*/
|
|
|
|
public function testEntityTableNameAndInheritance($class)
|
2009-08-13 15:03:26 +04:00
|
|
|
{
|
2009-06-06 01:40:47 +04:00
|
|
|
$this->assertEquals('cms_users', $class->getTableName());
|
2010-03-15 20:19:00 +03:00
|
|
|
$this->assertEquals(ClassMetadata::INHERITANCE_TYPE_NONE, $class->inheritanceType);
|
2010-02-02 00:48:27 +03:00
|
|
|
|
|
|
|
return $class;
|
|
|
|
}
|
|
|
|
|
2010-06-14 00:59:56 +04:00
|
|
|
/**
|
|
|
|
* @depends testEntityTableNameAndInheritance
|
|
|
|
* @param ClassMetadata $class
|
|
|
|
*/
|
|
|
|
public function testEntityIndexes($class)
|
|
|
|
{
|
|
|
|
$this->assertArrayHasKey('indexes', $class->table, 'ClassMetadata should have indexes key in table property.');
|
|
|
|
$this->assertEquals(array(
|
|
|
|
'name_idx' => array('columns' => array('name')),
|
|
|
|
0 => array('columns' => array('user_email'))
|
|
|
|
), $class->table['indexes']);
|
|
|
|
|
|
|
|
return $class;
|
|
|
|
}
|
|
|
|
|
2010-04-28 22:27:53 +04:00
|
|
|
/**
|
|
|
|
* @depends testEntityTableNameAndInheritance
|
|
|
|
* @param ClassMetadata $class
|
|
|
|
*/
|
|
|
|
public function testEntityUniqueConstraints($class)
|
|
|
|
{
|
|
|
|
$this->assertArrayHasKey('uniqueConstraints', $class->table,
|
|
|
|
'ClassMetadata should have uniqueConstraints key in table property when Unique Constraints are set.');
|
2011-11-15 23:03:13 +04:00
|
|
|
|
2010-04-28 22:27:53 +04:00
|
|
|
$this->assertEquals(array(
|
|
|
|
"search_idx" => array("columns" => array("name", "user_email"))
|
|
|
|
), $class->table['uniqueConstraints']);
|
|
|
|
|
|
|
|
return $class;
|
|
|
|
}
|
|
|
|
|
2010-05-01 05:28:18 +04:00
|
|
|
/**
|
|
|
|
* @depends testEntityTableNameAndInheritance
|
|
|
|
* @param ClassMetadata $class
|
|
|
|
*/
|
|
|
|
public function testEntitySequence($class)
|
|
|
|
{
|
2011-02-20 00:50:58 +03:00
|
|
|
$this->assertInternalType('array', $class->sequenceGeneratorDefinition, 'No Sequence Definition set on this driver.');
|
2010-05-01 05:28:18 +04:00
|
|
|
$this->assertEquals(
|
|
|
|
array(
|
|
|
|
'sequenceName' => 'tablename_seq',
|
|
|
|
'allocationSize' => 100,
|
|
|
|
'initialValue' => 1,
|
|
|
|
),
|
|
|
|
$class->sequenceGeneratorDefinition
|
|
|
|
);
|
|
|
|
}
|
2011-11-28 22:41:54 +04:00
|
|
|
|
|
|
|
public function testEntityCustomGenerator()
|
|
|
|
{
|
|
|
|
$class = $this->createClassMetadata('Doctrine\Tests\ORM\Mapping\Animal');
|
|
|
|
|
|
|
|
$this->assertEquals(ClassMetadata::GENERATOR_TYPE_CUSTOM,
|
|
|
|
$class->generatorType, "Generator Type");
|
|
|
|
$this->assertEquals(
|
|
|
|
array("class" => "stdClass", "args" => array("par1", "par2")),
|
|
|
|
$class->customGeneratorDefinition,
|
|
|
|
"Custom Generator Definition");
|
|
|
|
}
|
2010-05-01 05:28:18 +04:00
|
|
|
|
2010-04-28 22:27:53 +04:00
|
|
|
|
2010-02-02 00:48:27 +03:00
|
|
|
/**
|
|
|
|
* @depends testEntityTableNameAndInheritance
|
|
|
|
* @param ClassMetadata $class
|
|
|
|
*/
|
|
|
|
public function testFieldMappings($class)
|
|
|
|
{
|
|
|
|
$this->assertEquals(3, count($class->fieldMappings));
|
2009-06-06 01:40:47 +04:00
|
|
|
$this->assertTrue(isset($class->fieldMappings['id']));
|
|
|
|
$this->assertTrue(isset($class->fieldMappings['name']));
|
2010-02-02 00:48:27 +03:00
|
|
|
$this->assertTrue(isset($class->fieldMappings['email']));
|
|
|
|
|
2010-06-22 22:24:05 +04:00
|
|
|
return $class;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testEntityTableNameAndInheritance
|
|
|
|
* @param ClassMetadata $class
|
|
|
|
*/
|
|
|
|
public function testFieldMappingsColumnNames($class)
|
|
|
|
{
|
|
|
|
$this->assertEquals("id", $class->fieldMappings['id']['columnName']);
|
|
|
|
$this->assertEquals("name", $class->fieldMappings['name']['columnName']);
|
|
|
|
$this->assertEquals("user_email", $class->fieldMappings['email']['columnName']);
|
|
|
|
|
|
|
|
return $class;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testEntityTableNameAndInheritance
|
|
|
|
* @param ClassMetadata $class
|
|
|
|
*/
|
|
|
|
public function testStringFieldMappings($class)
|
|
|
|
{
|
2009-06-06 01:40:47 +04:00
|
|
|
$this->assertEquals('string', $class->fieldMappings['name']['type']);
|
2010-06-22 22:24:05 +04:00
|
|
|
$this->assertEquals(50, $class->fieldMappings['name']['length']);
|
2010-01-28 02:00:55 +03:00
|
|
|
$this->assertTrue($class->fieldMappings['name']['nullable']);
|
|
|
|
$this->assertTrue($class->fieldMappings['name']['unique']);
|
2010-02-02 00:48:27 +03:00
|
|
|
|
|
|
|
return $class;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testFieldMappings
|
|
|
|
* @param ClassMetadata $class
|
|
|
|
*/
|
|
|
|
public function testIdentifier($class)
|
|
|
|
{
|
2009-06-06 01:40:47 +04:00
|
|
|
$this->assertEquals(array('id'), $class->identifier);
|
2011-11-15 23:03:13 +04:00
|
|
|
$this->assertEquals('integer', $class->fieldMappings['id']['type']);
|
2010-03-15 20:19:00 +03:00
|
|
|
$this->assertEquals(ClassMetadata::GENERATOR_TYPE_AUTO, $class->generatorType, "ID-Generator is not ClassMetadata::GENERATOR_TYPE_AUTO");
|
2010-02-02 00:48:27 +03:00
|
|
|
|
|
|
|
return $class;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testIdentifier
|
|
|
|
* @param ClassMetadata $class
|
|
|
|
*/
|
|
|
|
public function testAssocations($class)
|
|
|
|
{
|
2009-06-06 01:40:47 +04:00
|
|
|
$this->assertEquals(3, count($class->associationMappings));
|
2010-02-02 00:48:27 +03:00
|
|
|
|
|
|
|
return $class;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testAssocations
|
|
|
|
* @param ClassMetadata $class
|
|
|
|
*/
|
|
|
|
public function testOwningOneToOneAssocation($class)
|
|
|
|
{
|
2009-06-06 01:40:47 +04:00
|
|
|
$this->assertTrue(isset($class->associationMappings['address']));
|
2010-08-09 15:13:21 +04:00
|
|
|
$this->assertTrue($class->associationMappings['address']['isOwningSide']);
|
|
|
|
$this->assertEquals('user', $class->associationMappings['address']['inversedBy']);
|
2010-01-22 18:10:13 +03:00
|
|
|
// Check cascading
|
2010-08-09 15:13:21 +04:00
|
|
|
$this->assertTrue($class->associationMappings['address']['isCascadeRemove']);
|
|
|
|
$this->assertFalse($class->associationMappings['address']['isCascadePersist']);
|
|
|
|
$this->assertFalse($class->associationMappings['address']['isCascadeRefresh']);
|
|
|
|
$this->assertFalse($class->associationMappings['address']['isCascadeDetach']);
|
|
|
|
$this->assertFalse($class->associationMappings['address']['isCascadeMerge']);
|
2010-02-02 00:48:27 +03:00
|
|
|
|
|
|
|
return $class;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testOwningOneToOneAssocation
|
|
|
|
* @param ClassMetadata $class
|
|
|
|
*/
|
|
|
|
public function testInverseOneToManyAssociation($class)
|
|
|
|
{
|
2009-06-06 01:40:47 +04:00
|
|
|
$this->assertTrue(isset($class->associationMappings['phonenumbers']));
|
2010-08-09 15:13:21 +04:00
|
|
|
$this->assertFalse($class->associationMappings['phonenumbers']['isOwningSide']);
|
|
|
|
$this->assertTrue($class->associationMappings['phonenumbers']['isCascadePersist']);
|
2011-09-06 08:58:16 +04:00
|
|
|
$this->assertTrue($class->associationMappings['phonenumbers']['isCascadeRemove']);
|
2010-08-09 15:13:21 +04:00
|
|
|
$this->assertFalse($class->associationMappings['phonenumbers']['isCascadeRefresh']);
|
|
|
|
$this->assertFalse($class->associationMappings['phonenumbers']['isCascadeDetach']);
|
|
|
|
$this->assertFalse($class->associationMappings['phonenumbers']['isCascadeMerge']);
|
2011-07-31 13:32:57 +04:00
|
|
|
$this->assertTrue($class->associationMappings['phonenumbers']['orphanRemoval']);
|
2010-02-02 00:48:27 +03:00
|
|
|
|
2010-02-14 22:38:22 +03:00
|
|
|
// Test Order By
|
2010-08-09 15:13:21 +04:00
|
|
|
$this->assertEquals(array('number' => 'ASC'), $class->associationMappings['phonenumbers']['orderBy']);
|
2010-02-14 22:38:22 +03:00
|
|
|
|
2010-02-02 00:48:27 +03:00
|
|
|
return $class;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testInverseOneToManyAssociation
|
|
|
|
* @param ClassMetadata $class
|
|
|
|
*/
|
|
|
|
public function testManyToManyAssociationWithCascadeAll($class)
|
|
|
|
{
|
2009-06-06 01:40:47 +04:00
|
|
|
$this->assertTrue(isset($class->associationMappings['groups']));
|
2010-08-09 15:13:21 +04:00
|
|
|
$this->assertTrue($class->associationMappings['groups']['isOwningSide']);
|
2010-01-22 18:10:13 +03:00
|
|
|
// Make sure that cascade-all works as expected
|
2010-08-09 15:13:21 +04:00
|
|
|
$this->assertTrue($class->associationMappings['groups']['isCascadeRemove']);
|
|
|
|
$this->assertTrue($class->associationMappings['groups']['isCascadePersist']);
|
|
|
|
$this->assertTrue($class->associationMappings['groups']['isCascadeRefresh']);
|
|
|
|
$this->assertTrue($class->associationMappings['groups']['isCascadeDetach']);
|
|
|
|
$this->assertTrue($class->associationMappings['groups']['isCascadeMerge']);
|
2010-01-28 02:00:55 +03:00
|
|
|
|
2010-08-09 15:13:21 +04:00
|
|
|
$this->assertFalse(isset($class->associationMappings['groups']['orderBy']));
|
2010-02-14 22:38:22 +03:00
|
|
|
|
2010-02-02 00:48:27 +03:00
|
|
|
return $class;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testManyToManyAssociationWithCascadeAll
|
|
|
|
* @param ClassMetadata $class
|
|
|
|
*/
|
|
|
|
public function testLifecycleCallbacks($class)
|
|
|
|
{
|
|
|
|
$this->assertEquals(count($class->lifecycleCallbacks), 2);
|
|
|
|
$this->assertEquals($class->lifecycleCallbacks['prePersist'][0], 'doStuffOnPrePersist');
|
|
|
|
$this->assertEquals($class->lifecycleCallbacks['postPersist'][0], 'doStuffOnPostPersist');
|
|
|
|
|
|
|
|
return $class;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2010-03-15 22:29:07 +03:00
|
|
|
* @depends testManyToManyAssociationWithCascadeAll
|
|
|
|
* @param ClassMetadata $class
|
|
|
|
*/
|
2010-03-17 01:41:09 +03:00
|
|
|
public function testLifecycleCallbacksSupportMultipleMethodNames($class)
|
|
|
|
{
|
2010-03-15 22:29:07 +03:00
|
|
|
$this->assertEquals(count($class->lifecycleCallbacks['prePersist']), 2);
|
|
|
|
$this->assertEquals($class->lifecycleCallbacks['prePersist'][1], 'doOtherStuffOnPrePersistToo');
|
|
|
|
|
|
|
|
return $class;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testLifecycleCallbacksSupportMultipleMethodNames
|
2010-02-02 00:48:27 +03:00
|
|
|
* @param ClassMetadata $class
|
|
|
|
*/
|
|
|
|
public function testJoinColumnUniqueAndNullable($class)
|
|
|
|
{
|
2010-01-28 02:00:55 +03:00
|
|
|
// Non-Nullability of Join Column
|
2010-08-09 15:13:21 +04:00
|
|
|
$this->assertFalse($class->associationMappings['groups']['joinTable']['joinColumns'][0]['nullable']);
|
|
|
|
$this->assertFalse($class->associationMappings['groups']['joinTable']['joinColumns'][0]['unique']);
|
2010-02-02 00:48:27 +03:00
|
|
|
|
|
|
|
return $class;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testJoinColumnUniqueAndNullable
|
|
|
|
* @param ClassMetadata $class
|
|
|
|
*/
|
|
|
|
public function testColumnDefinition($class)
|
|
|
|
{
|
|
|
|
$this->assertEquals("CHAR(32) NOT NULL", $class->fieldMappings['email']['columnDefinition']);
|
2010-08-09 15:13:21 +04:00
|
|
|
$this->assertEquals("INT NULL", $class->associationMappings['groups']['joinTable']['inverseJoinColumns'][0]['columnDefinition']);
|
2010-02-02 00:48:27 +03:00
|
|
|
|
|
|
|
return $class;
|
2009-06-06 01:40:47 +04:00
|
|
|
}
|
2010-03-17 17:20:18 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @depends testColumnDefinition
|
|
|
|
* @param ClassMetadata $class
|
|
|
|
*/
|
2011-06-28 23:50:14 +04:00
|
|
|
public function testJoinColumnOnDelete($class)
|
2010-03-17 17:20:18 +03:00
|
|
|
{
|
2010-08-09 15:13:21 +04:00
|
|
|
$this->assertEquals('CASCADE', $class->associationMappings['address']['joinColumns'][0]['onDelete']);
|
2010-03-17 17:20:18 +03:00
|
|
|
|
|
|
|
return $class;
|
|
|
|
}
|
2010-09-24 01:10:31 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DDC-514
|
|
|
|
*/
|
|
|
|
public function testDiscriminatorColumnDefaults()
|
|
|
|
{
|
|
|
|
if (strpos(get_class($this), 'PHPMappingDriver') !== false) {
|
|
|
|
$this->markTestSkipped('PHP Mapping Drivers have no defaults.');
|
|
|
|
}
|
|
|
|
|
|
|
|
$class = $this->createClassMetadata('Doctrine\Tests\ORM\Mapping\Animal');
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
array('name' => 'dtype', 'type' => 'string', 'length' => 255, 'fieldName' => 'dtype'),
|
|
|
|
$class->discriminatorColumn
|
|
|
|
);
|
|
|
|
}
|
2011-11-15 23:03:13 +04:00
|
|
|
|
2011-09-08 18:56:05 +04:00
|
|
|
/**
|
|
|
|
* @group DDC-869
|
|
|
|
*/
|
2011-09-08 19:55:55 +04:00
|
|
|
public function testMappedSuperclassWithRepository()
|
2011-09-08 18:56:05 +04:00
|
|
|
{
|
|
|
|
$driver = $this->_loadDriver();
|
|
|
|
$em = $this->_getTestEntityManager();
|
|
|
|
$factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
|
2011-11-15 23:03:13 +04:00
|
|
|
|
2011-09-08 18:56:05 +04:00
|
|
|
$em->getConfiguration()->setMetadataDriverImpl($driver);
|
|
|
|
$factory->setEntityManager($em);
|
2011-11-15 23:03:13 +04:00
|
|
|
|
|
|
|
|
2011-09-08 18:56:05 +04:00
|
|
|
$class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC869\DDC869CreditCardPayment');
|
2011-11-15 23:03:13 +04:00
|
|
|
|
2011-09-08 18:56:05 +04:00
|
|
|
$this->assertTrue(isset($class->fieldMappings['id']));
|
|
|
|
$this->assertTrue(isset($class->fieldMappings['value']));
|
|
|
|
$this->assertTrue(isset($class->fieldMappings['creditCardNumber']));
|
|
|
|
$this->assertEquals($class->customRepositoryClassName, "Doctrine\Tests\Models\DDC869\DDC869PaymentRepository");
|
2011-11-15 23:03:13 +04:00
|
|
|
$this->assertInstanceOf("Doctrine\Tests\Models\DDC869\DDC869PaymentRepository",
|
2011-09-08 18:56:05 +04:00
|
|
|
$em->getRepository("Doctrine\Tests\Models\DDC869\DDC869CreditCardPayment"));
|
|
|
|
$this->assertTrue($em->getRepository("Doctrine\Tests\Models\DDC869\DDC869ChequePayment")->isTrue());
|
2011-11-15 23:03:13 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
2011-09-08 18:56:05 +04:00
|
|
|
$class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC869\DDC869ChequePayment');
|
2011-11-15 23:03:13 +04:00
|
|
|
|
2011-09-08 18:56:05 +04:00
|
|
|
$this->assertTrue(isset($class->fieldMappings['id']));
|
|
|
|
$this->assertTrue(isset($class->fieldMappings['value']));
|
|
|
|
$this->assertTrue(isset($class->fieldMappings['serialNumber']));
|
|
|
|
$this->assertEquals($class->customRepositoryClassName, "Doctrine\Tests\Models\DDC869\DDC869PaymentRepository");
|
2011-11-15 23:03:13 +04:00
|
|
|
$this->assertInstanceOf("Doctrine\Tests\Models\DDC869\DDC869PaymentRepository",
|
2011-09-08 18:56:05 +04:00
|
|
|
$em->getRepository("Doctrine\Tests\Models\DDC869\DDC869ChequePayment"));
|
|
|
|
$this->assertTrue($em->getRepository("Doctrine\Tests\Models\DDC869\DDC869ChequePayment")->isTrue());
|
|
|
|
}
|
2011-11-15 23:03:13 +04:00
|
|
|
|
2011-11-14 19:15:43 +04:00
|
|
|
/**
|
|
|
|
* @group DDC-1476
|
|
|
|
*/
|
|
|
|
public function testDefaultFieldType()
|
|
|
|
{
|
|
|
|
$driver = $this->_loadDriver();
|
|
|
|
$em = $this->_getTestEntityManager();
|
|
|
|
$factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
|
2011-11-15 23:03:13 +04:00
|
|
|
|
2011-11-14 19:15:43 +04:00
|
|
|
$em->getConfiguration()->setMetadataDriverImpl($driver);
|
|
|
|
$factory->setEntityManager($em);
|
2011-11-15 23:03:13 +04:00
|
|
|
|
|
|
|
|
2011-11-14 19:15:43 +04:00
|
|
|
$class = $factory->getMetadataFor('Doctrine\Tests\Models\DDC1476\DDC1476EntityWithDefaultFieldType');
|
2011-11-15 23:03:13 +04:00
|
|
|
|
|
|
|
|
2011-11-14 19:15:43 +04:00
|
|
|
$this->assertArrayHasKey('id', $class->fieldMappings);
|
|
|
|
$this->assertArrayHasKey('name', $class->fieldMappings);
|
2011-11-15 23:03:13 +04:00
|
|
|
|
|
|
|
|
2011-11-14 19:15:43 +04:00
|
|
|
$this->assertArrayHasKey('type', $class->fieldMappings['id']);
|
|
|
|
$this->assertArrayHasKey('type', $class->fieldMappings['name']);
|
2011-11-15 23:03:13 +04:00
|
|
|
|
2011-11-14 19:15:43 +04:00
|
|
|
$this->assertEquals('string', $class->fieldMappings['id']['type']);
|
|
|
|
$this->assertEquals('string', $class->fieldMappings['name']['type']);
|
2011-11-15 23:03:13 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
2011-11-14 19:15:43 +04:00
|
|
|
$this->assertArrayHasKey('fieldName', $class->fieldMappings['id']);
|
|
|
|
$this->assertArrayHasKey('fieldName', $class->fieldMappings['name']);
|
2011-11-15 23:03:13 +04:00
|
|
|
|
2011-11-14 19:15:43 +04:00
|
|
|
$this->assertEquals('id', $class->fieldMappings['id']['fieldName']);
|
|
|
|
$this->assertEquals('name', $class->fieldMappings['name']['fieldName']);
|
2011-11-15 23:03:13 +04:00
|
|
|
|
|
|
|
|
|
|
|
|
2011-11-14 19:15:43 +04:00
|
|
|
$this->assertArrayHasKey('columnName', $class->fieldMappings['id']);
|
|
|
|
$this->assertArrayHasKey('columnName', $class->fieldMappings['name']);
|
2011-11-15 23:03:13 +04:00
|
|
|
|
2011-11-14 19:15:43 +04:00
|
|
|
$this->assertEquals('id', $class->fieldMappings['id']['columnName']);
|
|
|
|
$this->assertEquals('name', $class->fieldMappings['name']['columnName']);
|
2011-11-15 23:03:13 +04:00
|
|
|
|
2011-11-14 19:15:43 +04:00
|
|
|
$this->assertEquals(ClassMetadataInfo::GENERATOR_TYPE_NONE, $class->generatorType);
|
|
|
|
}
|
2009-08-13 15:03:26 +04:00
|
|
|
}
|
2009-06-06 01:40:47 +04:00
|
|
|
|
2010-02-14 22:38:22 +03:00
|
|
|
/**
|
|
|
|
* @Entity
|
|
|
|
* @HasLifecycleCallbacks
|
2010-06-14 00:59:56 +04:00
|
|
|
* @Table(
|
|
|
|
* name="cms_users",
|
|
|
|
* uniqueConstraints={@UniqueConstraint(name="search_idx", columns={"name", "user_email"})},
|
|
|
|
* indexes={@Index(name="name_idx", columns={"name"}), @Index(name="0", columns={"user_email"})}
|
|
|
|
* )
|
2010-02-14 22:38:22 +03:00
|
|
|
*/
|
|
|
|
class User
|
|
|
|
{
|
2010-05-01 05:28:18 +04:00
|
|
|
/**
|
|
|
|
* @Id
|
|
|
|
* @Column(type="integer")
|
|
|
|
* @generatedValue(strategy="AUTO")
|
|
|
|
* @SequenceGenerator(sequenceName="tablename_seq", initialValue=1, allocationSize=100)
|
|
|
|
**/
|
2010-02-14 22:38:22 +03:00
|
|
|
public $id;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Column(length=50, nullable=true, unique=true)
|
|
|
|
*/
|
|
|
|
public $name;
|
2010-02-02 00:48:27 +03:00
|
|
|
|
2010-02-14 22:38:22 +03:00
|
|
|
/**
|
|
|
|
* @Column(name="user_email", columnDefinition="CHAR(32) NOT NULL")
|
|
|
|
*/
|
|
|
|
public $email;
|
2009-08-25 01:05:55 +04:00
|
|
|
|
2010-02-14 22:38:22 +03:00
|
|
|
/**
|
2010-04-10 02:00:36 +04:00
|
|
|
* @OneToOne(targetEntity="Address", cascade={"remove"}, inversedBy="user")
|
2011-06-28 23:50:14 +04:00
|
|
|
* @JoinColumn(onDelete="CASCADE")
|
2010-02-14 22:38:22 +03:00
|
|
|
*/
|
|
|
|
public $address;
|
|
|
|
|
|
|
|
/**
|
2011-07-31 13:32:57 +04:00
|
|
|
* @OneToMany(targetEntity="Phonenumber", mappedBy="user", cascade={"persist"}, orphanRemoval=true)
|
2010-02-27 00:26:06 +03:00
|
|
|
* @OrderBy({"number"="ASC"})
|
2010-02-14 22:38:22 +03:00
|
|
|
*/
|
|
|
|
public $phonenumbers;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ManyToMany(targetEntity="Group", cascade={"all"})
|
|
|
|
* @JoinTable(name="cms_user_groups",
|
|
|
|
* joinColumns={@JoinColumn(name="user_id", referencedColumnName="id", nullable=false, unique=false)},
|
|
|
|
* inverseJoinColumns={@JoinColumn(name="group_id", referencedColumnName="id", columnDefinition="INT NULL")}
|
|
|
|
* )
|
|
|
|
*/
|
|
|
|
public $groups;
|
|
|
|
|
2010-03-15 22:29:07 +03:00
|
|
|
|
2010-02-14 22:38:22 +03:00
|
|
|
/**
|
|
|
|
* @PrePersist
|
|
|
|
*/
|
2009-08-25 01:05:55 +04:00
|
|
|
public function doStuffOnPrePersist()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-03-15 22:29:07 +03:00
|
|
|
/**
|
|
|
|
* @PrePersist
|
|
|
|
*/
|
|
|
|
public function doOtherStuffOnPrePersistToo() {
|
|
|
|
}
|
|
|
|
|
2010-02-14 22:38:22 +03:00
|
|
|
/**
|
|
|
|
* @PostPersist
|
|
|
|
*/
|
2009-08-25 01:05:55 +04:00
|
|
|
public function doStuffOnPostPersist()
|
|
|
|
{
|
2010-02-02 00:48:27 +03:00
|
|
|
|
2009-08-25 01:05:55 +04:00
|
|
|
}
|
2010-04-24 00:16:16 +04:00
|
|
|
|
|
|
|
public static function loadMetadata(ClassMetadataInfo $metadata)
|
|
|
|
{
|
|
|
|
$metadata->setInheritanceType(ClassMetadataInfo::INHERITANCE_TYPE_NONE);
|
|
|
|
$metadata->setPrimaryTable(array(
|
|
|
|
'name' => 'cms_users',
|
|
|
|
));
|
|
|
|
$metadata->setChangeTrackingPolicy(ClassMetadataInfo::CHANGETRACKING_DEFERRED_IMPLICIT);
|
|
|
|
$metadata->addLifecycleCallback('doStuffOnPrePersist', 'prePersist');
|
|
|
|
$metadata->addLifecycleCallback('doOtherStuffOnPrePersistToo', 'prePersist');
|
|
|
|
$metadata->addLifecycleCallback('doStuffOnPostPersist', 'postPersist');
|
|
|
|
$metadata->mapField(array(
|
|
|
|
'id' => true,
|
|
|
|
'fieldName' => 'id',
|
|
|
|
'type' => 'integer',
|
|
|
|
'columnName' => 'id',
|
|
|
|
));
|
|
|
|
$metadata->mapField(array(
|
|
|
|
'fieldName' => 'name',
|
|
|
|
'type' => 'string',
|
|
|
|
'length' => 50,
|
|
|
|
'unique' => true,
|
|
|
|
'nullable' => true,
|
|
|
|
'columnName' => 'name',
|
|
|
|
));
|
|
|
|
$metadata->mapField(array(
|
|
|
|
'fieldName' => 'email',
|
|
|
|
'type' => 'string',
|
|
|
|
'columnName' => 'user_email',
|
|
|
|
'columnDefinition' => 'CHAR(32) NOT NULL',
|
|
|
|
));
|
|
|
|
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_AUTO);
|
|
|
|
$metadata->mapOneToOne(array(
|
|
|
|
'fieldName' => 'address',
|
|
|
|
'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Address',
|
2011-11-15 23:03:13 +04:00
|
|
|
'cascade' =>
|
2010-04-24 00:16:16 +04:00
|
|
|
array(
|
|
|
|
0 => 'remove',
|
|
|
|
),
|
|
|
|
'mappedBy' => NULL,
|
|
|
|
'inversedBy' => 'user',
|
2011-11-15 23:03:13 +04:00
|
|
|
'joinColumns' =>
|
2010-04-24 00:16:16 +04:00
|
|
|
array(
|
2011-11-15 23:03:13 +04:00
|
|
|
0 =>
|
2010-04-24 00:16:16 +04:00
|
|
|
array(
|
|
|
|
'name' => 'address_id',
|
|
|
|
'referencedColumnName' => 'id',
|
|
|
|
'onDelete' => 'CASCADE',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'orphanRemoval' => false,
|
|
|
|
));
|
|
|
|
$metadata->mapOneToMany(array(
|
|
|
|
'fieldName' => 'phonenumbers',
|
|
|
|
'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Phonenumber',
|
2011-11-15 23:03:13 +04:00
|
|
|
'cascade' =>
|
2010-04-24 00:16:16 +04:00
|
|
|
array(
|
|
|
|
1 => 'persist',
|
|
|
|
),
|
|
|
|
'mappedBy' => 'user',
|
2011-07-31 13:32:57 +04:00
|
|
|
'orphanRemoval' => true,
|
2011-11-15 23:03:13 +04:00
|
|
|
'orderBy' =>
|
2010-04-24 00:16:16 +04:00
|
|
|
array(
|
|
|
|
'number' => 'ASC',
|
|
|
|
),
|
|
|
|
));
|
|
|
|
$metadata->mapManyToMany(array(
|
|
|
|
'fieldName' => 'groups',
|
|
|
|
'targetEntity' => 'Doctrine\\Tests\\ORM\\Mapping\\Group',
|
2011-11-15 23:03:13 +04:00
|
|
|
'cascade' =>
|
2010-04-24 00:16:16 +04:00
|
|
|
array(
|
|
|
|
0 => 'remove',
|
|
|
|
1 => 'persist',
|
|
|
|
2 => 'refresh',
|
|
|
|
3 => 'merge',
|
|
|
|
4 => 'detach',
|
|
|
|
),
|
|
|
|
'mappedBy' => NULL,
|
2011-11-15 23:03:13 +04:00
|
|
|
'joinTable' =>
|
2010-04-24 00:16:16 +04:00
|
|
|
array(
|
|
|
|
'name' => 'cms_users_groups',
|
2011-11-15 23:03:13 +04:00
|
|
|
'joinColumns' =>
|
2010-04-24 00:16:16 +04:00
|
|
|
array(
|
2011-11-15 23:03:13 +04:00
|
|
|
0 =>
|
2010-04-24 00:16:16 +04:00
|
|
|
array(
|
|
|
|
'name' => 'user_id',
|
|
|
|
'referencedColumnName' => 'id',
|
|
|
|
'unique' => false,
|
|
|
|
'nullable' => false,
|
|
|
|
),
|
|
|
|
),
|
2011-11-15 23:03:13 +04:00
|
|
|
'inverseJoinColumns' =>
|
2010-04-24 00:16:16 +04:00
|
|
|
array(
|
2011-11-15 23:03:13 +04:00
|
|
|
0 =>
|
2010-04-24 00:16:16 +04:00
|
|
|
array(
|
|
|
|
'name' => 'group_id',
|
|
|
|
'referencedColumnName' => 'id',
|
|
|
|
'columnDefinition' => 'INT NULL',
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
'orderBy' => NULL,
|
|
|
|
));
|
2010-04-28 22:27:53 +04:00
|
|
|
$metadata->table['uniqueConstraints'] = array(
|
|
|
|
'search_idx' => array('columns' => array('name', 'user_email')),
|
|
|
|
);
|
2010-06-14 00:59:56 +04:00
|
|
|
$metadata->table['indexes'] = array(
|
|
|
|
'name_idx' => array('columns' => array('name')), 0 => array('columns' => array('user_email'))
|
|
|
|
);
|
2010-05-01 05:28:18 +04:00
|
|
|
$metadata->setSequenceGeneratorDefinition(array(
|
|
|
|
'sequenceName' => 'tablename_seq',
|
|
|
|
'allocationSize' => 100,
|
|
|
|
'initialValue' => 1,
|
|
|
|
));
|
2010-04-24 00:16:16 +04:00
|
|
|
}
|
2010-09-22 01:14:45 +04:00
|
|
|
}
|
2010-09-24 01:10:31 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @Entity
|
|
|
|
* @InheritanceType("SINGLE_TABLE")
|
|
|
|
* @DiscriminatorMap({"cat" = "Cat", "dog" = "Dog"})
|
|
|
|
*/
|
|
|
|
abstract class Animal
|
|
|
|
{
|
|
|
|
/**
|
2011-11-28 22:54:54 +04:00
|
|
|
* @Id @Column(type="string") @GeneratedValue(strategy="CUSTOM")
|
|
|
|
* @CustomIdGenerator(class="stdClass", args={"par1", "par2"})
|
2010-09-24 01:10:31 +04:00
|
|
|
*/
|
|
|
|
public $id;
|
|
|
|
|
|
|
|
public static function loadMetadata(ClassMetadataInfo $metadata)
|
|
|
|
{
|
2011-11-29 00:21:46 +04:00
|
|
|
$metadata->setIdGeneratorType(ClassMetadataInfo::GENERATOR_TYPE_CUSTOM);
|
|
|
|
$metadata->setCustomGeneratorDefinition(array("class" => "stdClass", "args" => array("par1", "par2")));
|
2010-09-24 01:10:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @Entity */
|
|
|
|
class Cat extends Animal
|
|
|
|
{
|
|
|
|
public static function loadMetadata(ClassMetadataInfo $metadata)
|
|
|
|
{
|
2011-11-15 23:03:13 +04:00
|
|
|
|
2010-09-24 01:10:31 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @Entity */
|
|
|
|
class Dog extends Animal
|
|
|
|
{
|
|
|
|
public static function loadMetadata(ClassMetadataInfo $metadata)
|
|
|
|
{
|
2011-11-15 23:03:13 +04:00
|
|
|
|
2010-09-24 01:10:31 +04:00
|
|
|
}
|
|
|
|
}
|