diff --git a/tests/Doctrine/Tests/Models/CMS/CmsAddress.php b/tests/Doctrine/Tests/Models/CMS/CmsAddress.php index 0b4f1ad9a..9833f3dfb 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsAddress.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsAddress.php @@ -120,4 +120,72 @@ class CmsAddress $user->setAddress($this); } } + + public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) + { + $metadata->setPrimaryTable(array( + 'name' => 'company_person', + )); + + $metadata->addNamedNativeQuery(array ( + 'name' => 'find-all', + 'query' => 'SELECT id, country, city FROM cms_addresses', + 'resultSetMapping' => 'mapping-find-all', + )); + + $metadata->addNamedNativeQuery(array ( + 'name' => 'find-by-id', + 'query' => 'SELECT * FROM cms_addresses WHERE id = ?', + 'resultClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsAddress', + )); + + $metadata->addNamedNativeQuery(array ( + 'name' => 'count', + 'query' => 'SELECT COUNT(*) AS count FROM cms_addresses', + 'resultSetMapping' => 'mapping-count', + )); + + + $metadata->addSqlResultSetMapping(array ( + 'name' => 'mapping-find-all', + 'columns' => array(), + 'entities' => array ( array ( + 'fields' => array ( + array ( + 'name' => 'id', + 'column' => 'id', + ), + array ( + 'name' => 'city', + 'column' => 'city', + ), + array ( + 'name' => 'country', + 'column' => 'country', + ), + ), + 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsAddress', + ), + ), + )); + + $metadata->addSqlResultSetMapping(array ( + 'name' => 'mapping-without-fields', + 'columns' => array(), + 'entities' => array(array ( + 'entityClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsAddress', + 'fields' => array() + ) + ) + )); + + $metadata->addSqlResultSetMapping(array ( + 'name' => 'mapping-count', + 'columns' =>array ( + array ( + 'name' => 'count', + ), + ) + )); + } } \ No newline at end of file diff --git a/tests/Doctrine/Tests/Models/CMS/CmsUser.php b/tests/Doctrine/Tests/Models/CMS/CmsUser.php index e414ee95e..d3a8b46c0 100644 --- a/tests/Doctrine/Tests/Models/CMS/CmsUser.php +++ b/tests/Doctrine/Tests/Models/CMS/CmsUser.php @@ -218,4 +218,139 @@ class CmsUser } } } + + public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) + { + $metadata->setPrimaryTable(array( + 'name' => 'cms_users', + )); + + $metadata->addNamedNativeQuery(array ( + 'name' => 'fetchIdAndUsernameWithResultClass', + 'query' => 'SELECT id, username FROM cms_users WHERE username = ?', + 'resultClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser', + )); + + $metadata->addNamedNativeQuery(array ( + 'name' => 'fetchAllColumns', + 'query' => 'SELECT * FROM cms_users WHERE username = ?', + 'resultClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser', + )); + + $metadata->addNamedNativeQuery(array ( + 'name' => 'fetchJoinedAddress', + 'query' => 'SELECT u.id, u.name, u.status, a.id AS a_id, a.country, a.zip, a.city FROM cms_users u INNER JOIN cms_addresses a ON u.id = a.user_id WHERE u.username = ?', + 'resultSetMapping' => 'mappingJoinedAddress', + )); + + $metadata->addNamedNativeQuery(array ( + 'name' => 'fetchJoinedPhonenumber', + 'query' => 'SELECT id, name, status, phonenumber AS number FROM cms_users INNER JOIN cms_phonenumbers ON id = user_id WHERE username = ?', + 'resultSetMapping' => 'mappingJoinedPhonenumber', + )); + + $metadata->addNamedNativeQuery(array ( + 'name' => 'fetchUserPhonenumberCount', + 'query' => 'SELECT id, name, status, COUNT(phonenumber) AS numphones FROM cms_users INNER JOIN cms_phonenumbers ON id = user_id WHERE username IN (?) GROUP BY id, name, status, username ORDER BY username', + 'resultSetMapping' => 'mappingUserPhonenumberCount', + )); + + $metadata->addSqlResultSetMapping(array ( + 'name' => 'mappingJoinedAddress', + 'columns' => array(), + 'entities' => array(array ( + 'fields'=> array ( + array ( + 'name' => 'id', + 'column' => 'id', + ), + array ( + 'name' => 'name', + 'column' => 'name', + ), + array ( + 'name' => 'status', + 'column' => 'status', + ), + array ( + 'name' => 'address.zip', + 'column' => 'zip', + ), + array ( + 'name' => 'address.city', + 'column' => 'city', + ), + array ( + 'name' => 'address.country', + 'column' => 'country', + ), + array ( + 'name' => 'address.id', + 'column' => 'a_id', + ), + ), + 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsUser', + 'discriminatorColumn' => null + ), + ), + )); + + $metadata->addSqlResultSetMapping(array ( + 'name' => 'mappingJoinedPhonenumber', + 'columns' => array(), + 'entities' => array(array( + 'fields'=> array ( + array ( + 'name' => 'id', + 'column' => 'id', + ), + array ( + 'name' => 'name', + 'column' => 'name', + ), + array ( + 'name' => 'status', + 'column' => 'status', + ), + array ( + 'name' => 'phonenumbers.phonenumber', + 'column' => 'number', + ), + ), + 'entityClass' => 'Doctrine\\Tests\\Models\\CMS\\CmsUser', + 'discriminatorColumn' => null + ), + ), + )); + + $metadata->addSqlResultSetMapping(array ( + 'name' => 'mappingUserPhonenumberCount', + 'columns' => array(), + 'entities' => array ( + array( + 'fields' => array ( + array ( + 'name' => 'id', + 'column' => 'id', + ), + array ( + 'name' => 'name', + 'column' => 'name', + ), + array ( + 'name' => 'status', + 'column' => 'status', + ) + ), + 'entityClass' => 'Doctrine\Tests\Models\CMS\CmsUser', + 'discriminatorColumn' => null + ) + ), + 'columns' => array ( + array ( + 'name' => 'numphones', + ) + ) + )); + } } diff --git a/tests/Doctrine/Tests/Models/Company/CompanyPerson.php b/tests/Doctrine/Tests/Models/Company/CompanyPerson.php index f1cc318db..1bc916d81 100644 --- a/tests/Doctrine/Tests/Models/Company/CompanyPerson.php +++ b/tests/Doctrine/Tests/Models/Company/CompanyPerson.php @@ -108,5 +108,45 @@ class CompanyPerson $this->spouse->setSpouse($this); } } + + public static function loadMetadata(\Doctrine\ORM\Mapping\ClassMetadataInfo $metadata) + { + + $metadata->setPrimaryTable(array( + 'name' => 'company_person', + )); + + $metadata->addNamedNativeQuery(array ( + 'name' => 'fetchAllWithResultClass', + 'query' => 'SELECT id, name, discr FROM company_persons ORDER BY name', + 'resultClass' => 'Doctrine\\Tests\\Models\\Company\\CompanyPerson', + )); + + $metadata->addNamedNativeQuery(array ( + 'name' => 'fetchAllWithSqlResultSetMapping', + 'query' => 'SELECT id, name, discr AS discriminator FROM company_persons ORDER BY name', + 'resultSetMapping' => 'mappingFetchAll', + )); + + $metadata->addSqlResultSetMapping(array ( + 'name' => 'mappingFetchAll', + 'columns' => array(), + 'entities' => array ( array ( + 'fields' => array ( + array ( + 'name' => 'id', + 'column' => 'id', + ), + array ( + 'name' => 'name', + 'column' => 'name', + ), + ), + 'entityClass' => 'Doctrine\Tests\Models\Company\CompanyPerson', + 'discriminatorColumn' => 'discriminator', + ), + ), + )); + } } diff --git a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php index 1060bae84..49d2ab426 100644 --- a/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php +++ b/tests/Doctrine/Tests/ORM/Mapping/AbstractMappingDriverTest.php @@ -495,11 +495,6 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase */ public function testNamedNativeQuery() { - if (!$this instanceof AnnotationDriverTest && - !$this instanceof XmlMappingDriverTest && - !$this instanceof YamlMappingDriverTest) { - $this->markTestIncomplete(); - } $class = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsAddress'); @@ -553,11 +548,6 @@ abstract class AbstractMappingDriverTest extends \Doctrine\Tests\OrmTestCase */ public function testSqlResultSetMapping() { - if (!$this instanceof AnnotationDriverTest && - !$this instanceof XmlMappingDriverTest && - !$this instanceof YamlMappingDriverTest) { - $this->markTestIncomplete(); - } $userMetadata = $this->createClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'); $personMetadata = $this->createClassMetadata('Doctrine\Tests\Models\Company\CompanyPerson');