1
0
mirror of synced 2025-01-18 06:21:40 +03:00

mapping driver tests

This commit is contained in:
Fabio B. Silva 2012-02-26 21:10:19 -03:00
parent 015ea809b0
commit 3b79951824
3 changed files with 104 additions and 1 deletions

View File

@ -244,7 +244,7 @@ class AnnotationDriver implements Driver
$columns = array();
foreach ($resultSetMapping->columns as $columnResultAnnot) {
$columns[] = array(
'name' => $resultSetMapping->name,
'name' => $columnResultAnnot->name,
);
}

View File

@ -14,6 +14,16 @@ namespace Doctrine\Tests\Models\CMS;
* name = "find-all",
* resultSetMapping = "mapping-find-all",
* query = "SELECT id, country, city FROM cms_addresses"
* ),
* @NamedNativeQuery(
* name = "find-by-id",
* resultClass = "CmsAddress",
* query = "SELECT * FROM cms_addresses WHERE id = ?"
* ),
* @NamedNativeQuery(
* name = "count",
* resultSetMapping= "mapping-count",
* query = "SELECT COUNT(*) AS count FROM cms_addresses"
* )
* })
*
@ -30,6 +40,22 @@ namespace Doctrine\Tests\Models\CMS;
* }
* )
* }
* ),
* @SqlResultSetMapping(
* name = "mapping-without-fields",
* entities= {
* @EntityResult(
* entityClass = "__CLASS__"
* )
* }
* ),
* @SqlResultSetMapping(
* name = "mapping-count",
* columns = {
* @ColumnResult(
* name = "count"
* )
* }
* )
* })
*

View File

@ -467,6 +467,7 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
}
/**
<<<<<<< HEAD
* @group DDC-889
* @expectedException Doctrine\ORM\Mapping\MappingException
* @expectedExceptionMessage Class "Doctrine\Tests\Models\DDC889\DDC889Class" sub class of "Doctrine\Tests\Models\DDC889\DDC889SuperClass" is not a valid entity or mapped super class.
@ -488,6 +489,82 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase
$factory->getMetadataFor('Doctrine\Tests\Models\DDC889\DDC889Entity');
}
/**
* @group DDC-1663
*/
public function testNamedNativeQuery()
{
if (!$this instanceof AnnotationDriverTest) {
$this->markTestIncomplete();
}
$class = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress');
$this->assertCount(3, $class->namedNativeQueries);
$this->assertArrayHasKey('find-all', $class->namedNativeQueries);
$this->assertArrayHasKey('find-by-id', $class->namedNativeQueries);
$findAllQuery = $class->namedNativeQueries['find-all'];
$this->assertEquals('find-all', $findAllQuery['name']);
$this->assertEquals('mapping-find-all', $findAllQuery['resultSetMapping']);
$this->assertEquals('SELECT id, country, city FROM cms_addresses', $findAllQuery['query']);
$findByIdQuery = $class->namedNativeQueries['find-by-id'];
$this->assertEquals('find-by-id', $findByIdQuery['name']);
$this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddress',$findByIdQuery['resultClass']);
$this->assertEquals('SELECT * FROM cms_addresses WHERE id = ?', $findByIdQuery['query']);
$countQuery = $class->namedNativeQueries['count'];
$this->assertEquals('count', $countQuery['name']);
$this->assertEquals('mapping-count', $countQuery['resultSetMapping']);
$this->assertEquals('SELECT COUNT(*) AS count FROM cms_addresses', $countQuery['query']);
}
/**
* @group DDC-1663
*/
public function testSqlResultSetMapping()
{
if (!$this instanceof AnnotationDriverTest) {
$this->markTestIncomplete();
}
$class = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress');
$this->assertCount(3, $class->sqlResultSetMappings);
$this->assertArrayHasKey('mapping-find-all', $class->sqlResultSetMappings);
$this->assertArrayHasKey('mapping-without-fields', $class->sqlResultSetMappings);
// empty fields select all fields
$withoutFieldsMapping = $class->sqlResultSetMappings['mapping-without-fields'];
$this->assertEquals('mapping-without-fields', $withoutFieldsMapping['name']);
$this->assertCount(1, $withoutFieldsMapping['entities']);
$this->assertCount(0, $withoutFieldsMapping['columns']);
$this->assertEquals(array(), $withoutFieldsMapping['entities'][0]['fields']);
$this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddress', $withoutFieldsMapping['entities'][0]['entityClass']);
$findAllMapping = $class->sqlResultSetMappings['mapping-find-all'];
$this->assertEquals('mapping-find-all', $findAllMapping['name']);
$this->assertCount(1, $findAllMapping['entities']);
$this->assertCount(0, $findAllMapping['columns']);
$this->assertEquals(array(
array('name'=>'id','column'=>'id'),
array('name'=>'city','column'=>'city'),
array('name'=>'country','column' => 'country')
), $findAllMapping['entities'][0]['fields']);
$this->assertEquals('Doctrine\Tests\Models\CMS\CmsAddress', $findAllMapping['entities'][0]['entityClass']);
$countMapping = $class->sqlResultSetMappings['mapping-count'];
$this->assertEquals('mapping-count', $countMapping['name']);
$this->assertCount(0, $countMapping['entities']);
$this->assertCount(1, $countMapping['columns']);
$this->assertEquals(array(array('name'=>'count')),$countMapping['columns']);
}
}
/**