2009-01-05 20:18:56 +00:00
< ? php
2009-01-06 17:22:23 +00:00
2009-01-22 19:38:10 +00:00
namespace Doctrine\Tests\ORM\Mapping ;
2009-01-06 17:22:23 +00:00
2014-08-14 15:51:17 +02:00
use Doctrine\Common\Persistence\Mapping\RuntimeReflectionService ;
2015-04-11 19:43:34 +02:00
use Doctrine\Common\Persistence\Mapping\StaticReflectionService ;
2009-07-15 20:18:40 +00:00
use Doctrine\ORM\Events ;
2016-12-08 18:01:04 +01:00
use Doctrine\ORM\Mapping\ClassMetadata ;
2014-08-14 15:51:17 +02:00
use Doctrine\ORM\Mapping\DefaultNamingStrategy ;
2016-06-18 13:01:59 +02:00
use Doctrine\ORM\Mapping\MappingException ;
2016-05-11 01:55:12 +07:00
use Doctrine\ORM\Mapping\UnderscoreNamingStrategy ;
2016-12-08 18:01:04 +01:00
use Doctrine\Tests\Models\CMS ;
use Doctrine\Tests\Models\Company\CompanyContract ;
use Doctrine\Tests\Models\CustomType\CustomTypeParent ;
use Doctrine\Tests\Models\DDC117\DDC117Article ;
use Doctrine\Tests\Models\DDC117\DDC117ArticleDetails ;
use Doctrine\Tests\Models\DDC964\DDC964Admin ;
use Doctrine\Tests\Models\DDC964\DDC964Guest ;
use Doctrine\Tests\Models\Routing\RoutingLeg ;
2016-05-11 01:55:12 +07:00
use Doctrine\Tests\OrmTestCase ;
2016-12-08 18:01:04 +01:00
use DoctrineGlobal_Article ;
2009-01-22 19:38:10 +00:00
2010-12-30 22:30:51 +01:00
require_once __DIR__ . '/../../Models/Global/GlobalNamespaceModel.php' ;
2011-12-19 22:56:19 +01:00
2016-05-11 01:55:12 +07:00
class ClassMetadataTest extends OrmTestCase
2009-01-06 17:22:23 +00:00
{
2009-02-18 07:59:11 +00:00
public function testClassMetadataInstanceSerialization ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2009-01-05 20:18:56 +00:00
// Test initial state
2009-01-12 13:34:41 +00:00
$this -> assertTrue ( count ( $cm -> getReflectionProperties ()) == 0 );
2011-07-26 11:38:09 +02:00
$this -> assertInstanceOf ( 'ReflectionClass' , $cm -> reflClass );
2016-12-08 18:01:04 +01:00
$this -> assertEquals ( CMS\CmsUser :: class , $cm -> name );
$this -> assertEquals ( CMS\CmsUser :: class , $cm -> rootEntityName );
2016-12-07 23:33:41 +01:00
$this -> assertEquals ([], $cm -> subClasses );
$this -> assertEquals ([], $cm -> parentClasses );
2010-04-18 22:47:03 +02:00
$this -> assertEquals ( ClassMetadata :: INHERITANCE_TYPE_NONE , $cm -> inheritanceType );
2009-01-05 20:18:56 +00:00
// Customize state
2010-04-18 22:47:03 +02:00
$cm -> setInheritanceType ( ClassMetadata :: INHERITANCE_TYPE_SINGLE_TABLE );
2016-12-07 23:33:41 +01:00
$cm -> setSubclasses ([ " One " , " Two " , " Three " ]);
$cm -> setParentClasses ([ " UserParent " ]);
2009-01-05 20:18:56 +00:00
$cm -> setCustomRepositoryClass ( " UserRepository " );
2016-12-07 23:33:41 +01:00
$cm -> setDiscriminatorColumn ([ 'name' => 'disc' , 'type' => 'integer' ]);
$cm -> mapOneToOne ([ 'fieldName' => 'phonenumbers' , 'targetEntity' => 'CmsAddress' , 'mappedBy' => 'foo' ]);
2011-03-29 20:04:14 +02:00
$cm -> markReadOnly ();
2016-12-07 23:33:41 +01:00
$cm -> addNamedQuery ([ 'name' => 'dql' , 'query' => 'foo' ]);
2009-05-14 10:03:09 +00:00
$this -> assertEquals ( 1 , count ( $cm -> associationMappings ));
2009-01-05 20:18:56 +00:00
$serialized = serialize ( $cm );
$cm = unserialize ( $serialized );
2014-08-14 15:51:17 +02:00
$cm -> wakeupReflection ( new RuntimeReflectionService ());
2009-01-05 20:18:56 +00:00
// Check state
$this -> assertTrue ( count ( $cm -> getReflectionProperties ()) > 0 );
2010-04-30 17:30:27 +02:00
$this -> assertEquals ( 'Doctrine\Tests\Models\CMS' , $cm -> namespace );
2016-12-08 18:01:04 +01:00
$this -> assertInstanceOf ( \ReflectionClass :: class , $cm -> reflClass );
$this -> assertEquals ( CMS\CmsUser :: class , $cm -> name );
2009-05-14 10:03:09 +00:00
$this -> assertEquals ( 'UserParent' , $cm -> rootEntityName );
2016-12-08 18:01:04 +01:00
$this -> assertEquals ([ CMS\One :: class , CMS\Two :: class , CMS\Three :: class ], $cm -> subClasses );
2016-12-07 23:33:41 +01:00
$this -> assertEquals ([ 'UserParent' ], $cm -> parentClasses );
2016-12-08 18:01:04 +01:00
$this -> assertEquals ( CMS\UserRepository :: class , $cm -> customRepositoryClassName );
2016-12-07 23:33:41 +01:00
$this -> assertEquals ([ 'name' => 'disc' , 'type' => 'integer' , 'fieldName' => 'disc' ], $cm -> discriminatorColumn );
2010-08-09 13:13:21 +02:00
$this -> assertTrue ( $cm -> associationMappings [ 'phonenumbers' ][ 'type' ] == ClassMetadata :: ONE_TO_ONE );
2009-05-14 10:03:09 +00:00
$this -> assertEquals ( 1 , count ( $cm -> associationMappings ));
2009-01-12 13:34:41 +00:00
$oneOneMapping = $cm -> getAssociationMapping ( 'phonenumbers' );
2010-08-09 13:13:21 +02:00
$this -> assertTrue ( $oneOneMapping [ 'fetch' ] == ClassMetadata :: FETCH_LAZY );
$this -> assertEquals ( 'phonenumbers' , $oneOneMapping [ 'fieldName' ]);
2016-12-08 18:01:04 +01:00
$this -> assertEquals ( CMS\CmsAddress :: class , $oneOneMapping [ 'targetEntity' ]);
2011-03-29 20:04:14 +02:00
$this -> assertTrue ( $cm -> isReadOnly );
2016-12-07 23:33:41 +01:00
$this -> assertEquals ([ 'dql' => [ 'name' => 'dql' , 'query' => 'foo' , 'dql' => 'foo' ]], $cm -> namedQueries );
2009-01-05 20:18:56 +00:00
}
2009-11-02 12:53:05 +00:00
public function testFieldIsNullable ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2009-11-02 12:53:05 +00:00
// Explicit Nullable
2016-12-07 23:33:41 +01:00
$cm -> mapField ([ 'fieldName' => 'status' , 'nullable' => true , 'type' => 'string' , 'length' => 50 ]);
2009-11-02 12:53:05 +00:00
$this -> assertTrue ( $cm -> isNullable ( 'status' ));
// Explicit Not Nullable
2016-12-07 23:33:41 +01:00
$cm -> mapField ([ 'fieldName' => 'username' , 'nullable' => false , 'type' => 'string' , 'length' => 50 ]);
2009-11-02 12:53:05 +00:00
$this -> assertFalse ( $cm -> isNullable ( 'username' ));
// Implicit Not Nullable
2016-12-07 23:33:41 +01:00
$cm -> mapField ([ 'fieldName' => 'name' , 'type' => 'string' , 'length' => 50 ]);
2009-11-02 12:53:05 +00:00
$this -> assertFalse ( $cm -> isNullable ( 'name' ), " By default a field should not be nullable. " );
}
2009-11-04 23:06:38 +00:00
/**
* @ group DDC - 115
*/
2013-03-11 00:08:58 +00:00
public function testMapAssociationInGlobalNamespace ()
2009-11-04 23:06:38 +00:00
{
require_once __DIR__ . " /../../Models/Global/GlobalNamespaceModel.php " ;
$cm = new ClassMetadata ( 'DoctrineGlobal_Article' );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2016-12-07 23:33:41 +01:00
$cm -> mapManyToMany (
[
2009-11-04 23:06:38 +00:00
'fieldName' => 'author' ,
'targetEntity' => 'DoctrineGlobal_User' ,
2016-12-07 23:33:41 +01:00
'joinTable' => [
2009-11-04 23:06:38 +00:00
'name' => 'bar' ,
2016-12-07 23:33:41 +01:00
'joinColumns' => [[ 'name' => 'bar_id' , 'referencedColumnName' => 'id' ]],
'inverseJoinColumns' => [[ 'name' => 'baz_id' , 'referencedColumnName' => 'id' ]],
],
]
);
2009-11-04 23:06:38 +00:00
2010-08-09 13:13:21 +02:00
$this -> assertEquals ( " DoctrineGlobal_User " , $cm -> associationMappings [ 'author' ][ 'targetEntity' ]);
2009-11-04 23:06:38 +00:00
}
2011-12-19 22:56:19 +01:00
2010-02-09 17:13:49 +00:00
public function testMapManyToManyJoinTableDefaults ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2010-02-09 17:13:49 +00:00
$cm -> mapManyToMany (
2016-12-07 23:33:41 +01:00
[
2010-02-09 17:13:49 +00:00
'fieldName' => 'groups' ,
'targetEntity' => 'CmsGroup'
2016-12-07 23:33:41 +01:00
]
);
2011-12-19 22:56:19 +01:00
2010-02-09 17:13:49 +00:00
$assoc = $cm -> associationMappings [ 'groups' ];
2016-12-07 23:33:41 +01:00
$this -> assertEquals (
[
2010-08-26 13:47:22 +02:00
'name' => 'cmsuser_cmsgroup' ,
2016-12-07 23:33:41 +01:00
'joinColumns' => [[ 'name' => 'cmsuser_id' , 'referencedColumnName' => 'id' , 'onDelete' => 'CASCADE' ]],
'inverseJoinColumns' => [[ 'name' => 'cmsgroup_id' , 'referencedColumnName' => 'id' , 'onDelete' => 'CASCADE' ]]
], $assoc [ 'joinTable' ]);
2010-08-09 13:13:21 +02:00
$this -> assertTrue ( $assoc [ 'isOnDeleteCascade' ]);
2010-07-10 12:04:02 +02:00
}
public function testSerializeManyToManyJoinTableCascade ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2010-07-10 12:04:02 +02:00
$cm -> mapManyToMany (
2016-12-07 23:33:41 +01:00
[
2010-07-10 12:04:02 +02:00
'fieldName' => 'groups' ,
'targetEntity' => 'CmsGroup'
2016-12-07 23:33:41 +01:00
]
);
2010-07-10 12:04:02 +02:00
2016-12-08 18:01:04 +01:00
/* @var $assoc \Doctrine\ORM\Mapping\ManyToMany */
2010-07-10 12:04:02 +02:00
$assoc = $cm -> associationMappings [ 'groups' ];
$assoc = unserialize ( serialize ( $assoc ));
2010-08-09 13:13:21 +02:00
$this -> assertTrue ( $assoc [ 'isOnDeleteCascade' ]);
2010-02-09 17:13:49 +00:00
}
2009-11-04 23:06:38 +00:00
/**
* @ group DDC - 115
*/
public function testSetDiscriminatorMapInGlobalNamespace ()
{
require_once __DIR__ . " /../../Models/Global/GlobalNamespaceModel.php " ;
$cm = new ClassMetadata ( 'DoctrineGlobal_User' );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2016-12-07 23:33:41 +01:00
$cm -> setDiscriminatorMap ([ 'descr' => 'DoctrineGlobal_Article' , 'foo' => 'DoctrineGlobal_User' ]);
2009-11-04 23:06:38 +00:00
$this -> assertEquals ( " DoctrineGlobal_Article " , $cm -> discriminatorMap [ 'descr' ]);
$this -> assertEquals ( " DoctrineGlobal_User " , $cm -> discriminatorMap [ 'foo' ]);
}
/**
* @ group DDC - 115
*/
public function testSetSubClassesInGlobalNamespace ()
{
require_once __DIR__ . " /../../Models/Global/GlobalNamespaceModel.php " ;
$cm = new ClassMetadata ( 'DoctrineGlobal_User' );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2016-12-07 23:33:41 +01:00
$cm -> setSubclasses ([ 'DoctrineGlobal_Article' ]);
2009-11-04 23:06:38 +00:00
$this -> assertEquals ( " DoctrineGlobal_Article " , $cm -> subClasses [ 0 ]);
}
2010-02-02 21:17:00 +00:00
/**
* @ group DDC - 268
*/
public function testSetInvalidVersionMapping_ThrowsException ()
{
2016-12-07 23:33:41 +01:00
$field = [];
2010-02-02 21:17:00 +00:00
$field [ 'fieldName' ] = 'foo' ;
$field [ 'type' ] = 'string' ;
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2010-02-02 21:17:00 +00:00
2016-06-18 13:01:59 +02:00
$this -> expectException ( \Doctrine\ORM\Mapping\MappingException :: class );
2010-02-02 21:17:00 +00:00
$cm -> setVersionMapping ( $field );
}
public function testGetSingleIdentifierFieldName_MultipleIdentifierEntity_ThrowsException ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2010-02-02 21:17:00 +00:00
$cm -> isIdentifierComposite = true ;
2016-06-18 13:01:59 +02:00
$this -> expectException ( \Doctrine\ORM\Mapping\MappingException :: class );
2010-02-02 21:17:00 +00:00
$cm -> getSingleIdentifierFieldName ();
}
2010-02-02 21:46:39 +00:00
public function testDuplicateAssociationMappingException ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2012-01-02 17:06:22 +01:00
2016-12-07 23:33:41 +01:00
$a1 = [ 'fieldName' => 'foo' , 'sourceEntity' => 'stdClass' , 'targetEntity' => 'stdClass' , 'mappedBy' => 'foo' ];
$a2 = [ 'fieldName' => 'foo' , 'sourceEntity' => 'stdClass' , 'targetEntity' => 'stdClass' , 'mappedBy' => 'foo' ];
2010-02-02 21:46:39 +00:00
2010-04-14 17:07:08 +02:00
$cm -> addInheritedAssociationMapping ( $a1 );
2016-06-18 13:01:59 +02:00
$this -> expectException ( \Doctrine\ORM\Mapping\MappingException :: class );
2010-04-14 17:07:08 +02:00
$cm -> addInheritedAssociationMapping ( $a2 );
2010-02-02 21:46:39 +00:00
}
2010-03-20 19:23:13 +00:00
public function testDuplicateColumnName_ThrowsMappingException ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2012-01-02 17:06:22 +01:00
2016-12-07 23:33:41 +01:00
$cm -> mapField ([ 'fieldName' => 'name' , 'columnName' => 'name' ]);
2010-03-20 19:23:13 +00:00
2016-06-18 13:01:59 +02:00
$this -> expectException ( \Doctrine\ORM\Mapping\MappingException :: class );
2016-12-07 23:33:41 +01:00
$cm -> mapField ([ 'fieldName' => 'username' , 'columnName' => 'name' ]);
2010-03-20 19:23:13 +00:00
}
public function testDuplicateColumnName_DiscriminatorColumn_ThrowsMappingException ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2012-01-02 17:06:22 +01:00
2016-12-07 23:33:41 +01:00
$cm -> mapField ([ 'fieldName' => 'name' , 'columnName' => 'name' ]);
2010-03-20 19:23:13 +00:00
2016-06-18 13:01:59 +02:00
$this -> expectException ( \Doctrine\ORM\Mapping\MappingException :: class );
2016-12-07 23:33:41 +01:00
$cm -> setDiscriminatorColumn ([ 'name' => 'name' ]);
2010-03-20 19:23:13 +00:00
}
public function testDuplicateColumnName_DiscriminatorColumn2_ThrowsMappingException ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2012-01-02 17:06:22 +01:00
2016-12-07 23:33:41 +01:00
$cm -> setDiscriminatorColumn ([ 'name' => 'name' ]);
2010-03-20 19:23:13 +00:00
2016-06-18 13:01:59 +02:00
$this -> expectException ( \Doctrine\ORM\Mapping\MappingException :: class );
2016-12-07 23:33:41 +01:00
$cm -> mapField ([ 'fieldName' => 'name' , 'columnName' => 'name' ]);
2010-03-20 19:23:13 +00:00
}
2013-03-11 00:08:58 +00:00
public function testDuplicateFieldAndAssociationMapping1_ThrowsException ()
2010-03-20 19:23:13 +00:00
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2012-01-02 17:06:22 +01:00
2016-12-07 23:33:41 +01:00
$cm -> mapField ([ 'fieldName' => 'name' , 'columnName' => 'name' ]);
2010-03-20 19:23:13 +00:00
2016-06-18 13:01:59 +02:00
$this -> expectException ( \Doctrine\ORM\Mapping\MappingException :: class );
2016-12-07 23:33:41 +01:00
$cm -> mapOneToOne ([ 'fieldName' => 'name' , 'targetEntity' => 'CmsUser' ]);
2010-03-20 19:23:13 +00:00
}
2013-03-11 00:08:58 +00:00
public function testDuplicateFieldAndAssociationMapping2_ThrowsException ()
2010-03-20 19:23:13 +00:00
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2012-01-02 17:06:22 +01:00
2016-12-07 23:33:41 +01:00
$cm -> mapOneToOne ([ 'fieldName' => 'name' , 'targetEntity' => 'CmsUser' ]);
2010-03-20 19:23:13 +00:00
2016-06-18 13:01:59 +02:00
$this -> expectException ( \Doctrine\ORM\Mapping\MappingException :: class );
2016-12-07 23:33:41 +01:00
$cm -> mapField ([ 'fieldName' => 'name' , 'columnName' => 'name' ]);
2010-03-20 19:23:13 +00:00
}
2011-12-19 22:56:19 +01:00
2011-06-26 10:10:57 +02:00
/**
* @ group DDC - 1224
*/
public function testGetTemporaryTableNameSchema ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2012-01-02 17:06:22 +01:00
2011-06-26 10:10:57 +02:00
$cm -> setTableName ( 'foo.bar' );
2011-12-19 22:56:19 +01:00
2011-06-26 10:10:57 +02:00
$this -> assertEquals ( 'foo_bar_id_tmp' , $cm -> getTemporaryIdTableName ());
}
2010-08-26 13:47:22 +02:00
public function testDefaultTableName ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2010-08-26 13:47:22 +02:00
// When table's name is not given
2016-12-07 23:33:41 +01:00
$primaryTable = [];
2010-08-26 13:47:22 +02:00
$cm -> setPrimaryTable ( $primaryTable );
$this -> assertEquals ( 'CmsUser' , $cm -> getTableName ());
$this -> assertEquals ( 'CmsUser' , $cm -> table [ 'name' ]);
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsAddress :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2010-08-26 13:47:22 +02:00
// When joinTable's name is not given
2016-12-07 23:33:41 +01:00
$cm -> mapManyToMany (
[
2016-12-08 18:01:04 +01:00
'fieldName' => 'user' ,
'targetEntity' => 'CmsUser' ,
'inversedBy' => 'users' ,
'joinTable' => [
'joinColumns' => [[ 'referencedColumnName' => 'id' ]],
'inverseJoinColumns' => [[ 'referencedColumnName' => 'id' ]]
]
2016-12-07 23:33:41 +01:00
]
);
2010-08-26 13:47:22 +02:00
$this -> assertEquals ( 'cmsaddress_cmsuser' , $cm -> associationMappings [ 'user' ][ 'joinTable' ][ 'name' ]);
}
public function testDefaultJoinColumnName ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsAddress :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2012-01-02 17:06:22 +01:00
2013-03-11 00:08:58 +00:00
// this is really dirty, but it's the simplest way to test whether
2010-08-26 13:47:22 +02:00
// joinColumn's name will be automatically set to user_id
2016-12-07 23:33:41 +01:00
$cm -> mapOneToOne (
[
2010-08-26 13:47:22 +02:00
'fieldName' => 'user' ,
'targetEntity' => 'CmsUser' ,
2016-12-07 23:33:41 +01:00
'joinColumns' => [[ 'referencedColumnName' => 'id' ]]
]
);
2010-08-26 13:47:22 +02:00
$this -> assertEquals ( 'user_id' , $cm -> associationMappings [ 'user' ][ 'joinColumns' ][ 0 ][ 'name' ]);
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsAddress :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2016-12-07 23:33:41 +01:00
$cm -> mapManyToMany (
[
2010-08-26 13:47:22 +02:00
'fieldName' => 'user' ,
'targetEntity' => 'CmsUser' ,
'inversedBy' => 'users' ,
2016-12-07 23:33:41 +01:00
'joinTable' => [
2016-12-08 18:01:04 +01:00
'name' => 'user_CmsUser' ,
'joinColumns' => [[ 'referencedColumnName' => 'id' ]],
'inverseJoinColumns' => [[ 'referencedColumnName' => 'id' ]]
]
2016-12-07 23:33:41 +01:00
]
);
2010-08-26 13:47:22 +02:00
$this -> assertEquals ( 'cmsaddress_id' , $cm -> associationMappings [ 'user' ][ 'joinTable' ][ 'joinColumns' ][ 0 ][ 'name' ]);
$this -> assertEquals ( 'cmsuser_id' , $cm -> associationMappings [ 'user' ][ 'joinTable' ][ 'inverseJoinColumns' ][ 0 ][ 'name' ]);
}
2010-11-27 17:38:12 +01:00
2011-12-23 14:13:21 -02:00
/**
* @ group DDC - 559
*/
public function testUnderscoreNamingStrategyDefaults ()
{
2016-05-11 01:55:12 +07:00
$namingStrategy = new UnderscoreNamingStrategy ( CASE_UPPER );
2016-12-08 18:01:04 +01:00
$oneToOneMetadata = new ClassMetadata ( CMS\CmsAddress :: class , $namingStrategy );
$manyToManyMetadata = new ClassMetadata ( CMS\CmsAddress :: class , $namingStrategy );
2011-12-23 14:13:21 -02:00
2016-12-07 23:33:41 +01:00
$oneToOneMetadata -> mapOneToOne (
[
2011-12-23 14:13:21 -02:00
'fieldName' => 'user' ,
'targetEntity' => 'CmsUser'
2016-12-07 23:33:41 +01:00
]
);
2011-12-23 14:13:21 -02:00
2016-12-07 23:33:41 +01:00
$manyToManyMetadata -> mapManyToMany (
[
2011-12-23 14:13:21 -02:00
'fieldName' => 'user' ,
'targetEntity' => 'CmsUser'
2016-12-07 23:33:41 +01:00
]
);
2013-05-17 12:08:14 +02:00
2016-12-07 23:33:41 +01:00
$this -> assertEquals ([ 'USER_ID' => 'ID' ], $oneToOneMetadata -> associationMappings [ 'user' ][ 'sourceToTargetKeyColumns' ]);
$this -> assertEquals ([ 'USER_ID' => 'USER_ID' ], $oneToOneMetadata -> associationMappings [ 'user' ][ 'joinColumnFieldNames' ]);
$this -> assertEquals ([ 'ID' => 'USER_ID' ], $oneToOneMetadata -> associationMappings [ 'user' ][ 'targetToSourceKeyColumns' ]);
2011-12-23 14:13:21 -02:00
$this -> assertEquals ( 'USER_ID' , $oneToOneMetadata -> associationMappings [ 'user' ][ 'joinColumns' ][ 0 ][ 'name' ]);
$this -> assertEquals ( 'ID' , $oneToOneMetadata -> associationMappings [ 'user' ][ 'joinColumns' ][ 0 ][ 'referencedColumnName' ]);
2013-05-17 12:08:14 +02:00
2011-12-23 14:13:21 -02:00
$this -> assertEquals ( 'CMS_ADDRESS_CMS_USER' , $manyToManyMetadata -> associationMappings [ 'user' ][ 'joinTable' ][ 'name' ]);
2016-12-07 23:33:41 +01:00
$this -> assertEquals ([ 'CMS_ADDRESS_ID' , 'CMS_USER_ID' ], $manyToManyMetadata -> associationMappings [ 'user' ][ 'joinTableColumns' ]);
$this -> assertEquals ([ 'CMS_ADDRESS_ID' => 'ID' ], $manyToManyMetadata -> associationMappings [ 'user' ][ 'relationToSourceKeyColumns' ]);
$this -> assertEquals ([ 'CMS_USER_ID' => 'ID' ], $manyToManyMetadata -> associationMappings [ 'user' ][ 'relationToTargetKeyColumns' ]);
2011-12-23 14:13:21 -02:00
$this -> assertEquals ( 'CMS_ADDRESS_ID' , $manyToManyMetadata -> associationMappings [ 'user' ][ 'joinTable' ][ 'joinColumns' ][ 0 ][ 'name' ]);
$this -> assertEquals ( 'CMS_USER_ID' , $manyToManyMetadata -> associationMappings [ 'user' ][ 'joinTable' ][ 'inverseJoinColumns' ][ 0 ][ 'name' ]);
$this -> assertEquals ( 'ID' , $manyToManyMetadata -> associationMappings [ 'user' ][ 'joinTable' ][ 'joinColumns' ][ 0 ][ 'referencedColumnName' ]);
$this -> assertEquals ( 'ID' , $manyToManyMetadata -> associationMappings [ 'user' ][ 'joinTable' ][ 'inverseJoinColumns' ][ 0 ][ 'referencedColumnName' ]);
$cm = new ClassMetadata ( 'DoctrineGlobal_Article' , $namingStrategy );
2016-12-08 18:01:04 +01:00
$cm -> mapManyToMany ([ 'fieldName' => 'author' , 'targetEntity' => CMS\CmsUser :: class ]);
2011-12-23 14:13:21 -02:00
$this -> assertEquals ( 'DOCTRINE_GLOBAL_ARTICLE_CMS_USER' , $cm -> associationMappings [ 'author' ][ 'joinTable' ][ 'name' ]);
}
2010-11-27 17:38:12 +01:00
/**
* @ group DDC - 886
*/
public function testSetMultipleIdentifierSetsComposite ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2012-01-02 17:06:22 +01:00
2016-12-07 23:33:41 +01:00
$cm -> mapField ([ 'fieldName' => 'name' ]);
$cm -> mapField ([ 'fieldName' => 'username' ]);
2010-11-27 17:38:12 +01:00
2016-12-07 23:33:41 +01:00
$cm -> setIdentifier ([ 'name' , 'username' ]);
2010-11-27 17:38:12 +01:00
$this -> assertTrue ( $cm -> isIdentifierComposite );
}
2010-12-22 00:17:50 +01:00
/**
* @ group DDC - 944
*/
public function testMappingNotFound ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2010-12-22 00:17:50 +01:00
2016-06-18 13:01:59 +02:00
$this -> expectException ( MappingException :: class );
2016-12-08 18:01:04 +01:00
$this -> expectExceptionMessage ( " No mapping found for field 'foo' on class ' " . CMS\CmsUser :: class . " '. " );
2016-06-18 13:01:59 +02:00
2010-12-22 00:17:50 +01:00
$cm -> getFieldMapping ( 'foo' );
}
2010-12-30 22:30:51 +01:00
/**
* @ group DDC - 961
*/
public function testJoinTableMappingDefaults ()
{
$cm = new ClassMetadata ( 'DoctrineGlobal_Article' );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2012-01-02 17:06:22 +01:00
2016-12-08 18:01:04 +01:00
$cm -> mapManyToMany ([ 'fieldName' => 'author' , 'targetEntity' => CMS\CmsUser :: class ]);
2010-12-30 22:30:51 +01:00
$this -> assertEquals ( 'doctrineglobal_article_cmsuser' , $cm -> associationMappings [ 'author' ][ 'joinTable' ][ 'name' ]);
}
2011-01-02 12:01:05 +01:00
2011-01-01 18:17:19 +01:00
/**
* @ group DDC - 117
*/
public function testMapIdentifierAssociation ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( DDC117ArticleDetails :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2012-01-02 17:06:22 +01:00
2016-12-07 23:33:41 +01:00
$cm -> mapOneToOne (
[
2011-01-01 18:17:19 +01:00
'fieldName' => 'article' ,
'id' => true ,
2016-12-08 18:01:04 +01:00
'targetEntity' => DDC117Article :: class ,
2016-12-07 23:33:41 +01:00
'joinColumns' => [],
]
);
2011-01-01 18:17:19 +01:00
$this -> assertTrue ( $cm -> containsForeignIdentifier , " Identifier Association should set 'containsForeignIdentifier' boolean flag. " );
2016-12-07 23:33:41 +01:00
$this -> assertEquals ([ " article " ], $cm -> identifier );
2011-01-01 18:17:19 +01:00
}
/**
* @ group DDC - 117
*/
public function testOrphanRemovalIdentifierAssociation ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( DDC117ArticleDetails :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2011-01-01 18:17:19 +01:00
2016-06-18 13:01:59 +02:00
$this -> expectException ( MappingException :: class );
$this -> expectExceptionMessage ( 'The orphan removal option is not allowed on an association that' );
2016-12-07 23:33:41 +01:00
$cm -> mapOneToOne (
[
2011-01-01 18:17:19 +01:00
'fieldName' => 'article' ,
'id' => true ,
2016-12-08 18:01:04 +01:00
'targetEntity' => DDC117Article :: class ,
2011-01-01 18:17:19 +01:00
'orphanRemoval' => true ,
2016-12-07 23:33:41 +01:00
'joinColumns' => [],
]
);
2011-01-01 18:17:19 +01:00
}
/**
* @ group DDC - 117
*/
2013-03-11 00:08:58 +00:00
public function testInverseIdentifierAssociation ()
2011-01-01 18:17:19 +01:00
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( DDC117ArticleDetails :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2012-01-02 17:06:22 +01:00
2016-06-18 13:01:59 +02:00
$this -> expectException ( MappingException :: class );
$this -> expectExceptionMessage ( 'An inverse association is not allowed to be identifier in' );
2011-01-01 18:17:19 +01:00
2016-12-07 23:33:41 +01:00
$cm -> mapOneToOne (
[
2011-01-01 18:17:19 +01:00
'fieldName' => 'article' ,
'id' => true ,
'mappedBy' => 'details' , // INVERSE!
2016-12-08 18:01:04 +01:00
'targetEntity' => DDC117Article :: class ,
2016-12-07 23:33:41 +01:00
'joinColumns' => [],
]
);
2011-01-01 18:17:19 +01:00
}
/**
* @ group DDC - 117
*/
2013-03-11 00:08:58 +00:00
public function testIdentifierAssociationManyToMany ()
2011-01-01 18:17:19 +01:00
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( DDC117ArticleDetails :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2012-01-02 17:06:22 +01:00
2016-06-18 13:01:59 +02:00
$this -> expectException ( MappingException :: class );
$this -> expectExceptionMessage ( 'Many-to-many or one-to-many associations are not allowed to be identifier in' );
2011-01-01 18:17:19 +01:00
2016-12-07 23:33:41 +01:00
$cm -> mapManyToMany (
[
2011-01-01 18:17:19 +01:00
'fieldName' => 'article' ,
'id' => true ,
2016-12-08 18:01:04 +01:00
'targetEntity' => DDC117Article :: class ,
2016-12-07 23:33:41 +01:00
'joinColumns' => [],
]
);
2011-01-01 18:17:19 +01:00
}
2011-01-23 14:20:15 +01:00
/**
* @ group DDC - 996
*/
public function testEmptyFieldNameThrowsException ()
{
2016-06-18 13:01:59 +02:00
$this -> expectException ( MappingException :: class );
2016-12-08 18:01:04 +01:00
$this -> expectExceptionMessage ( " The field or association mapping misses the 'fieldName' attribute in entity ' " . CMS\CmsUser :: class . " '. " );
2016-06-18 13:01:59 +02:00
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2012-01-02 17:06:22 +01:00
2016-12-07 23:33:41 +01:00
$cm -> mapField ([ 'fieldName' => '' ]);
2011-01-23 14:20:15 +01:00
}
2011-03-06 18:45:09 -03:00
public function testRetrievalOfNamedQueries ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2012-01-02 17:06:22 +01:00
2011-03-06 18:45:09 -03:00
$this -> assertEquals ( 0 , count ( $cm -> getNamedQueries ()));
2016-12-07 23:33:41 +01:00
$cm -> addNamedQuery (
[
2011-03-06 18:45:09 -03:00
'name' => 'userById' ,
'query' => 'SELECT u FROM __CLASS__ u WHERE u.id = ?1'
2016-12-07 23:33:41 +01:00
]
);
2011-03-06 18:45:09 -03:00
$this -> assertEquals ( 1 , count ( $cm -> getNamedQueries ()));
}
2012-02-26 00:16:54 -03:00
/**
* @ group DDC - 1663
*/
public function testRetrievalOfResultSetMappings ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2012-02-26 00:16:54 -03:00
$this -> assertEquals ( 0 , count ( $cm -> getSqlResultSetMappings ()));
2016-12-07 23:33:41 +01:00
$cm -> addSqlResultSetMapping (
[
2012-02-26 00:16:54 -03:00
'name' => 'find-all' ,
2016-12-07 23:33:41 +01:00
'entities' => [
[
2016-12-08 18:01:04 +01:00
'entityClass' => CMS\CmsUser :: class ,
2016-12-07 23:33:41 +01:00
],
],
]
);
2012-02-26 00:16:54 -03:00
$this -> assertEquals ( 1 , count ( $cm -> getSqlResultSetMappings ()));
}
2011-03-06 18:45:09 -03:00
public function testExistanceOfNamedQuery ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2012-01-02 17:06:22 +01:00
2011-03-06 18:45:09 -03:00
2016-12-07 23:33:41 +01:00
$cm -> addNamedQuery (
[
2011-03-06 18:45:09 -03:00
'name' => 'all' ,
'query' => 'SELECT u FROM __CLASS__ u'
2016-12-07 23:33:41 +01:00
]
);
2011-03-06 18:45:09 -03:00
$this -> assertTrue ( $cm -> hasNamedQuery ( 'all' ));
$this -> assertFalse ( $cm -> hasNamedQuery ( 'userById' ));
}
2012-02-25 23:13:46 -02:00
/**
* @ group DDC - 1663
*/
public function testRetrieveOfNamedNativeQuery ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2012-02-25 23:13:46 -02:00
2016-12-07 23:33:41 +01:00
$cm -> addNamedNativeQuery (
[
2012-02-25 23:13:46 -02:00
'name' => 'find-all' ,
'query' => 'SELECT * FROM cms_users' ,
'resultSetMapping' => 'result-mapping-name' ,
2016-12-08 18:01:04 +01:00
'resultClass' => CMS\CmsUser :: class ,
2016-12-07 23:33:41 +01:00
]
);
2012-02-25 23:13:46 -02:00
2016-12-07 23:33:41 +01:00
$cm -> addNamedNativeQuery (
[
2012-02-25 23:13:46 -02:00
'name' => 'find-by-id' ,
'query' => 'SELECT * FROM cms_users WHERE id = ?' ,
'resultClass' => '__CLASS__' ,
'resultSetMapping' => 'result-mapping-name' ,
2016-12-07 23:33:41 +01:00
]
);
2012-02-25 23:13:46 -02:00
$mapping = $cm -> getNamedNativeQuery ( 'find-all' );
$this -> assertEquals ( 'SELECT * FROM cms_users' , $mapping [ 'query' ]);
$this -> assertEquals ( 'result-mapping-name' , $mapping [ 'resultSetMapping' ]);
2016-12-08 18:01:04 +01:00
$this -> assertEquals ( CMS\CmsUser :: class , $mapping [ 'resultClass' ]);
2012-02-25 23:13:46 -02:00
$mapping = $cm -> getNamedNativeQuery ( 'find-by-id' );
$this -> assertEquals ( 'SELECT * FROM cms_users WHERE id = ?' , $mapping [ 'query' ]);
$this -> assertEquals ( 'result-mapping-name' , $mapping [ 'resultSetMapping' ]);
2016-12-08 18:01:04 +01:00
$this -> assertEquals ( CMS\CmsUser :: class , $mapping [ 'resultClass' ]);
2012-02-25 23:13:46 -02:00
}
2012-02-26 00:16:54 -03:00
/**
* @ group DDC - 1663
*/
public function testRetrieveOfSqlResultSetMapping ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2012-02-26 00:16:54 -03:00
2016-12-07 23:33:41 +01:00
$cm -> addSqlResultSetMapping (
[
2012-02-26 00:16:54 -03:00
'name' => 'find-all' ,
2016-12-07 23:33:41 +01:00
'entities' => [
[
2012-02-26 00:16:54 -03:00
'entityClass' => '__CLASS__' ,
2016-12-07 23:33:41 +01:00
'fields' => [
[
2012-02-26 00:16:54 -03:00
'name' => 'id' ,
'column' => 'id'
2016-12-07 23:33:41 +01:00
],
[
2012-02-26 00:16:54 -03:00
'name' => 'name' ,
'column' => 'name'
2016-12-07 23:33:41 +01:00
]
]
],
[
2016-12-08 18:01:04 +01:00
'entityClass' => CMS\CmsEmail :: class ,
2016-12-07 23:33:41 +01:00
'fields' => [
[
2012-02-26 00:16:54 -03:00
'name' => 'id' ,
'column' => 'id'
2016-12-07 23:33:41 +01:00
],
[
2012-02-26 00:16:54 -03:00
'name' => 'email' ,
'column' => 'email'
2016-12-07 23:33:41 +01:00
]
]
]
],
'columns' => [
[
2012-02-26 00:16:54 -03:00
'name' => 'scalarColumn'
2016-12-07 23:33:41 +01:00
]
]
]
);
2012-02-26 00:16:54 -03:00
$mapping = $cm -> getSqlResultSetMapping ( 'find-all' );
2016-12-08 18:01:04 +01:00
$this -> assertEquals ( CMS\CmsUser :: class , $mapping [ 'entities' ][ 0 ][ 'entityClass' ]);
2016-12-07 23:33:41 +01:00
$this -> assertEquals ([ 'name' => 'id' , 'column' => 'id' ], $mapping [ 'entities' ][ 0 ][ 'fields' ][ 0 ]);
$this -> assertEquals ([ 'name' => 'name' , 'column' => 'name' ], $mapping [ 'entities' ][ 0 ][ 'fields' ][ 1 ]);
2012-02-26 00:16:54 -03:00
2016-12-08 18:01:04 +01:00
$this -> assertEquals ( CMS\CmsEmail :: class , $mapping [ 'entities' ][ 1 ][ 'entityClass' ]);
2016-12-07 23:33:41 +01:00
$this -> assertEquals ([ 'name' => 'id' , 'column' => 'id' ], $mapping [ 'entities' ][ 1 ][ 'fields' ][ 0 ]);
$this -> assertEquals ([ 'name' => 'email' , 'column' => 'email' ], $mapping [ 'entities' ][ 1 ][ 'fields' ][ 1 ]);
2012-02-26 00:16:54 -03:00
$this -> assertEquals ( 'scalarColumn' , $mapping [ 'columns' ][ 0 ][ 'name' ]);
}
/**
* @ group DDC - 1663
*/
public function testExistanceOfSqlResultSetMapping ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2012-02-26 00:16:54 -03:00
2016-12-07 23:33:41 +01:00
$cm -> addSqlResultSetMapping (
[
2012-02-26 00:16:54 -03:00
'name' => 'find-all' ,
2016-12-07 23:33:41 +01:00
'entities' => [
[
2016-12-08 18:01:04 +01:00
'entityClass' => CMS\CmsUser :: class ,
2016-12-07 23:33:41 +01:00
],
],
]
);
2012-02-26 00:16:54 -03:00
$this -> assertTrue ( $cm -> hasSqlResultSetMapping ( 'find-all' ));
$this -> assertFalse ( $cm -> hasSqlResultSetMapping ( 'find-by-id' ));
}
2012-02-25 23:13:46 -02:00
/**
* @ group DDC - 1663
*/
public function testExistanceOfNamedNativeQuery ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2012-02-25 23:13:46 -02:00
2016-12-07 23:33:41 +01:00
$cm -> addNamedNativeQuery (
[
2012-02-25 23:13:46 -02:00
'name' => 'find-all' ,
'query' => 'SELECT * FROM cms_users' ,
2016-12-08 18:01:04 +01:00
'resultClass' => CMS\CmsUser :: class ,
2012-02-25 23:13:46 -02:00
'resultSetMapping' => 'result-mapping-name'
2016-12-07 23:33:41 +01:00
]
);
2012-02-25 23:13:46 -02:00
$this -> assertTrue ( $cm -> hasNamedNativeQuery ( 'find-all' ));
$this -> assertFalse ( $cm -> hasNamedNativeQuery ( 'find-by-id' ));
}
2011-03-06 18:45:09 -03:00
public function testRetrieveOfNamedQuery ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2012-01-02 17:06:22 +01:00
2011-03-06 18:45:09 -03:00
2016-12-07 23:33:41 +01:00
$cm -> addNamedQuery (
[
2011-03-06 18:45:09 -03:00
'name' => 'userById' ,
'query' => 'SELECT u FROM __CLASS__ u WHERE u.id = ?1'
2016-12-07 23:33:41 +01:00
]
);
2011-03-06 18:45:09 -03:00
$this -> assertEquals ( 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = ?1' , $cm -> getNamedQuery ( 'userById' ));
}
2012-02-25 23:13:46 -02:00
/**
* @ group DDC - 1663
*/
public function testRetrievalOfNamedNativeQueries ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2012-02-25 23:13:46 -02:00
$this -> assertEquals ( 0 , count ( $cm -> getNamedNativeQueries ()));
2016-12-07 23:33:41 +01:00
$cm -> addNamedNativeQuery (
[
2012-02-25 23:13:46 -02:00
'name' => 'find-all' ,
'query' => 'SELECT * FROM cms_users' ,
2016-12-08 18:01:04 +01:00
'resultClass' => CMS\CmsUser :: class ,
2012-02-25 23:13:46 -02:00
'resultSetMapping' => 'result-mapping-name'
2016-12-07 23:33:41 +01:00
]
);
2012-02-25 23:13:46 -02:00
$this -> assertEquals ( 1 , count ( $cm -> getNamedNativeQueries ()));
}
2013-05-17 11:42:11 -03:00
/**
* @ group DDC - 2451
*/
public function testSerializeEntityListeners ()
{
2016-12-08 18:01:04 +01:00
$metadata = new ClassMetadata ( CompanyContract :: class );
2013-05-17 11:42:11 -03:00
2014-08-14 15:51:17 +02:00
$metadata -> initializeReflection ( new RuntimeReflectionService ());
2016-05-11 01:55:12 +07:00
$metadata -> addEntityListener ( Events :: prePersist , 'CompanyContractListener' , 'prePersistHandler' );
$metadata -> addEntityListener ( Events :: postPersist , 'CompanyContractListener' , 'postPersistHandler' );
2013-05-17 11:42:11 -03:00
$serialize = serialize ( $metadata );
$unserialize = unserialize ( $serialize );
2013-05-17 11:55:36 -03:00
$this -> assertEquals ( $metadata -> entityListeners , $unserialize -> entityListeners );
2013-05-17 11:42:11 -03:00
}
2012-02-26 00:16:54 -03:00
/**
* @ expectedException \Doctrine\ORM\Mapping\MappingException
* @ expectedExceptionMessage Query named " userById " in " Doctrine \T ests \ Models \ CMS \ CmsUser " was already declared , but it must be declared only once
*/
2011-03-06 18:45:09 -03:00
public function testNamingCollisionNamedQueryShouldThrowException ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2012-01-02 17:06:22 +01:00
2016-12-07 23:33:41 +01:00
$cm -> addNamedQuery (
[
2011-03-06 18:45:09 -03:00
'name' => 'userById' ,
'query' => 'SELECT u FROM __CLASS__ u WHERE u.id = ?1'
2016-12-07 23:33:41 +01:00
]
);
2011-03-06 18:45:09 -03:00
2016-12-07 23:33:41 +01:00
$cm -> addNamedQuery (
[
2011-03-06 18:45:09 -03:00
'name' => 'userById' ,
'query' => 'SELECT u FROM __CLASS__ u WHERE u.id = ?1'
2016-12-07 23:33:41 +01:00
]
);
2011-03-06 18:45:09 -03:00
}
2011-03-20 12:35:52 +01:00
2012-02-25 23:13:46 -02:00
/**
* @ group DDC - 1663
2012-02-26 00:16:54 -03:00
*
* @ expectedException \Doctrine\ORM\Mapping\MappingException
* @ expectedExceptionMessage Query named " find-all " in " Doctrine \T ests \ Models \ CMS \ CmsUser " was already declared , but it must be declared only once
2012-02-25 23:13:46 -02:00
*/
public function testNamingCollisionNamedNativeQueryShouldThrowException ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2012-02-25 23:13:46 -02:00
2016-12-07 23:33:41 +01:00
$cm -> addNamedNativeQuery (
[
2012-02-25 23:13:46 -02:00
'name' => 'find-all' ,
'query' => 'SELECT * FROM cms_users' ,
2016-12-08 18:01:04 +01:00
'resultClass' => CMS\CmsUser :: class ,
2012-02-25 23:13:46 -02:00
'resultSetMapping' => 'result-mapping-name'
2016-12-07 23:33:41 +01:00
]
);
2012-02-25 23:13:46 -02:00
2016-12-07 23:33:41 +01:00
$cm -> addNamedNativeQuery (
[
2012-02-25 23:13:46 -02:00
'name' => 'find-all' ,
'query' => 'SELECT * FROM cms_users' ,
2016-12-08 18:01:04 +01:00
'resultClass' => CMS\CmsUser :: class ,
2012-02-25 23:13:46 -02:00
'resultSetMapping' => 'result-mapping-name'
2016-12-07 23:33:41 +01:00
]
);
2012-02-25 23:13:46 -02:00
}
2012-02-26 00:16:54 -03:00
/**
* @ group DDC - 1663
*
* @ expectedException \Doctrine\ORM\Mapping\MappingException
* @ expectedExceptionMessage Result set mapping named " find-all " in " Doctrine \T ests \ Models \ CMS \ CmsUser " was already declared , but it must be declared only once
*/
public function testNamingCollisionSqlResultSetMappingShouldThrowException ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2013-05-17 12:08:14 +02:00
2016-12-07 23:33:41 +01:00
$cm -> addSqlResultSetMapping (
[
2012-02-26 00:16:54 -03:00
'name' => 'find-all' ,
2016-12-07 23:33:41 +01:00
'entities' => [
[
2016-12-08 18:01:04 +01:00
'entityClass' => CMS\CmsUser :: class ,
2016-12-07 23:33:41 +01:00
],
],
]
);
2012-02-26 00:16:54 -03:00
2016-12-07 23:33:41 +01:00
$cm -> addSqlResultSetMapping (
[
2012-02-26 00:16:54 -03:00
'name' => 'find-all' ,
2016-12-07 23:33:41 +01:00
'entities' => [
[
2016-12-08 18:01:04 +01:00
'entityClass' => CMS\CmsUser :: class ,
2016-12-07 23:33:41 +01:00
],
],
]
);
2012-02-26 00:16:54 -03:00
}
2011-03-20 12:35:52 +01:00
/**
* @ group DDC - 1068
*/
public function testClassCaseSensitivity ()
{
2016-12-08 18:01:04 +01:00
$user = new CMS\CmsUser ();
$cm = new ClassMetadata ( strtoupper ( CMS\CmsUser :: class ));
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2012-01-02 17:06:22 +01:00
2016-12-08 18:01:04 +01:00
$this -> assertEquals ( CMS\CmsUser :: class , $cm -> name );
2011-03-20 12:35:52 +01:00
}
2011-09-04 14:13:20 +02:00
/**
* @ group DDC - 659
*/
public function testLifecycleCallbackNotFound ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2012-01-02 21:32:18 +01:00
$cm -> addLifecycleCallback ( 'notfound' , 'postLoad' );
2011-09-04 14:13:20 +02:00
2016-06-18 13:01:59 +02:00
$this -> expectException ( MappingException :: class );
2016-12-08 18:01:04 +01:00
$this -> expectExceptionMessage ( " Entity ' " . CMS\CmsUser :: class . " ' has no method 'notfound' to be registered as lifecycle callback. " );
2016-06-18 13:01:59 +02:00
2014-08-14 15:51:17 +02:00
$cm -> validateLifecycleCallbacks ( new RuntimeReflectionService ());
2011-09-04 14:13:20 +02:00
}
2011-10-22 11:28:07 +02:00
/**
* @ group ImproveErrorMessages
*/
public function testTargetEntityNotFound ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2016-12-07 23:33:41 +01:00
$cm -> mapManyToOne ([ 'fieldName' => 'address' , 'targetEntity' => 'UnknownClass' ]);
2011-10-22 11:28:07 +02:00
2016-06-18 13:01:59 +02:00
$this -> expectException ( MappingException :: class );
2016-12-08 18:01:04 +01:00
$this -> expectExceptionMessage ( " The target-entity Doctrine \\ Tests \\ Models \\ CMS \\ UnknownClass cannot be found in ' " . CMS\CmsUser :: class . " #address'. " );
2016-06-18 13:01:59 +02:00
2013-03-11 00:08:58 +00:00
$cm -> validateAssociations ();
2011-10-22 11:28:07 +02:00
}
2012-01-03 16:59:43 -02:00
2012-02-25 23:13:46 -02:00
/**
* @ group DDC - 1663
*
* @ expectedException \Doctrine\ORM\Mapping\MappingException
* @ expectedExceptionMessage Query name on entity class ' Doctrine\Tests\Models\CMS\CmsUser ' is not defined .
*/
public function testNameIsMandatoryForNamedQueryMappingException ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2016-12-07 23:33:41 +01:00
$cm -> addNamedQuery (
[
2012-02-25 23:13:46 -02:00
'query' => 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u' ,
2016-12-07 23:33:41 +01:00
]
);
2012-02-25 23:13:46 -02:00
}
/**
* @ group DDC - 1663
*
* @ expectedException \Doctrine\ORM\Mapping\MappingException
* @ expectedExceptionMessage Query name on entity class ' Doctrine\Tests\Models\CMS\CmsUser ' is not defined .
*/
public function testNameIsMandatoryForNameNativeQueryMappingException ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2016-12-07 23:33:41 +01:00
$cm -> addNamedQuery (
[
2012-02-25 23:13:46 -02:00
'query' => 'SELECT * FROM cms_users' ,
2016-12-08 18:01:04 +01:00
'resultClass' => CMS\CmsUser :: class ,
2012-02-25 23:13:46 -02:00
'resultSetMapping' => 'result-mapping-name'
2016-12-07 23:33:41 +01:00
]
);
2012-02-26 00:16:54 -03:00
}
/**
* @ group DDC - 1663
*
* @ expectedException \Doctrine\ORM\Mapping\MappingException
* @ expectedExceptionMessage Result set mapping named " find-all " in " Doctrine \T ests \ Models \ CMS \ CmsUser requires a entity class name.
*/
public function testNameIsMandatoryForEntityNameSqlResultSetMappingException ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2016-12-07 23:33:41 +01:00
$cm -> addSqlResultSetMapping (
[
2012-02-26 00:16:54 -03:00
'name' => 'find-all' ,
2016-12-07 23:33:41 +01:00
'entities' => [
[
'fields' => []
]
],
]
);
2012-02-25 23:13:46 -02:00
}
2012-02-13 23:38:36 -02:00
/**
* @ expectedException \Doctrine\ORM\Mapping\MappingException
* @ expectedExceptionMessage Discriminator column name on entity class ' Doctrine\Tests\Models\CMS\CmsUser ' is not defined .
*/
public function testNameIsMandatoryForDiscriminatorColumnsMappingException ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2016-12-07 23:33:41 +01:00
$cm -> setDiscriminatorColumn ([]);
2012-02-13 23:38:36 -02:00
}
2012-01-03 16:59:43 -02:00
/**
* @ group DDC - 984
* @ group DDC - 559
* @ group DDC - 1575
*/
public function testFullyQualifiedClassNameShouldBeGivenToNamingStrategy ()
{
$namingStrategy = new MyNamespacedNamingStrategy ();
2016-12-08 18:01:04 +01:00
$addressMetadata = new ClassMetadata ( CMS\CmsAddress :: class , $namingStrategy );
$articleMetadata = new ClassMetadata ( DoctrineGlobal_Article :: class , $namingStrategy );
$routingMetadata = new ClassMetadata ( RoutingLeg :: class , $namingStrategy );
2012-01-03 16:59:43 -02:00
2014-08-14 15:51:17 +02:00
$addressMetadata -> initializeReflection ( new RuntimeReflectionService ());
$articleMetadata -> initializeReflection ( new RuntimeReflectionService ());
$routingMetadata -> initializeReflection ( new RuntimeReflectionService ());
2012-01-03 16:59:43 -02:00
2016-12-07 23:33:41 +01:00
$addressMetadata -> mapManyToMany (
[
2012-01-03 16:59:43 -02:00
'fieldName' => 'user' ,
'targetEntity' => 'CmsUser'
2016-12-07 23:33:41 +01:00
]
);
2012-01-03 16:59:43 -02:00
2016-12-07 23:33:41 +01:00
$articleMetadata -> mapManyToMany (
[
2012-01-03 16:59:43 -02:00
'fieldName' => 'author' ,
2016-12-08 18:01:04 +01:00
'targetEntity' => CMS\CmsUser :: class
2016-12-07 23:33:41 +01:00
]
);
2012-01-03 16:59:43 -02:00
$this -> assertEquals ( 'routing_routingleg' , $routingMetadata -> table [ 'name' ]);
$this -> assertEquals ( 'cms_cmsaddress_cms_cmsuser' , $addressMetadata -> associationMappings [ 'user' ][ 'joinTable' ][ 'name' ]);
$this -> assertEquals ( 'doctrineglobal_article_cms_cmsuser' , $articleMetadata -> associationMappings [ 'author' ][ 'joinTable' ][ 'name' ]);
}
2012-04-01 11:01:41 +02:00
2012-07-05 23:46:08 +02:00
/**
2012-07-05 23:52:36 +02:00
* @ group DDC - 984
* @ group DDC - 559
2012-07-05 23:46:08 +02:00
*/
public function testFullyQualifiedClassNameShouldBeGivenToNamingStrategyPropertyToColumnName ()
{
$namingStrategy = new MyPrefixNamingStrategy ();
2016-12-08 18:01:04 +01:00
$metadata = new ClassMetadata ( CMS\CmsAddress :: class , $namingStrategy );
2012-07-05 23:46:08 +02:00
2014-08-14 15:51:17 +02:00
$metadata -> initializeReflection ( new RuntimeReflectionService ());
2012-07-05 23:46:08 +02:00
2016-12-07 23:33:41 +01:00
$metadata -> mapField ([ 'fieldName' => 'country' ]);
$metadata -> mapField ([ 'fieldName' => 'city' ]);
2012-07-05 23:46:08 +02:00
2016-12-07 23:33:41 +01:00
$this -> assertEquals ( $metadata -> fieldNames , [
2012-07-05 23:46:08 +02:00
'cmsaddress_country' => 'country' ,
'cmsaddress_city' => 'city'
2016-12-07 23:33:41 +01:00
]
);
2012-07-05 23:46:08 +02:00
}
2012-04-01 11:01:41 +02:00
/**
* @ group DDC - 1746
*/
public function testInvalidCascade ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2012-04-01 11:01:41 +02:00
2016-06-18 13:01:59 +02:00
$this -> expectException ( MappingException :: class );
2016-12-08 18:01:04 +01:00
$this -> expectExceptionMessage ( " You have specified invalid cascade options for " . CMS\CmsUser :: class . " :: \$ address: 'invalid'; available options: 'remove', 'persist', 'refresh', 'merge', and 'detach' " );
2012-05-04 18:26:17 +02:00
2016-12-07 23:33:41 +01:00
$cm -> mapManyToOne ([ 'fieldName' => 'address' , 'targetEntity' => 'UnknownClass' , 'cascade' => [ 'invalid' ]]);
2012-02-02 00:57:39 -02:00
}
/**
* @ group DDC - 964
* @ expectedException Doctrine\ORM\Mapping\MappingException
* @ expectedExceptionMessage Invalid field override named 'invalidPropertyName' for class ' Doctrine\Tests\Models\DDC964\DDC964Admin
*/
2012-04-14 02:10:44 -03:00
public function testInvalidPropertyAssociationOverrideNameException ()
2012-02-02 00:57:39 -02:00
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( DDC964Admin :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2016-12-07 23:33:41 +01:00
$cm -> mapManyToOne ([ 'fieldName' => 'address' , 'targetEntity' => 'DDC964Address' ]);
2012-02-02 00:57:39 -02:00
2016-12-07 23:33:41 +01:00
$cm -> setAssociationOverride ( 'invalidPropertyName' , []);
2012-04-01 11:01:41 +02:00
}
2012-04-14 02:10:44 -03:00
/**
* @ group DDC - 964
* @ expectedException Doctrine\ORM\Mapping\MappingException
* @ expectedExceptionMessage Invalid field override named 'invalidPropertyName' for class ' Doctrine\Tests\Models\DDC964\DDC964Guest ' .
*/
public function testInvalidPropertyAttributeOverrideNameException ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( DDC964Guest :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2016-12-07 23:33:41 +01:00
$cm -> mapField ([ 'fieldName' => 'name' ]);
2012-04-14 02:10:44 -03:00
2016-12-07 23:33:41 +01:00
$cm -> setAttributeOverride ( 'invalidPropertyName' , []);
2012-04-14 02:10:44 -03:00
}
/**
* @ group DDC - 964
* @ expectedException Doctrine\ORM\Mapping\MappingException
* @ expectedExceptionMessage The column type of attribute 'name' on class ' Doctrine\Tests\Models\DDC964\DDC964Guest ' could not be changed .
*/
public function testInvalidOverrideAttributeFieldTypeException ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( DDC964Guest :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2016-12-07 23:33:41 +01:00
$cm -> mapField ([ 'fieldName' => 'name' , 'type' => 'string' ]);
2012-04-14 02:10:44 -03:00
2016-12-07 23:33:41 +01:00
$cm -> setAttributeOverride ( 'name' , [ 'type' => 'date' ]);
2012-04-14 02:10:44 -03:00
}
2012-08-04 18:02:32 -03:00
/**
* @ group DDC - 1955
2013-05-17 12:08:14 +02:00
*
2012-08-04 18:02:32 -03:00
* @ expectedException Doctrine\ORM\Mapping\MappingException
* @ expectedExceptionMessage Entity Listener " \ InvalidClassName " declared on " Doctrine \T ests \ Models \ CMS \ CmsUser " not found .
*/
public function testInvalidEntityListenerClassException ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2012-08-04 18:02:32 -03:00
$cm -> addEntityListener ( Events :: postLoad , '\InvalidClassName' , 'postLoadHandler' );
}
/**
* @ group DDC - 1955
*
* @ expectedException Doctrine\ORM\Mapping\MappingException
2012-08-11 23:48:09 -03:00
* @ expectedExceptionMessage Entity Listener " \ Doctrine \T ests \ Models \ Company \ CompanyContractListener " declared on " Doctrine \T ests \ Models \ CMS \ CmsUser " has no method " invalidMethod " .
2012-08-04 18:02:32 -03:00
*/
public function testInvalidEntityListenerMethodException ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2012-08-04 18:02:32 -03:00
2012-08-11 23:48:09 -03:00
$cm -> addEntityListener ( Events :: postLoad , '\Doctrine\Tests\Models\Company\CompanyContractListener' , 'invalidMethod' );
2012-08-04 18:02:32 -03:00
}
2013-05-17 12:08:14 +02:00
public function testManyToManySelfReferencingNamingStrategyDefaults ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CustomTypeParent :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2013-05-17 12:08:14 +02:00
$cm -> mapManyToMany (
2016-12-07 23:33:41 +01:00
[
2013-05-17 12:08:14 +02:00
'fieldName' => 'friendsWithMe' ,
'targetEntity' => 'CustomTypeParent'
2016-12-07 23:33:41 +01:00
]
2013-05-17 12:08:14 +02:00
);
$this -> assertEquals (
2016-12-07 23:33:41 +01:00
[
2013-05-17 12:08:14 +02:00
'name' => 'customtypeparent_customtypeparent' ,
2016-12-07 23:33:41 +01:00
'joinColumns' => [[ 'name' => 'customtypeparent_source' , 'referencedColumnName' => 'id' , 'onDelete' => 'CASCADE' ]],
'inverseJoinColumns' => [[ 'name' => 'customtypeparent_target' , 'referencedColumnName' => 'id' , 'onDelete' => 'CASCADE' ]],
],
2013-05-17 12:08:14 +02:00
$cm -> associationMappings [ 'friendsWithMe' ][ 'joinTable' ]
);
2016-12-07 23:33:41 +01:00
$this -> assertEquals ([ 'customtypeparent_source' , 'customtypeparent_target' ], $cm -> associationMappings [ 'friendsWithMe' ][ 'joinTableColumns' ]);
$this -> assertEquals ([ 'customtypeparent_source' => 'id' ], $cm -> associationMappings [ 'friendsWithMe' ][ 'relationToSourceKeyColumns' ]);
$this -> assertEquals ([ 'customtypeparent_target' => 'id' ], $cm -> associationMappings [ 'friendsWithMe' ][ 'relationToTargetKeyColumns' ]);
2013-05-17 12:08:14 +02:00
}
2013-09-08 15:59:39 +02:00
/**
* @ group DDC - 2608
*/
public function testSetSequenceGeneratorThrowsExceptionWhenSequenceNameIsMissing ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2013-09-08 15:59:39 +02:00
2016-06-18 13:01:59 +02:00
$this -> expectException ( \Doctrine\ORM\Mapping\MappingException :: class );
2016-12-07 23:33:41 +01:00
$cm -> setSequenceGeneratorDefinition ([]);
2013-09-08 15:59:39 +02:00
}
/**
* @ group DDC - 2662
*/
public function testQuotedSequenceName ()
{
2016-12-08 18:01:04 +01:00
$cm = new ClassMetadata ( CMS\CmsUser :: class );
2014-08-14 15:51:17 +02:00
$cm -> initializeReflection ( new RuntimeReflectionService ());
2013-09-08 15:59:39 +02:00
2016-12-07 23:33:41 +01:00
$cm -> setSequenceGeneratorDefinition ([ 'sequenceName' => '`foo`' ]);
2013-09-08 15:59:39 +02:00
2016-12-07 23:33:41 +01:00
$this -> assertEquals ([ 'sequenceName' => 'foo' , 'quoted' => true ], $cm -> sequenceGeneratorDefinition );
2013-09-08 15:59:39 +02:00
}
2014-01-02 23:50:15 +01:00
/**
* @ group DDC - 2700
*/
public function testIsIdentifierMappedSuperClass ()
{
2016-12-08 18:01:04 +01:00
$class = new ClassMetadata ( DDC2700MappedSuperClass :: class );
2014-01-02 23:50:15 +01:00
$this -> assertFalse ( $class -> isIdentifier ( 'foo' ));
}
2014-08-14 15:38:55 +02:00
/**
* @ group DDC - 3120
*/
public function testCanInstantiateInternalPhpClassSubclass ()
{
2016-12-08 18:01:04 +01:00
$classMetadata = new ClassMetadata ( MyArrayObjectEntity :: class );
2014-08-14 15:38:55 +02:00
2016-12-08 18:01:04 +01:00
$this -> assertInstanceOf ( MyArrayObjectEntity :: class , $classMetadata -> newInstance ());
2014-08-14 15:38:55 +02:00
}
2014-08-14 15:39:58 +02:00
/**
* @ group DDC - 3120
*/
public function testCanInstantiateInternalPhpClassSubclassFromUnserializedMetadata ()
{
/* @var $classMetadata ClassMetadata */
2016-12-08 18:01:04 +01:00
$classMetadata = unserialize ( serialize ( new ClassMetadata ( MyArrayObjectEntity :: class )));
2014-08-14 15:39:58 +02:00
2014-08-14 15:51:17 +02:00
$classMetadata -> wakeupReflection ( new RuntimeReflectionService ());
2016-12-08 18:01:04 +01:00
$this -> assertInstanceOf ( MyArrayObjectEntity :: class , $classMetadata -> newInstance ());
2014-08-14 15:39:58 +02:00
}
2015-04-11 19:43:34 +02:00
public function testWakeupReflectionWithEmbeddableAndStaticReflectionService ()
{
2016-12-08 18:01:04 +01:00
$classMetadata = new ClassMetadata ( TestEntity1 :: class );
2015-04-11 19:43:34 +02:00
2016-12-07 23:33:41 +01:00
$classMetadata -> mapEmbedded (
[
2015-04-11 19:43:34 +02:00
'fieldName' => 'test' ,
2016-12-08 18:01:04 +01:00
'class' => TestEntity1 :: class ,
2015-04-11 19:43:34 +02:00
'columnPrefix' => false ,
2016-12-07 23:33:41 +01:00
]
);
2015-04-11 19:43:34 +02:00
2016-12-07 23:33:41 +01:00
$field = [
2015-04-11 19:43:34 +02:00
'fieldName' => 'test.embeddedProperty' ,
'type' => 'string' ,
2016-12-08 18:01:04 +01:00
'originalClass' => TestEntity1 :: class ,
2015-04-11 19:43:34 +02:00
'declaredField' => 'test' ,
'originalField' => 'embeddedProperty'
2016-12-07 23:33:41 +01:00
];
2015-04-11 19:43:34 +02:00
$classMetadata -> mapField ( $field );
$classMetadata -> wakeupReflection ( new StaticReflectionService ());
2016-12-07 23:33:41 +01:00
$this -> assertEquals ([ 'test' => null , 'test.embeddedProperty' => null ], $classMetadata -> getReflectionProperties ());
2015-04-11 19:43:34 +02:00
}
2015-12-11 20:48:59 +01:00
public function testGetColumnNamesWithGivenFieldNames ()
{
2016-12-08 18:01:04 +01:00
$metadata = new ClassMetadata ( CMS\CmsUser :: class );
2015-12-11 20:48:59 +01:00
$metadata -> initializeReflection ( new RuntimeReflectionService ());
2016-12-07 23:33:41 +01:00
$metadata -> mapField ([ 'fieldName' => 'status' , 'type' => 'string' , 'columnName' => 'foo' ]);
$metadata -> mapField ([ 'fieldName' => 'username' , 'type' => 'string' , 'columnName' => 'bar' ]);
$metadata -> mapField ([ 'fieldName' => 'name' , 'type' => 'string' , 'columnName' => 'baz' ]);
2015-12-11 20:48:59 +01:00
self :: assertSame ([ 'foo' , 'baz' ], $metadata -> getColumnNames ([ 'status' , 'name' ]));
}
2014-01-02 23:50:15 +01:00
}
/**
* @ MappedSuperclass
*/
class DDC2700MappedSuperClass
{
/** @Column */
private $foo ;
2012-01-03 16:59:43 -02:00
}
2014-08-14 15:51:17 +02:00
class MyNamespacedNamingStrategy extends DefaultNamingStrategy
2012-01-03 16:59:43 -02:00
{
/**
* { @ inheritdoc }
*/
public function classToTableName ( $className )
{
if ( strpos ( $className , '\\' ) !== false ) {
$className = str_replace ( '\\' , '_' , str_replace ( 'Doctrine\Tests\Models\\' , '' , $className ));
}
return strtolower ( $className );
}
2011-01-02 12:01:05 +01:00
}
2012-07-05 23:46:08 +02:00
2014-08-14 15:51:17 +02:00
class MyPrefixNamingStrategy extends DefaultNamingStrategy
2012-07-05 23:46:08 +02:00
{
/**
* { @ inheritdoc }
*/
public function propertyToColumnName ( $propertyName , $className = null )
{
return strtolower ( $this -> classToTableName ( $className )) . '_' . $propertyName ;
}
2013-09-08 15:59:39 +02:00
}
2014-08-14 15:38:55 +02:00
class MyArrayObjectEntity extends \ArrayObject
{
}