setExpectedException('Doctrine\ORM\Mapping\MappingException'); $annotationDriver->loadMetadataForClass('stdClass', $cm); } /** * @group DDC-268 */ public function testColumnWithMissingTypeDefaultsToString() { $cm = new ClassMetadata('Doctrine\Tests\ORM\Mapping\ColumnWithoutType'); $annotationDriver = $this->_loadDriver(); $annotationDriver->loadMetadataForClass('Doctrine\Tests\ORM\Mapping\InvalidColumn', $cm); $this->assertEquals('string', $cm->fieldMappings['id']['type']); } /** * @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); } public function testInheritenceWithoutDiscriminatorMap() { $cm = new ClassMetadata('Doctrine\Tests\ORM\Mapping\ClassWithoutDiscriminatorMap'); $annotationDriver = $this->_loadDriver(); $this->setExpectedException("Doctrine\ORM\Mapping\MappingException"); $annotationDriver->loadMetadataForClass($cm->name, $cm); } public function testInheritenceWithoutDiscriminatorColumn() { $cm = new ClassMetadata('Doctrine\Tests\ORM\Mapping\ClassWithoutDiscriminatorColumn'); $annotationDriver = $this->_loadDriver(); $this->setExpectedException("Doctrine\ORM\Mapping\MappingException"); $annotationDriver->loadMetadataForClass($cm->name, $cm); } protected function _loadDriverForCMSModels() { $annotationDriver = $this->_loadDriver(); $annotationDriver->addPaths(array(__DIR__ . '/../../Models/CMS/')); return $annotationDriver; } 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); } protected function _ensureIsLoaded($entityClassName) { new $entityClassName; } } /** * @Entity */ class ColumnWithoutType { /** @Id @Column */ public $id; } /** * @Entity * @InheritanceType("SINGLE_TABLE") * @DiscriminatorMap({"a" = "ClassWithoutDiscriminatorColumn"}) */ class ClassWithoutDiscriminatorColumn { /** @Id @Column */ public $id; } /** * @Entity * @InheritanceType("SINGLE_TABLE") * @DiscriminatorColumn(name="discr", type="string") */ class ClassWithoutDiscriminatorMap { /** @Id @Column */ public $id; }