Skip to content

Commit

Permalink
Merge branch 'DDC-1034' into 2.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Mar 4, 2011
2 parents af4e836 + ceb6924 commit 8eef747
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/Doctrine/ORM/Mapping/Driver/AnnotationDriver.php
Expand Up @@ -367,7 +367,8 @@ public function loadMetadataForClass($className, ClassMetadataInfo $metadata)
// Evaluate @HasLifecycleCallbacks annotation
if (isset($classAnnotations['Doctrine\ORM\Mapping\HasLifecycleCallbacks'])) {
foreach ($class->getMethods() as $method) {
if ($method->isPublic()) {
// filter for the declaring class only, callbacks from parents will already be registered.
if ($method->isPublic() && $method->getDeclaringClass()->getName() == $class->name) {
$annotations = $this->_reader->getMethodAnnotations($method);

if (isset($annotations['Doctrine\ORM\Mapping\PrePersist'])) {
Expand Down
89 changes: 88 additions & 1 deletion tests/Doctrine/Tests/ORM/Mapping/AnnotationDriverTest.php
Expand Up @@ -149,6 +149,44 @@ public function testInvalidMappedSuperClassWithManyToManyAssociation()
"mapped superclass 'Doctrine\Tests\ORM\Mapping\InvalidMappedSuperClass#users'");
$usingInvalidMsc = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\UsingInvalidMappedSuperClass');
}

/**
* @group DDC-1050
*/
public function testInvalidMappedSuperClassWithInheritanceInformation()
{
$annotationDriver = $this->_loadDriver();

$em = $this->_getTestEntityManager();
$em->getConfiguration()->setMetadataDriverImpl($annotationDriver);
$factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
$factory->setEntityManager($em);

$this->setExpectedException('Doctrine\ORM\Mapping\MappingException',
"Its not supported to define inheritance information on a mapped ".
"superclass 'Doctrine\Tests\ORM\Mapping\MappedSuperClassInheritence'.");
$usingInvalidMsc = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\MappedSuperClassInheritence');
}

/**
* @group DDC-1034
*/
public function testInheritanceSkipsParentLifecycleCallbacks()
{
$annotationDriver = $this->_loadDriver();

$cm = new ClassMetadata('Doctrine\Tests\ORM\Mapping\AnnotationChild');
$em = $this->_getTestEntityManager();
$em->getConfiguration()->setMetadataDriverImpl($annotationDriver);
$factory = new \Doctrine\ORM\Mapping\ClassMetadataFactory();
$factory->setEntityManager($em);

$cm = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\AnnotationChild');
$this->assertEquals(array("postLoad" => array("postLoad"), "preUpdate" => array("preUpdate")), $cm->lifecycleCallbacks);

$cm = $factory->getMetadataFor('Doctrine\Tests\ORM\Mapping\AnnotationParent');
$this->assertEquals(array("postLoad" => array("postLoad"), "preUpdate" => array("preUpdate")), $cm->lifecycleCallbacks);
}
}

/**
Expand Down Expand Up @@ -180,4 +218,53 @@ class UsingInvalidMappedSuperClass extends InvalidMappedSuperClass
* @Id @Column(type="integer") @GeneratedValue
*/
private $id;
}
}

/**
* @MappedSuperclass
* @InheritanceType("JOINED")
* @DiscriminatorMap({"test" = "ColumnWithoutType"})
*/
class MappedSuperClassInheritence
{

}

/**
* @Entity
* @InheritanceType("JOINED")
* @DiscriminatorMap({"parent" = "AnnotationParent", "child" = "AnnotationChild"})
* @HasLifecycleCallbacks
*/
class AnnotationParent
{
/**
* @Id @Column(type="integer") @GeneratedValue
*/
private $id;

/**
* @PostLoad
*/
public function postLoad()
{

}

/**
* @PreUpdate
*/
public function preUpdate()
{

}
}

/**
* @Entity
* @HasLifecycleCallbacks
*/
class AnnotationChild extends AnnotationParent
{

}

0 comments on commit 8eef747

Please sign in to comment.