|
6 | 6 |
|
7 | 7 | use Doctrine\Common\Collections\ArrayCollection; |
8 | 8 | use Doctrine\DBAL\Platforms\AbstractPlatform; |
| 9 | +use Doctrine\DBAL\Types\Type as DBALType; |
9 | 10 | use Doctrine\Deprecations\PHPUnit\VerifyDeprecations; |
10 | 11 | use Doctrine\ORM\Internal\Hydration\HydrationException; |
11 | 12 | use Doctrine\ORM\Internal\SQLResultCasing; |
12 | 13 | use Doctrine\ORM\PersistentCollection; |
13 | 14 | use Doctrine\ORM\Query\Parameter; |
14 | 15 | use Doctrine\ORM\Query\ResultSetMapping; |
15 | 16 | use Doctrine\ORM\Query\ResultSetMappingBuilder; |
| 17 | +use Doctrine\Tests\DbalTypes\UpperCaseStringType; |
16 | 18 | use Doctrine\Tests\Models\CMS\CmsAddress; |
17 | 19 | use Doctrine\Tests\Models\CMS\CmsEmail; |
18 | 20 | use Doctrine\Tests\Models\CMS\CmsPhonenumber; |
|
22 | 24 | use Doctrine\Tests\Models\Company\CompanyFixContract; |
23 | 25 | use Doctrine\Tests\Models\Company\CompanyFlexContract; |
24 | 26 | use Doctrine\Tests\Models\Company\CompanyPerson; |
| 27 | +use Doctrine\Tests\Models\CustomType\CustomTypeUpperCase; |
25 | 28 | use Doctrine\Tests\Models\DDC3899\DDC3899FixContract; |
26 | 29 | use Doctrine\Tests\Models\DDC3899\DDC3899User; |
27 | 30 | use Doctrine\Tests\OrmFunctionalTestCase; |
@@ -796,4 +799,38 @@ public function testGenerateSelectClauseWithDiscriminatorColumn(): void |
796 | 799 |
|
797 | 800 | $this->assertSQLEquals('u1.id as id, c1.discr as discr', $selectClause); |
798 | 801 | } |
| 802 | + |
| 803 | + public function testGenerateSelectClauseWithCustomTypeUsingEntityFromClassMetadata(): void |
| 804 | + { |
| 805 | + if (DBALType::hasType('upper_case_string')) { |
| 806 | + DBALType::overrideType('upper_case_string', UpperCaseStringType::class); |
| 807 | + } else { |
| 808 | + DBALType::addType('upper_case_string', UpperCaseStringType::class); |
| 809 | + } |
| 810 | + |
| 811 | + $rsm = new ResultSetMappingBuilder($this->_em, ResultSetMappingBuilder::COLUMN_RENAMING_INCREMENT); |
| 812 | + |
| 813 | + $rsm->addRootEntityFromClassMetadata(CustomTypeUpperCase::class, 'ct'); |
| 814 | + |
| 815 | + $selectClause = $rsm->generateSelectClause(['ct' => 'ct1']); |
| 816 | + |
| 817 | + $this->assertSQLEquals('ct1.id as id0, lower(ct1.lowercasestring) as lowercasestring1, lower(ct1.named_lower_case_string) as named_lower_case_string2', $selectClause); |
| 818 | + } |
| 819 | + |
| 820 | + public function testGenerateSelectClauseWithCustomTypeUsingAddFieldResult(): void |
| 821 | + { |
| 822 | + if (DBALType::hasType('upper_case_string')) { |
| 823 | + DBALType::overrideType('upper_case_string', UpperCaseStringType::class); |
| 824 | + } else { |
| 825 | + DBALType::addType('upper_case_string', UpperCaseStringType::class); |
| 826 | + } |
| 827 | + |
| 828 | + $rsm = new ResultSetMappingBuilder($this->_em, ResultSetMappingBuilder::COLUMN_RENAMING_INCREMENT); |
| 829 | + $rsm->addEntityResult(CustomTypeUpperCase::class, 'ct'); |
| 830 | + $rsm->addFieldResult('ct', $this->getSQLResultCasing($this->platform, 'lowercasestring'), 'lowerCaseString'); |
| 831 | + |
| 832 | + $selectClause = $rsm->generateSelectClause(['ct' => 'ct1']); |
| 833 | + |
| 834 | + $this->assertSQLEquals('lower(ct1.lowercasestring) as lowercasestring', $selectClause); |
| 835 | + } |
799 | 836 | } |
0 commit comments