Skip to content

Commit 9b71beb

Browse files
committed
Merge branch '7.2' into 7.3
* 7.2: 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 7.2.6 Update VERSION for 7.2.5 Update CHANGELOG for 7.2.5 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 529bb34 + 8d9c8a5 commit 9b71beb

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);
@@ -445,13 +386,7 @@ public function testValidateUniquenessWithValidCustomErrorPath()
445386

446387
public function testValidateUniquenessUsingCustomRepositoryMethod()
447388
{
448-
$repository = $this->createRepositoryMock(SingleIntIdEntity::class);
449-
$repository->expects($this->once())
450-
->method('findByCustom')
451-
->willReturn([])
452-
;
453-
$this->em = $this->createEntityManagerMock($repository);
454-
$this->registry = $this->createRegistryMock($this->em);
389+
$this->em->getRepository(SingleIntIdEntity::class)->result = [];
455390
$this->validator = $this->createValidator();
456391
$this->validator->initialize($this->context);
457392

@@ -466,22 +401,12 @@ public function testValidateUniquenessWithUnrewoundArray()
466401
{
467402
$entity = new SingleIntIdEntity(1, 'foo');
468403

469-
$repository = $this->createRepositoryMock(SingleIntIdEntity::class);
470-
$repository->expects($this->once())
471-
->method('findByCustom')
472-
->willReturnCallback(
473-
function () use ($entity) {
474-
$returnValue = [
475-
$entity,
476-
];
477-
next($returnValue);
478-
479-
return $returnValue;
480-
}
481-
)
482-
;
483-
$this->em = $this->createEntityManagerMock($repository);
484-
$this->registry = $this->createRegistryMock($this->em);
404+
$returnValue = [
405+
$entity,
406+
];
407+
next($returnValue);
408+
409+
$this->em->getRepository(SingleIntIdEntity::class)->result = $returnValue;
485410
$this->validator = $this->createValidator();
486411
$this->validator->initialize($this->context);
487412

@@ -502,13 +427,7 @@ public function testValidateResultTypes($entity1, $result)
502427
repositoryMethod: 'findByCustom',
503428
);
504429

505-
$repository = $this->createRepositoryMock($entity1::class);
506-
$repository->expects($this->once())
507-
->method('findByCustom')
508-
->willReturn($result)
509-
;
510-
$this->em = $this->createEntityManagerMock($repository);
511-
$this->registry = $this->createRegistryMock($this->em);
430+
$this->em->getRepository(SingleIntIdEntity::class)->result = $result;
512431
$this->validator = $this->createValidator();
513432
$this->validator->initialize($this->context);
514433

@@ -658,9 +577,6 @@ public function testAssociatedEntityReferencedByPrimaryKey()
658577

659578
public function testValidateUniquenessWithArrayValue()
660579
{
661-
$repository = $this->createRepositoryMock(SingleIntIdEntity::class);
662-
$this->repositoryFactory->setRepository($this->em, SingleIntIdEntity::class, $repository);
663-
664580
$constraint = new UniqueEntity(
665581
message: 'myMessage',
666582
fields: ['phoneNumbers'],
@@ -671,10 +587,7 @@ public function testValidateUniquenessWithArrayValue()
671587
$entity1 = new SingleIntIdEntity(1, 'foo');
672588
$entity1->phoneNumbers[] = 123;
673589

674-
$repository->expects($this->once())
675-
->method('findByCustom')
676-
->willReturn([$entity1])
677-
;
590+
$this->em->getRepository(SingleIntIdEntity::class)->result = $entity1;
678591

679592
$this->em->persist($entity1);
680593
$this->em->flush();
@@ -724,8 +637,6 @@ public function testEntityManagerNullObject()
724637
// no "em" option set
725638
);
726639

727-
$this->em = null;
728-
$this->registry = $this->createRegistryMock($this->em);
729640
$this->validator = $this->createValidator();
730641
$this->validator->initialize($this->context);
731642

@@ -739,14 +650,6 @@ public function testEntityManagerNullObject()
739650

740651
public function testValidateUniquenessOnNullResult()
741652
{
742-
$repository = $this->createRepositoryMock(SingleIntIdEntity::class);
743-
$repository
744-
->method('find')
745-
->willReturn(null)
746-
;
747-
748-
$this->em = $this->createEntityManagerMock($repository);
749-
$this->registry = $this->createRegistryMock($this->em);
750653
$this->validator = $this->createValidator();
751654
$this->validator->initialize($this->context);
752655

@@ -927,13 +830,7 @@ public function testValidateUniquenessWithEmptyIterator($entity, $result)
927830
repositoryMethod: 'findByCustom',
928831
);
929832

930-
$repository = $this->createRepositoryMock($entity::class);
931-
$repository->expects($this->once())
932-
->method('findByCustom')
933-
->willReturn($result)
934-
;
935-
$this->em = $this->createEntityManagerMock($repository);
936-
$this->registry = $this->createRegistryMock($this->em);
833+
$this->em->getRepository(SingleIntIdEntity::class)->result = $result;
937834
$this->validator = $this->createValidator();
938835
$this->validator->initialize($this->context);
939836

0 commit comments

Comments
 (0)