From 917aa70c9745a0f946ae34ebd870108fe3f0ffa4 Mon Sep 17 00:00:00 2001 From: "Fabio B. Silva" Date: Sat, 4 Aug 2012 18:02:32 -0300 Subject: [PATCH] test invalid class/method --- .../ORM/Mapping/ClassMetadataInfo.php | 2 +- .../Tests/ORM/Mapping/ClassMetadataTest.php | 28 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php index 51a04aa3f..597256ed7 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php @@ -2505,7 +2505,7 @@ class ClassMetadataInfo implements ClassMetadata throw MappingException::entityListenerClassNotFound($class, $this->name); } - if ( !method_exists($class, $method)) { + if ( ! method_exists($class, $method)) { throw MappingException::entityListenerMethodNotFound($class, $method, $this->name); } diff --git a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php index fee6d822c..2f79b967c 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php @@ -997,6 +997,34 @@ class ClassMetadataTest extends \Doctrine\Tests\OrmTestCase $cm->setAttributeOverride('name', array('type'=>'date')); } + + /** + * @group DDC-1955 + * + * @expectedException Doctrine\ORM\Mapping\MappingException + * @expectedExceptionMessage Entity Listener "\InvalidClassName" declared on "Doctrine\Tests\Models\CMS\CmsUser" not found. + */ + public function testInvalidEntityListenerClassException() + { + $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); + + $cm->addEntityListener(Events::postLoad, '\InvalidClassName', 'postLoadHandler'); + } + + /** + * @group DDC-1955 + * + * @expectedException Doctrine\ORM\Mapping\MappingException + * @expectedExceptionMessage Entity Listener "\Doctrine\Tests\Models\Company\ContractSubscriber" declared on "Doctrine\Tests\Models\CMS\CmsUser" has no method "invalidMethod". + */ + public function testInvalidEntityListenerMethodException() + { + $cm = new ClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); + $cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService); + + $cm->addEntityListener(Events::postLoad, '\Doctrine\Tests\Models\Company\ContractSubscriber', 'invalidMethod'); + } } class MyNamespacedNamingStrategy extends \Doctrine\ORM\Mapping\DefaultNamingStrategy