Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit79d75ff

Browse files
committed
Run high-deps tests with ORM 3 and DBAL 4
1 parent7aaa92a commit79d75ff

File tree

19 files changed

+247
-145
lines changed

19 files changed

+247
-145
lines changed

‎src/Symfony/Bridge/Doctrine/PropertyInfo/DoctrineExtractor.php‎

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@
1414
useDoctrine\Common\Collections\Collection;
1515
useDoctrine\DBAL\Types\Types;
1616
useDoctrine\ORM\EntityManagerInterface;
17+
useDoctrine\ORM\Mapping\AssociationMapping;
1718
useDoctrine\ORM\Mapping\ClassMetadata;
18-
useDoctrine\ORM\Mapping\ClassMetadataInfo;
19-
useDoctrine\ORM\Mapping\Embedded;
2019
useDoctrine\ORM\Mapping\MappingExceptionasOrmMappingException;
2120
useDoctrine\Persistence\Mapping\MappingException;
2221
useSymfony\Component\PropertyInfo\PropertyAccessExtractorInterface;
@@ -49,7 +48,7 @@ public function getProperties(string $class, array $context = [])
4948

5049
$properties =array_merge($metadata->getFieldNames(),$metadata->getAssociationNames());
5150

52-
if ($metadatainstanceofClassMetadataInfo &&class_exists(Embedded::class) &&$metadata->embeddedClasses) {
51+
if ($metadatainstanceofClassMetadata &&$metadata->embeddedClasses) {
5352
$properties =array_filter($properties,function ($property) {
5453
return !str_contains($property,'.');
5554
});
@@ -73,7 +72,7 @@ public function getTypes(string $class, string $property, array $context = [])
7372
$class =$metadata->getAssociationTargetClass($property);
7473

7574
if ($metadata->isSingleValuedAssociation($property)) {
76-
if ($metadatainstanceofClassMetadataInfo) {
75+
if ($metadatainstanceofClassMetadata) {
7776
$associationMapping =$metadata->getAssociationMapping($property);
7877

7978
$nullable =$this->isAssociationNullable($associationMapping);
@@ -86,11 +85,10 @@ public function getTypes(string $class, string $property, array $context = [])
8685

8786
$collectionKeyType = Type::BUILTIN_TYPE_INT;
8887

89-
if ($metadatainstanceofClassMetadataInfo) {
88+
if ($metadatainstanceofClassMetadata) {
9089
$associationMapping =$metadata->getAssociationMapping($property);
9190

9291
if (isset($associationMapping['indexBy'])) {
93-
/** @var ClassMetadataInfo $subMetadata */
9492
$subMetadata =$this->entityManager->getClassMetadata($associationMapping['targetEntity']);
9593

9694
// Check if indexBy value is a property
@@ -102,7 +100,6 @@ public function getTypes(string $class, string $property, array $context = [])
102100
// Maybe the column name is the association join column?
103101
$associationMapping =$subMetadata->getAssociationMapping($fieldName);
104102

105-
/** @var ClassMetadataInfo $subMetadata */
106103
$indexProperty =$subMetadata->getSingleAssociationReferencedJoinColumnName($fieldName);
107104
$subMetadata =$this->entityManager->getClassMetadata($associationMapping['targetEntity']);
108105

@@ -130,7 +127,7 @@ public function getTypes(string $class, string $property, array $context = [])
130127
)];
131128
}
132129

133-
if ($metadatainstanceofClassMetadataInfo &&class_exists(Embedded::class) &&isset($metadata->embeddedClasses[$property])) {
130+
if ($metadatainstanceofClassMetadata &&isset($metadata->embeddedClasses[$property])) {
134131
return [newType(Type::BUILTIN_TYPE_OBJECT,false,$metadata->embeddedClasses[$property]['class'])];
135132
}
136133

@@ -141,7 +138,7 @@ public function getTypes(string $class, string $property, array $context = [])
141138
returnnull;
142139
}
143140

144-
$nullable =$metadatainstanceofClassMetadataInfo &&$metadata->isNullable($property);
141+
$nullable =$metadatainstanceofClassMetadata &&$metadata->isNullable($property);
145142
$enumType =null;
146143
if (null !==$enumClass =$metadata->getFieldMapping($property)['enumType'] ??null) {
147144
$enumType =newType(Type::BUILTIN_TYPE_OBJECT,$nullable,$enumClass);
@@ -233,9 +230,11 @@ private function getMetadata(string $class): ?ClassMetadata
233230
/**
234231
* Determines whether an association is nullable.
235232
*
233+
* @param array<string, mixed>|AssociationMapping $associationMapping
234+
*
236235
* @see https://github.com/doctrine/doctrine2/blob/v2.5.4/lib/Doctrine/ORM/Tools/EntityGenerator.php#L1221-L1246
237236
*/
238-
privatefunctionisAssociationNullable(array$associationMapping):bool
237+
privatefunctionisAssociationNullable($associationMapping):bool
239238
{
240239
if (isset($associationMapping['id']) &&$associationMapping['id']) {
241240
returnfalse;

‎src/Symfony/Bridge/Doctrine/Test/TestRepositoryFactory.php‎

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,51 @@
1212
namespaceSymfony\Bridge\Doctrine\Test;
1313

1414
useDoctrine\ORM\EntityManagerInterface;
15+
useDoctrine\ORM\EntityRepository;
1516
useDoctrine\ORM\Mapping\ClassMetadata;
1617
useDoctrine\ORM\Repository\RepositoryFactory;
1718
useDoctrine\Persistence\ObjectRepository;
1819

20+
if ((new \ReflectionMethod(RepositoryFactory::class,'getRepository'))->hasReturnType()) {
21+
/** @internal */
22+
trait GetRepositoryTrait
23+
{
24+
publicfunctiongetRepository(EntityManagerInterface$entityManager,string$entityName):EntityRepository
25+
{
26+
return$this->doGetRepository($entityManager,$entityName);
27+
}
28+
}
29+
}else {
30+
/** @internal */
31+
trait GetRepositoryTrait
32+
{
33+
/**
34+
* {@inheritdoc}
35+
*
36+
* @return ObjectRepository
37+
*/
38+
publicfunctiongetRepository(EntityManagerInterface$entityManager,$entityName)
39+
{
40+
return$this->doGetRepository($entityManager,$entityName);
41+
}
42+
}
43+
}
44+
1945
/**
2046
* @author Andreas Braun <alcaeus@alcaeus.org>
2147
*
2248
* @deprecated since Symfony 5.3
2349
*/
2450
class TestRepositoryFactoryimplements RepositoryFactory
2551
{
52+
use GetRepositoryTrait;
53+
2654
/**
2755
* @var ObjectRepository[]
2856
*/
2957
private$repositoryList = [];
3058

31-
/**
32-
* {@inheritdoc}
33-
*
34-
* @return ObjectRepository
35-
*/
36-
publicfunctiongetRepository(EntityManagerInterface$entityManager,$entityName)
59+
privatefunctiondoGetRepository(EntityManagerInterface$entityManager,string$entityName):ObjectRepository
3760
{
3861
if (__CLASS__ ===static::class) {
3962
trigger_deprecation('symfony/doctrine-bridge','5.3','"%s" is deprecated and will be removed in 6.0.',__CLASS__);
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespaceSymfony\Bridge\Doctrine\Tests\Fixtures;
13+
14+
useDoctrine\DBAL\Result;
15+
useDoctrine\ORM\AbstractQuery;
16+
17+
class LegacyQueryMockextends AbstractQuery
18+
{
19+
publicfunction__construct()
20+
{
21+
}
22+
23+
/**
24+
* @return array|string
25+
*/
26+
publicfunctiongetSQL()
27+
{
28+
}
29+
30+
/**
31+
* @return Result|int
32+
*/
33+
protectedfunction_doExecute()
34+
{
35+
}
36+
}

‎src/Symfony/Bridge/Doctrine/Tests/Form/ChoiceList/ORMQueryBuilderLoaderTest.php‎

Lines changed: 28 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,19 @@
1313

1414
useDoctrine\DBAL\ArrayParameterType;
1515
useDoctrine\DBAL\Connection;
16-
useDoctrine\DBAL\Result;
1716
useDoctrine\DBAL\Types\GuidType;
1817
useDoctrine\DBAL\Types\Type;
1918
useDoctrine\ORM\AbstractQuery;
20-
useDoctrine\ORM\Version;
19+
useDoctrine\ORM\Query;
20+
useDoctrine\ORM\QueryBuilder;
21+
usePHPUnit\Framework\MockObject\MockObject;
2122
usePHPUnit\Framework\TestCase;
2223
useSymfony\Bridge\Doctrine\Form\ChoiceList\ORMQueryBuilderLoader;
2324
useSymfony\Bridge\Doctrine\Tests\DoctrineTestHelper;
25+
useSymfony\Bridge\Doctrine\Tests\Fixtures\EmbeddedIdentifierEntity;
26+
useSymfony\Bridge\Doctrine\Tests\Fixtures\LegacyQueryMock;
27+
useSymfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity;
28+
useSymfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdEntity;
2429
useSymfony\Bridge\Doctrine\Types\UlidType;
2530
useSymfony\Bridge\Doctrine\Types\UuidType;
2631
useSymfony\Component\Form\Exception\TransformationFailedException;
@@ -37,21 +42,19 @@ protected function tearDown(): void
3742

3843
publicfunctiontestIdentifierTypeIsStringArray()
3944
{
40-
$this->checkIdentifierType('Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdEntity',class_exists(ArrayParameterType::class) ? ArrayParameterType::STRING : Connection::PARAM_STR_ARRAY);
45+
$this->checkIdentifierType(SingleStringIdEntity::class,class_exists(ArrayParameterType::class) ? ArrayParameterType::STRING : Connection::PARAM_STR_ARRAY);
4146
}
4247

4348
publicfunctiontestIdentifierTypeIsIntegerArray()
4449
{
45-
$this->checkIdentifierType('Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity',class_exists(ArrayParameterType::class) ? ArrayParameterType::INTEGER : Connection::PARAM_INT_ARRAY);
50+
$this->checkIdentifierType(SingleIntIdEntity::class,class_exists(ArrayParameterType::class) ? ArrayParameterType::INTEGER : Connection::PARAM_INT_ARRAY);
4651
}
4752

48-
protectedfunctioncheckIdentifierType($classname,$expectedType)
53+
protectedfunctioncheckIdentifierType(string$classname,$expectedType)
4954
{
5055
$em = DoctrineTestHelper::createTestEntityManager();
5156

52-
$query =$this->getMockBuilder(QueryMock::class)
53-
->onlyMethods(['setParameter','getResult','getSql','_doExecute'])
54-
->getMock();
57+
$query =$this->getQueryMock();
5558

5659
$query
5760
->method('getResult')
@@ -62,7 +65,7 @@ protected function checkIdentifierType($classname, $expectedType)
6265
->with('ORMQueryBuilderLoader_getEntitiesByIds_id', [1,2],$expectedType)
6366
->willReturn($query);
6467

65-
$qb =$this->getMockBuilder(\Doctrine\ORM\QueryBuilder::class)
68+
$qb =$this->getMockBuilder(QueryBuilder::class)
6669
->setConstructorArgs([$em])
6770
->onlyMethods(['getQuery'])
6871
->getMock();
@@ -82,9 +85,7 @@ public function testFilterNonIntegerValues()
8285
{
8386
$em = DoctrineTestHelper::createTestEntityManager();
8487

85-
$query =$this->getMockBuilder(QueryMock::class)
86-
->onlyMethods(['setParameter','getResult','getSql','_doExecute'])
87-
->getMock();
88+
$query =$this->getQueryMock();
8889

8990
$query
9091
->method('getResult')
@@ -95,7 +96,7 @@ public function testFilterNonIntegerValues()
9596
->with('ORMQueryBuilderLoader_getEntitiesByIds_id', [1,2,3,'9223372036854775808'],class_exists(ArrayParameterType::class) ? ArrayParameterType::INTEGER : Connection::PARAM_INT_ARRAY)
9697
->willReturn($query);
9798

98-
$qb =$this->getMockBuilder(\Doctrine\ORM\QueryBuilder::class)
99+
$qb =$this->getMockBuilder(QueryBuilder::class)
99100
->setConstructorArgs([$em])
100101
->onlyMethods(['getQuery'])
101102
->getMock();
@@ -118,9 +119,7 @@ public function testFilterEmptyUuids($entityClass)
118119
{
119120
$em = DoctrineTestHelper::createTestEntityManager();
120121

121-
$query =$this->getMockBuilder(QueryMock::class)
122-
->onlyMethods(['setParameter','getResult','getSql','_doExecute'])
123-
->getMock();
122+
$query =$this->getQueryMock();
124123

125124
$query
126125
->method('getResult')
@@ -131,7 +130,7 @@ public function testFilterEmptyUuids($entityClass)
131130
->with('ORMQueryBuilderLoader_getEntitiesByIds_id', ['71c5fd46-3f16-4abb-bad7-90ac1e654a2d','b98e8e11-2897-44df-ad24-d2627eb7f499'],class_exists(ArrayParameterType::class) ? ArrayParameterType::STRING : Connection::PARAM_STR_ARRAY)
132131
->willReturn($query);
133132

134-
$qb =$this->getMockBuilder(\Doctrine\ORM\QueryBuilder::class)
133+
$qb =$this->getMockBuilder(QueryBuilder::class)
135134
->setConstructorArgs([$em])
136135
->onlyMethods(['getQuery'])
137136
->getMock();
@@ -163,9 +162,7 @@ public function testFilterUid($entityClass)
163162

164163
$em = DoctrineTestHelper::createTestEntityManager();
165164

166-
$query =$this->getMockBuilder(QueryMock::class)
167-
->onlyMethods(['setParameter','getResult','getSql','_doExecute'])
168-
->getMock();
165+
$query =$this->getQueryMock();
169166

170167
$query
171168
->method('getResult')
@@ -176,7 +173,7 @@ public function testFilterUid($entityClass)
176173
->with('ORMQueryBuilderLoader_getEntitiesByIds_id', [Uuid::fromString('71c5fd46-3f16-4abb-bad7-90ac1e654a2d')->toBinary(), Uuid::fromString('b98e8e11-2897-44df-ad24-d2627eb7f499')->toBinary()],class_exists(ArrayParameterType::class) ? ArrayParameterType::STRING : Connection::PARAM_STR_ARRAY)
177174
->willReturn($query);
178175

179-
$qb =$this->getMockBuilder(\Doctrine\ORM\QueryBuilder::class)
176+
$qb =$this->getMockBuilder(QueryBuilder::class)
180177
->setConstructorArgs([$em])
181178
->onlyMethods(['getQuery'])
182179
->getMock();
@@ -208,7 +205,7 @@ public function testUidThrowProperException($entityClass)
208205

209206
$em = DoctrineTestHelper::createTestEntityManager();
210207

211-
$qb =$this->getMockBuilder(\Doctrine\ORM\QueryBuilder::class)
208+
$qb =$this->getMockBuilder(QueryBuilder::class)
212209
->setConstructorArgs([$em])
213210
->onlyMethods(['getQuery'])
214211
->getMock();
@@ -229,17 +226,9 @@ public function testUidThrowProperException($entityClass)
229226

230227
publicfunctiontestEmbeddedIdentifierName()
231228
{
232-
if (Version::compare('2.5.0') >0) {
233-
$this->markTestSkipped('Applicable only for Doctrine >= 2.5.0');
234-
235-
return;
236-
}
237-
238229
$em = DoctrineTestHelper::createTestEntityManager();
239230

240-
$query =$this->getMockBuilder(QueryMock::class)
241-
->onlyMethods(['setParameter','getResult','getSql','_doExecute'])
242-
->getMock();
231+
$query =$this->getQueryMock();
243232

244233
$query
245234
->method('getResult')
@@ -250,7 +239,7 @@ public function testEmbeddedIdentifierName()
250239
->with('ORMQueryBuilderLoader_getEntitiesByIds_id_value', [1,2,3],class_exists(ArrayParameterType::class) ? ArrayParameterType::INTEGER : Connection::PARAM_INT_ARRAY)
251240
->willReturn($query);
252241

253-
$qb =$this->getMockBuilder(\Doctrine\ORM\QueryBuilder::class)
242+
$qb =$this->getMockBuilder(QueryBuilder::class)
254243
->setConstructorArgs([$em])
255244
->onlyMethods(['getQuery'])
256245
->getMock();
@@ -259,46 +248,35 @@ public function testEmbeddedIdentifierName()
259248
->willReturn($query);
260249

261250
$qb->select('e')
262-
->from('Symfony\Bridge\Doctrine\Tests\Fixtures\EmbeddedIdentifierEntity','e');
251+
->from(EmbeddedIdentifierEntity::class,'e');
263252

264253
$loader =newORMQueryBuilderLoader($qb);
265254
$loader->getEntitiesByIds('id.value', [1,'',2,3,'foo']);
266255
}
267256

268-
publicstaticfunctionprovideGuidEntityClasses()
257+
publicstaticfunctionprovideGuidEntityClasses():array
269258
{
270259
return [
271260
['Symfony\Bridge\Doctrine\Tests\Fixtures\GuidIdEntity'],
272261
['Symfony\Bridge\Doctrine\Tests\Fixtures\UuidIdEntity'],
273262
];
274263
}
275264

276-
publicstaticfunctionprovideUidEntityClasses()
265+
publicstaticfunctionprovideUidEntityClasses():array
277266
{
278267
return [
279268
['Symfony\Bridge\Doctrine\Tests\Fixtures\UuidIdEntity'],
280269
['Symfony\Bridge\Doctrine\Tests\Fixtures\UlidIdEntity'],
281270
];
282271
}
283-
}
284-
285-
class QueryMockextends AbstractQuery
286-
{
287-
publicfunction__construct()
288-
{
289-
}
290272

291273
/**
292-
* @returnarray|string
274+
* @return(LegacyQueryMock&MockObject)|(Query&MockObject)
293275
*/
294-
publicfunctiongetSQL()
276+
privatefunctiongetQueryMock():AbstractQuery
295277
{
296-
}
278+
$class = ((new \ReflectionClass(Query::class))->isFinal()) ? LegacyQueryMock::class : Query::class;
297279

298-
/**
299-
* @return Result|int
300-
*/
301-
protectedfunction_doExecute()
302-
{
280+
return$this->createMock($class);
303281
}
304282
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp