2010-02-02 21:17:00 +00:00
< ? php
namespace Doctrine\Tests\ORM\Mapping ;
use Doctrine\ORM\Mapping\ClassMetadata ;
use Doctrine\ORM\Events ;
require_once __DIR__ . '/../../TestInit.php' ;
2010-02-14 19:38:22 +00:00
class AnnotationDriverTest extends AbstractMappingDriverTest
2010-02-02 21:17:00 +00:00
{
/**
* @ group DDC - 268
*/
public function testLoadMetadataForNonEntityThrowsException ()
{
$cm = new ClassMetadata ( 'stdClass' );
$reader = new \Doctrine\Common\Annotations\AnnotationReader ( new \Doctrine\Common\Cache\ArrayCache ());
$annotationDriver = new \Doctrine\ORM\Mapping\Driver\AnnotationDriver ( $reader );
$this -> setExpectedException ( 'Doctrine\ORM\Mapping\MappingException' );
$annotationDriver -> loadMetadataForClass ( 'stdClass' , $cm );
}
/**
* @ group DDC - 268
*/
2010-02-09 17:13:49 +00:00
public function testColumnWithMissingTypeDefaultsToString ()
2010-02-02 21:17:00 +00:00
{
2010-02-14 19:38:22 +00:00
$cm = new ClassMetadata ( 'Doctrine\Tests\ORM\Mapping\ColumnWithoutType' );
2010-08-08 12:29:14 +02:00
$annotationDriver = $this -> _loadDriver ();
2010-02-02 21:17:00 +00:00
$annotationDriver -> loadMetadataForClass ( 'Doctrine\Tests\ORM\Mapping\InvalidColumn' , $cm );
2010-02-09 17:13:49 +00:00
$this -> assertEquals ( 'string' , $cm -> fieldMappings [ 'id' ][ 'type' ]);
2010-02-02 21:17:00 +00:00
}
2010-02-14 19:38:22 +00:00
2010-03-18 23:04:21 +00:00
/**
* @ group DDC - 318
*/
public function testGetAllClassNamesIsIdempotent ()
{
$annotationDriver = $this -> _loadDriverForCMSModels ();
$original = $annotationDriver -> getAllClassNames ();
$annotationDriver = $this -> _loadDriverForCMSModels ();
$afterTestReset = $annotationDriver -> getAllClassNames ();
$this -> assertEquals ( $original , $afterTestReset );
}
/**
* @ group DDC - 318
*/
public function testGetAllClassNamesIsIdempotentEvenWithDifferentDriverInstances ()
{
$annotationDriver = $this -> _loadDriverForCMSModels ();
$original = $annotationDriver -> getAllClassNames ();
$annotationDriver = $this -> _loadDriverForCMSModels ();
$afterTestReset = $annotationDriver -> getAllClassNames ();
$this -> assertEquals ( $original , $afterTestReset );
}
/**
* @ group DDC - 318
*/
public function testGetAllClassNamesReturnsAlreadyLoadedClassesIfAppropriate ()
{
$rightClassName = 'Doctrine\Tests\Models\CMS\CmsUser' ;
$this -> _ensureIsLoaded ( $rightClassName );
$annotationDriver = $this -> _loadDriverForCMSModels ();
$classes = $annotationDriver -> getAllClassNames ();
$this -> assertContains ( $rightClassName , $classes );
}
/**
* @ group DDC - 318
*/
public function testGetClassNamesReturnsOnlyTheAppropriateClasses ()
{
$extraneousClassName = 'Doctrine\Tests\Models\ECommerce\ECommerceCart' ;
$this -> _ensureIsLoaded ( $extraneousClassName );
$annotationDriver = $this -> _loadDriverForCMSModels ();
$classes = $annotationDriver -> getAllClassNames ();
$this -> assertNotContains ( $extraneousClassName , $classes );
}
protected function _loadDriverForCMSModels ()
{
$annotationDriver = $this -> _loadDriver ();
$annotationDriver -> addPaths ( array ( __DIR__ . '/../../Models/CMS/' ));
return $annotationDriver ;
}
2010-02-14 19:38:22 +00:00
protected function _loadDriver ()
{
$cache = new \Doctrine\Common\Cache\ArrayCache ();
$reader = new \Doctrine\Common\Annotations\AnnotationReader ( $cache );
$reader -> setDefaultAnnotationNamespace ( 'Doctrine\ORM\Mapping\\' );
return new \Doctrine\ORM\Mapping\Driver\AnnotationDriver ( $reader );
}
2010-03-18 23:04:21 +00:00
protected function _ensureIsLoaded ( $entityClassName )
{
new $entityClassName ;
}
2010-09-21 23:14:45 +02:00
/**
* @ group DDC - 671
*
* Entities for this test are in AbstractMappingDriverTest
*/
public function testJoinTablesWithMappedSuperclassForAnnotationDriver ()
{
$em = $this -> _getTestEntityManager ();
$em -> getConfiguration () -> setMetadataDriverImpl ( $this -> _loadDriver ());
$classPage = $em -> getClassMetadata ( 'Doctrine\Tests\ORM\Mapping\Page' );
$this -> assertEquals ( 'Doctrine\Tests\ORM\Mapping\Page' , $classPage -> associationMappings [ 'parentDirectory' ][ 'sourceEntity' ]);
$classDirectory = $em -> getClassMetadata ( 'Doctrine\Tests\ORM\Mapping\Directory' );
$this -> assertEquals ( 'Doctrine\Tests\ORM\Mapping\Directory' , $classDirectory -> associationMappings [ 'parentDirectory' ][ 'sourceEntity' ]);
$dql = " SELECT f FROM Doctrine \T ests \ ORM \ Mapping \ Page f JOIN f.parentDirectory d " .
" WHERE (d.url = :url) AND (f.extension = :extension) " ;
$query = $em -> createQuery ( $dql )
-> setParameter ( 'url' , " test " )
-> setParameter ( 'extension' , " extension " );
$this -> assertEquals (
'SELECT c0_.id AS id0, c0_.extension AS extension1, c0_.parent_directory_id AS parent_directory_id2 FROM core_content_pages c0_ INNER JOIN core_content_directories c1_ ON c0_.parent_directory_id = c1_.id WHERE (c1_.url = ?) AND (c0_.extension = ?)' ,
$query -> getSql ()
);
}
2010-02-02 21:17:00 +00:00
}
/**
* @ Entity
*/
2010-02-14 19:38:22 +00:00
class ColumnWithoutType
2010-02-02 21:17:00 +00:00
{
/** @Id @Column */
public $id ;
}