Skip to content

Commit d45e6d6

Browse files
committed
Merge branch '7.1' into 7.2
* 7.1: Remove subtree split checks Remove subtree split checks Revert "minor symfony#54653 Auto-close PRs on subtree-splits (nicolas-grekas)" [SecurityBundle] Fix `container.build_hash` parameter binding [Serializer] Fix denormalizing a collection of union types [DoctrineBridge] Fix `UniqueEntityValidator` with proxy object
2 parents 1b4d67d + 32483f6 commit d45e6d6

File tree

479 files changed

+356
-8010
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

479 files changed

+356
-8010
lines changed

.gitattributes

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@
77
/src/Symfony/Component/Translation/Bridge export-ignore
88
/src/Symfony/Component/Emoji/Resources/data/* linguist-generated=true
99
/src/Symfony/Component/Intl/Resources/data/*/* linguist-generated=true
10-
/.git* export-ignore

.github/sync-packages.php

Lines changed: 0 additions & 80 deletions
This file was deleted.

.github/workflows/package-tests.yml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,6 @@ jobs:
101101
done
102102
103103
exit $ok
104-
105104
- name: Verify symfony/deprecation-contracts requirements
106105
run: |
107106
set +e
@@ -142,9 +141,3 @@ jobs:
142141
done
143142
144143
exit $ok
145-
146-
- name: Verify subtree-splits are auto-closed
147-
run: |
148-
php .github/sync-packages.php
149-
git add src/
150-
git diff --staged --exit-code || (echo '::error::Please run "php .github/sync-packages.php".' && exit 1)
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/Tests export-ignore
22
/phpunit.xml.dist export-ignore
3-
/.git* export-ignore
3+
/.gitattributes export-ignore
4+
/.gitignore export-ignore

src/Symfony/Bridge/Doctrine/.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/Symfony/Bridge/Doctrine/.github/workflows/check-subtree-split.yml

Lines changed: 0 additions & 37 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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+
namespace Symfony\Bridge\Doctrine\Tests\Fixtures;
13+
14+
use Doctrine\ORM\Mapping\Column;
15+
use Doctrine\ORM\Mapping\Entity;
16+
use Doctrine\ORM\Mapping\Id;
17+
18+
#[Entity]
19+
class SingleIntIdWithPrivateNameEntity
20+
{
21+
public function __construct(
22+
#[Id, Column(type: 'integer')]
23+
protected int $id,
24+
25+
#[Column(type: 'string', nullable: true)]
26+
private ?string $name,
27+
) {
28+
}
29+
30+
public function getName(): ?string
31+
{
32+
return $this->name;
33+
}
34+
35+
public function __toString(): string
36+
{
37+
return (string) $this->name;
38+
}
39+
}

src/Symfony/Bridge/Doctrine/Tests/Validator/Constraints/UniqueEntityValidatorTest.php

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity;
3737
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity;
3838
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdStringWrapperNameEntity;
39+
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdWithPrivateNameEntity;
3940
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdEntity;
4041
use Symfony\Bridge\Doctrine\Tests\Fixtures\Type\StringWrapper;
4142
use Symfony\Bridge\Doctrine\Tests\Fixtures\Type\StringWrapperType;
@@ -90,12 +91,17 @@ protected function createRegistryMock($em = null)
9091
return $registry;
9192
}
9293

93-
protected function createRepositoryMock()
94+
protected function createRepositoryMock(string $className)
9495
{
95-
return $this->getMockBuilder(MockableRepository::class)
96+
$repositoryMock = $this->getMockBuilder(MockableRepository::class)
9697
->disableOriginalConstructor()
9798
->onlyMethods(['find', 'findAll', 'findOneBy', 'findBy', 'getClassName', 'findByCustom'])
9899
->getMock();
100+
101+
$repositoryMock->method('getClassName')
102+
->willReturn($className);
103+
104+
return $repositoryMock;
99105
}
100106

101107
protected function createEntityManagerMock($repositoryMock)
@@ -109,6 +115,10 @@ protected function createEntityManagerMock($repositoryMock)
109115
$classMetadata = $this->createMock(
110116
class_exists(ClassMetadataInfo::class) ? ClassMetadataInfo::class : ClassMetadata::class
111117
);
118+
$classMetadata
119+
->method('getName')
120+
->willReturn($repositoryMock->getClassName())
121+
;
112122
$classMetadata
113123
->expects($this->any())
114124
->method('hasField')
@@ -138,6 +148,7 @@ private function createSchema($em)
138148
$schemaTool = new SchemaTool($em);
139149
$schemaTool->createSchema([
140150
$em->getClassMetadata(SingleIntIdEntity::class),
151+
$em->getClassMetadata(SingleIntIdWithPrivateNameEntity::class),
141152
$em->getClassMetadata(SingleIntIdNoToStringEntity::class),
142153
$em->getClassMetadata(DoubleNameEntity::class),
143154
$em->getClassMetadata(DoubleNullableNameEntity::class),
@@ -194,6 +205,25 @@ public static function provideUniquenessConstraints(): iterable
194205
yield 'Named arguments' => [new UniqueEntity(message: 'myMessage', fields: ['name'], em: 'foo')];
195206
}
196207

208+
public function testValidateEntityWithPrivatePropertyAndProxyObject()
209+
{
210+
$entity = new SingleIntIdWithPrivateNameEntity(1, 'Foo');
211+
$this->em->persist($entity);
212+
$this->em->flush();
213+
214+
$this->em->clear();
215+
216+
// this will load a proxy object
217+
$entity = $this->em->getReference(SingleIntIdWithPrivateNameEntity::class, 1);
218+
219+
$this->validator->validate($entity, new UniqueEntity([
220+
'fields' => ['name'],
221+
'em' => self::EM_NAME,
222+
]));
223+
224+
$this->assertNoViolation();
225+
}
226+
197227
/**
198228
* @dataProvider provideConstraintsWithCustomErrorPath
199229
*/
@@ -387,7 +417,7 @@ public function testValidateUniquenessWithValidCustomErrorPath()
387417
*/
388418
public function testValidateUniquenessUsingCustomRepositoryMethod(UniqueEntity $constraint)
389419
{
390-
$repository = $this->createRepositoryMock();
420+
$repository = $this->createRepositoryMock(SingleIntIdEntity::class);
391421
$repository->expects($this->once())
392422
->method('findByCustom')
393423
->willReturn([])
@@ -411,7 +441,7 @@ public function testValidateUniquenessWithUnrewoundArray(UniqueEntity $constrain
411441
{
412442
$entity = new SingleIntIdEntity(1, 'foo');
413443

414-
$repository = $this->createRepositoryMock();
444+
$repository = $this->createRepositoryMock(SingleIntIdEntity::class);
415445
$repository->expects($this->once())
416446
->method('findByCustom')
417447
->willReturnCallback(
@@ -459,7 +489,7 @@ public function testValidateResultTypes($entity1, $result)
459489
'repositoryMethod' => 'findByCustom',
460490
]);
461491

462-
$repository = $this->createRepositoryMock();
492+
$repository = $this->createRepositoryMock($entity1::class);
463493
$repository->expects($this->once())
464494
->method('findByCustom')
465495
->willReturn($result)
@@ -581,7 +611,7 @@ public function testAssociatedEntityWithNull()
581611

582612
public function testValidateUniquenessWithArrayValue()
583613
{
584-
$repository = $this->createRepositoryMock();
614+
$repository = $this->createRepositoryMock(SingleIntIdEntity::class);
585615
$this->repositoryFactory->setRepository($this->em, SingleIntIdEntity::class, $repository);
586616

587617
$constraint = new UniqueEntity([
@@ -662,7 +692,7 @@ public function testEntityManagerNullObject()
662692

663693
public function testValidateUniquenessOnNullResult()
664694
{
665-
$repository = $this->createRepositoryMock();
695+
$repository = $this->createRepositoryMock(SingleIntIdEntity::class);
666696
$repository
667697
->method('find')
668698
->willReturn(null)
@@ -850,7 +880,7 @@ public function testValidateUniquenessWithEmptyIterator($entity, $result)
850880
'repositoryMethod' => 'findByCustom',
851881
]);
852882

853-
$repository = $this->createRepositoryMock();
883+
$repository = $this->createRepositoryMock($entity::class);
854884
$repository->expects($this->once())
855885
->method('findByCustom')
856886
->willReturn($result)

src/Symfony/Bridge/Doctrine/Validator/Constraints/UniqueEntityValidator.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,9 @@ private function getFieldValues(mixed $object, ClassMetadata $class, array $fiel
287287
throw new ConstraintDefinitionException(sprintf('The field "%s" is not a property of class "%s".', $fieldName, $objectClass));
288288
}
289289

290-
$fieldValues[$entityFieldName] = $this->getPropertyValue($objectClass, $fieldName, $object);
290+
$fieldValues[$entityFieldName] = $isValueEntity && $object instanceof ($class->getName())
291+
? $class->reflFields[$fieldName]->getValue($object)
292+
: $this->getPropertyValue($objectClass, $fieldName, $object);
291293
}
292294

293295
return $fieldValues;
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/Tests export-ignore
22
/phpunit.xml.dist export-ignore
3-
/.git* export-ignore
3+
/.gitattributes export-ignore
4+
/.gitignore export-ignore

0 commit comments

Comments
 (0)