Skip to content

Commit 8d9c8a5

Browse files
committed
Merge branch '6.4' into 7.2
* 6.4: fix tests with Doctrine ORM 3.4+ on PHP < 8.4 reject URLs with URL-encoded non UTF-8 characters in the host part Bump Symfony version to 6.4.21 Update VERSION for 6.4.20 Update CONTRIBUTORS for 6.4.20 Update CHANGELOG for 6.4.20
2 parents f8a298b + d7733a3 commit 8d9c8a5

File tree

3 files changed

+36
-115
lines changed

3 files changed

+36
-115
lines changed

Tests/Fixtures/SingleIntIdEntity.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
use Doctrine\ORM\Mapping\Entity;
1717
use Doctrine\ORM\Mapping\Id;
1818

19-
#[Entity]
19+
#[Entity(repositoryClass: SingleIntIdEntityRepository::class)]
2020
class SingleIntIdEntity
2121
{
2222
#[Column(type: Types::JSON, nullable: true)]
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
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+
namespace Symfony\Bridge\Doctrine\Tests\Fixtures;
13+
14+
use Doctrine\ORM\EntityRepository;
15+
16+
class SingleIntIdEntityRepository extends EntityRepository
17+
{
18+
public $result = null;
19+
20+
public function findByCustom()
21+
{
22+
return $this->result;
23+
}
24+
}

Tests/Validator/Constraints/UniqueEntityValidatorTest.php

Lines changed: 11 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,7 @@
1414
use Doctrine\Common\Collections\ArrayCollection;
1515
use Doctrine\DBAL\Types\Type;
1616
use Doctrine\ORM\EntityRepository;
17-
use Doctrine\ORM\Mapping\ClassMetadata;
1817
use Doctrine\ORM\Mapping\ClassMetadataInfo;
19-
use Doctrine\ORM\Mapping\PropertyAccessors\RawValuePropertyAccessor;
2018
use Doctrine\ORM\Tools\SchemaTool;
2119
use Doctrine\Persistence\ManagerRegistry;
2220
use Doctrine\Persistence\ObjectManager;
@@ -33,8 +31,8 @@
3331
use Symfony\Bridge\Doctrine\Tests\Fixtures\Dto;
3432
use Symfony\Bridge\Doctrine\Tests\Fixtures\Employee;
3533
use Symfony\Bridge\Doctrine\Tests\Fixtures\HireAnEmployee;
36-
use Symfony\Bridge\Doctrine\Tests\Fixtures\MockableRepository;
3734
use Symfony\Bridge\Doctrine\Tests\Fixtures\Person;
35+
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntityRepository;
3836
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity;
3937
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity;
4038
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdStringWrapperNameEntity;
@@ -99,63 +97,6 @@ protected function createRegistryMock($em = null)
9997
return $registry;
10098
}
10199

102-
protected function createRepositoryMock(string $className)
103-
{
104-
$repositoryMock = $this->getMockBuilder(MockableRepository::class)
105-
->disableOriginalConstructor()
106-
->onlyMethods(['find', 'findAll', 'findOneBy', 'findBy', 'getClassName', 'findByCustom'])
107-
->getMock();
108-
109-
$repositoryMock->method('getClassName')
110-
->willReturn($className);
111-
112-
return $repositoryMock;
113-
}
114-
115-
protected function createEntityManagerMock($repositoryMock)
116-
{
117-
$em = $this->createMock(ObjectManager::class);
118-
$em->expects($this->any())
119-
->method('getRepository')
120-
->willReturn($repositoryMock)
121-
;
122-
123-
$classMetadata = $this->createMock(
124-
class_exists(ClassMetadataInfo::class) ? ClassMetadataInfo::class : ClassMetadata::class
125-
);
126-
$classMetadata
127-
->method('getName')
128-
->willReturn($repositoryMock->getClassName())
129-
;
130-
$classMetadata
131-
->expects($this->any())
132-
->method('hasField')
133-
->willReturn(true)
134-
;
135-
$refl = $this->createMock(\ReflectionProperty::class);
136-
$refl
137-
->method('getName')
138-
->willReturn('name')
139-
;
140-
$refl
141-
->method('getValue')
142-
->willReturn(true)
143-
;
144-
145-
if (property_exists(ClassMetadata::class, 'propertyAccessors')) {
146-
$classMetadata->propertyAccessors['name'] = RawValuePropertyAccessor::fromReflectionProperty($refl);
147-
} else {
148-
$classMetadata->reflFields = ['name' => $refl];
149-
}
150-
151-
$em->expects($this->any())
152-
->method('getClassMetadata')
153-
->willReturn($classMetadata)
154-
;
155-
156-
return $em;
157-
}
158-
159100
protected function createValidator(): UniqueEntityValidator
160101
{
161102
return new UniqueEntityValidator($this->registry);
@@ -435,13 +376,7 @@ public function testValidateUniquenessWithValidCustomErrorPath()
435376
*/
436377
public function testValidateUniquenessUsingCustomRepositoryMethod(UniqueEntity $constraint)
437378
{
438-
$repository = $this->createRepositoryMock(SingleIntIdEntity::class);
439-
$repository->expects($this->once())
440-
->method('findByCustom')
441-
->willReturn([])
442-
;
443-
$this->em = $this->createEntityManagerMock($repository);
444-
$this->registry = $this->createRegistryMock($this->em);
379+
$this->em->getRepository(SingleIntIdEntity::class)->result = [];
445380
$this->validator = $this->createValidator();
446381
$this->validator->initialize($this->context);
447382

@@ -459,22 +394,12 @@ public function testValidateUniquenessWithUnrewoundArray(UniqueEntity $constrain
459394
{
460395
$entity = new SingleIntIdEntity(1, 'foo');
461396

462-
$repository = $this->createRepositoryMock(SingleIntIdEntity::class);
463-
$repository->expects($this->once())
464-
->method('findByCustom')
465-
->willReturnCallback(
466-
function () use ($entity) {
467-
$returnValue = [
468-
$entity,
469-
];
470-
next($returnValue);
471-
472-
return $returnValue;
473-
}
474-
)
475-
;
476-
$this->em = $this->createEntityManagerMock($repository);
477-
$this->registry = $this->createRegistryMock($this->em);
397+
$returnValue = [
398+
$entity,
399+
];
400+
next($returnValue);
401+
402+
$this->em->getRepository(SingleIntIdEntity::class)->result = $returnValue;
478403
$this->validator = $this->createValidator();
479404
$this->validator->initialize($this->context);
480405

@@ -507,13 +432,7 @@ public function testValidateResultTypes($entity1, $result)
507432
'repositoryMethod' => 'findByCustom',
508433
]);
509434

510-
$repository = $this->createRepositoryMock($entity1::class);
511-
$repository->expects($this->once())
512-
->method('findByCustom')
513-
->willReturn($result)
514-
;
515-
$this->em = $this->createEntityManagerMock($repository);
516-
$this->registry = $this->createRegistryMock($this->em);
435+
$this->em->getRepository(SingleIntIdEntity::class)->result = $result;
517436
$this->validator = $this->createValidator();
518437
$this->validator->initialize($this->context);
519438

@@ -663,9 +582,6 @@ public function testAssociatedEntityReferencedByPrimaryKey()
663582

664583
public function testValidateUniquenessWithArrayValue()
665584
{
666-
$repository = $this->createRepositoryMock(SingleIntIdEntity::class);
667-
$this->repositoryFactory->setRepository($this->em, SingleIntIdEntity::class, $repository);
668-
669585
$constraint = new UniqueEntity([
670586
'message' => 'myMessage',
671587
'fields' => ['phoneNumbers'],
@@ -676,10 +592,7 @@ public function testValidateUniquenessWithArrayValue()
676592
$entity1 = new SingleIntIdEntity(1, 'foo');
677593
$entity1->phoneNumbers[] = 123;
678594

679-
$repository->expects($this->once())
680-
->method('findByCustom')
681-
->willReturn([$entity1])
682-
;
595+
$this->em->getRepository(SingleIntIdEntity::class)->result = $entity1;
683596

684597
$this->em->persist($entity1);
685598
$this->em->flush();
@@ -729,8 +642,6 @@ public function testEntityManagerNullObject()
729642
// no "em" option set
730643
]);
731644

732-
$this->em = null;
733-
$this->registry = $this->createRegistryMock($this->em);
734645
$this->validator = $this->createValidator();
735646
$this->validator->initialize($this->context);
736647

@@ -744,14 +655,6 @@ public function testEntityManagerNullObject()
744655

745656
public function testValidateUniquenessOnNullResult()
746657
{
747-
$repository = $this->createRepositoryMock(SingleIntIdEntity::class);
748-
$repository
749-
->method('find')
750-
->willReturn(null)
751-
;
752-
753-
$this->em = $this->createEntityManagerMock($repository);
754-
$this->registry = $this->createRegistryMock($this->em);
755658
$this->validator = $this->createValidator();
756659
$this->validator->initialize($this->context);
757660

@@ -932,13 +835,7 @@ public function testValidateUniquenessWithEmptyIterator($entity, $result)
932835
'repositoryMethod' => 'findByCustom',
933836
]);
934837

935-
$repository = $this->createRepositoryMock($entity::class);
936-
$repository->expects($this->once())
937-
->method('findByCustom')
938-
->willReturn($result)
939-
;
940-
$this->em = $this->createEntityManagerMock($repository);
941-
$this->registry = $this->createRegistryMock($this->em);
838+
$this->em->getRepository(SingleIntIdEntity::class)->result = $result;
942839
$this->validator = $this->createValidator();
943840
$this->validator->initialize($this->context);
944841

0 commit comments

Comments
 (0)