Skip to content

Commit b492be5

Browse files
committed
Merge branch '7.1' into 7.2
* 7.1: [Console] Fix division by 0 error [ErrorHandler] Fix error message with PHP 8.5 add test covering associated entities referenced by their primary key Add an experimental CI job for PHP 8.5 Fix change log to mentioned thrown exception [HttpClient] Always set CURLOPT_CUSTOMREQUEST to the correct HTTP method in CurlHttpClient evaluate access flags for properties with asymmetric visibility [Mime] Fix wrong PHPDoc in `FormDataPart` constructor
2 parents 3272170 + daccae6 commit b492be5

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
class AssociatedEntityDto
15+
{
16+
public $singleId;
17+
}

Tests/Validator/Constraints/UniqueEntityValidatorTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use Doctrine\Persistence\ObjectManager;
2222
use PHPUnit\Framework\MockObject\MockObject;
2323
use Symfony\Bridge\Doctrine\Tests\DoctrineTestHelper;
24+
use Symfony\Bridge\Doctrine\Tests\Fixtures\AssociatedEntityDto;
2425
use Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity;
2526
use Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity2;
2627
use Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity;
@@ -609,6 +610,40 @@ public function testAssociatedEntityWithNull()
609610
$this->assertNoViolation();
610611
}
611612

613+
public function testAssociatedEntityReferencedByPrimaryKey()
614+
{
615+
$this->registry = $this->createRegistryMock($this->em);
616+
$this->registry->expects($this->any())
617+
->method('getManagerForClass')
618+
->willReturn($this->em);
619+
$this->validator = $this->createValidator();
620+
$this->validator->initialize($this->context);
621+
622+
$entity = new SingleIntIdEntity(1, 'foo');
623+
$associated = new AssociationEntity();
624+
$associated->single = $entity;
625+
626+
$this->em->persist($entity);
627+
$this->em->persist($associated);
628+
$this->em->flush();
629+
630+
$dto = new AssociatedEntityDto();
631+
$dto->singleId = 1;
632+
633+
$this->validator->validate($dto, new UniqueEntity(
634+
fields: ['singleId' => 'single'],
635+
entityClass: AssociationEntity::class,
636+
));
637+
638+
$this->buildViolation('This value is already used.')
639+
->atPath('property.path.single')
640+
->setParameter('{{ value }}', 1)
641+
->setInvalidValue(1)
642+
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
643+
->setCause([$associated])
644+
->assertRaised();
645+
}
646+
612647
public function testValidateUniquenessWithArrayValue()
613648
{
614649
$repository = $this->createRepositoryMock(SingleIntIdEntity::class);

0 commit comments

Comments
 (0)