123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
-
- namespace Doctrine\Tests\ORM\Mapping;
-
- use Doctrine\ORM\Mapping\ClassMetadata;
- use Doctrine\ORM\Events;
-
- require_once __DIR__ . '/../../TestInit.php';
-
- class ClassMetadataLoadEventTest extends \Doctrine\Tests\OrmTestCase
- {
- public function testEvent()
- {
- $em = $this->_getTestEntityManager();
- $metadataFactory = $em->getMetadataFactory();
- $evm = $em->getEventManager();
- $evm->addEventListener(Events::loadClassMetadata, $this);
- $classMetadata = $metadataFactory->getMetadataFor('Doctrine\Tests\ORM\Mapping\LoadEventTestEntity');
- $this->assertTrue($classMetadata->hasField('about'));
- }
-
- public function loadClassMetadata(\Doctrine\ORM\Event\LoadClassMetadataEventArgs $eventArgs)
- {
- $classMetadata = $eventArgs->getClassMetadata();
- $field = array(
- 'fieldName' => 'about',
- 'type' => 'string',
- 'length' => 255
- );
- $classMetadata->mapField($field);
- }
- }
-
- /**
- * @Entity
- * @Table(name="load_event_test_entity")
- */
- class LoadEventTestEntity
- {
- /**
- * @Id @Column(type="integer")
- * @GeneratedValue(strategy="AUTO")
- */
- private $id;
- /**
- * @Column(type="string", length=255)
- */
- private $name;
-
- private $about;
- }
|