ClassMetadataLoadEventTest.php 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace Doctrine\Tests\ORM\Mapping;
  3. use Doctrine\ORM\Mapping\ClassMetadata;
  4. use Doctrine\ORM\Events;
  5. require_once __DIR__ . '/../../TestInit.php';
  6. class ClassMetadataLoadEventTest extends \Doctrine\Tests\OrmTestCase
  7. {
  8. public function testEvent()
  9. {
  10. $em = $this->_getTestEntityManager();
  11. $metadataFactory = $em->getMetadataFactory();
  12. $evm = $em->getEventManager();
  13. $evm->addEventListener(Events::loadClassMetadata, $this);
  14. $classMetadata = $metadataFactory->getMetadataFor('Doctrine\Tests\ORM\Mapping\LoadEventTestEntity');
  15. $this->assertTrue($classMetadata->hasField('about'));
  16. }
  17. public function loadClassMetadata(\Doctrine\ORM\Event\LoadClassMetadataEventArgs $eventArgs)
  18. {
  19. $classMetadata = $eventArgs->getClassMetadata();
  20. $field = array(
  21. 'fieldName' => 'about',
  22. 'type' => 'string',
  23. 'length' => 255
  24. );
  25. $classMetadata->mapField($field);
  26. }
  27. }
  28. /**
  29. * @Entity
  30. * @Table(name="load_event_test_entity")
  31. */
  32. class LoadEventTestEntity
  33. {
  34. /**
  35. * @Id @Column(type="integer")
  36. * @GeneratedValue(strategy="AUTO")
  37. */
  38. private $id;
  39. /**
  40. * @Column(type="string", length=255)
  41. */
  42. private $name;
  43. private $about;
  44. }