Location: PHPKode > projects > MongoDB Object Document Mapper > tests/Doctrine/ODM/MongoDB/Tests/Mapping/ClassMetadataLoadEventTest.php
<?php

namespace Doctrine\ODM\MongoDB\Tests\Mapping;

use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
use Doctrine\ODM\MongoDB\ODMEvents;

require_once __DIR__ . '/../../../../../TestInit.php';

class ClassMetadataLoadEventTest extends \Doctrine\ODM\MongoDB\Tests\BaseTest
{
    public function testEvent()
    {
        $metadataFactory = $this->dm->getMetadataFactory();
        $evm = $this->dm->getEventManager();
        $evm->addEventListener(ODMEvents::loadClassMetadata, $this);
        $classMetadata = $metadataFactory->getMetadataFor('Doctrine\ODM\MongoDB\Tests\Mapping\LoadEventTestDocument');
        $this->assertTrue($classMetadata->hasField('about'));
    }

    public function loadClassMetadata(\Doctrine\ODM\MongoDB\Event\LoadClassMetadataEventArgs $eventArgs)
    {
        $classMetadata = $eventArgs->getClassMetadata();
        $field = array(
            'fieldName' => 'about',
            'type' => 'string'
        );
        $classMetadata->mapField($field);
    }
}

/**
 * @Document
 */
class LoadEventTestDocument
{
    /** @Id */
    private $id;

    /** @String */
    private $name;

    private $about;
}
Return current item: MongoDB Object Document Mapper