Skip to content

Commit

Permalink
Merge branch '7.1' into 7.2
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
xabbuh committed Dec 7, 2024
2 parents 3272170 + daccae6 commit b492be5
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Tests/Fixtures/AssociatedEntityDto.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bridge\Doctrine\Tests\Fixtures;

class AssociatedEntityDto
{
public $singleId;
}
35 changes: 35 additions & 0 deletions Tests/Validator/Constraints/UniqueEntityValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Doctrine\Persistence\ObjectManager;
use PHPUnit\Framework\MockObject\MockObject;
use Symfony\Bridge\Doctrine\Tests\DoctrineTestHelper;
use Symfony\Bridge\Doctrine\Tests\Fixtures\AssociatedEntityDto;
use Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity;
use Symfony\Bridge\Doctrine\Tests\Fixtures\AssociationEntity2;
use Symfony\Bridge\Doctrine\Tests\Fixtures\CompositeIntIdEntity;
Expand Down Expand Up @@ -609,6 +610,40 @@ public function testAssociatedEntityWithNull()
$this->assertNoViolation();
}

public function testAssociatedEntityReferencedByPrimaryKey()
{
$this->registry = $this->createRegistryMock($this->em);
$this->registry->expects($this->any())
->method('getManagerForClass')
->willReturn($this->em);
$this->validator = $this->createValidator();
$this->validator->initialize($this->context);

$entity = new SingleIntIdEntity(1, 'foo');
$associated = new AssociationEntity();
$associated->single = $entity;

$this->em->persist($entity);
$this->em->persist($associated);
$this->em->flush();

$dto = new AssociatedEntityDto();
$dto->singleId = 1;

$this->validator->validate($dto, new UniqueEntity(
fields: ['singleId' => 'single'],
entityClass: AssociationEntity::class,
));

$this->buildViolation('This value is already used.')
->atPath('property.path.single')
->setParameter('{{ value }}', 1)
->setInvalidValue(1)
->setCode(UniqueEntity::NOT_UNIQUE_ERROR)
->setCause([$associated])
->assertRaised();
}

public function testValidateUniquenessWithArrayValue()
{
$repository = $this->createRepositoryMock(SingleIntIdEntity::class);
Expand Down

0 comments on commit b492be5

Please sign in to comment.