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:
  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
  • Loading branch information
fabpot committed May 31, 2024
2 parents 1b4d67d + 32483f6 commit d45e6d6
Show file tree
Hide file tree
Showing 479 changed files with 356 additions and 8,010 deletions.
1 change: 0 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@
/src/Symfony/Component/Translation/Bridge export-ignore
/src/Symfony/Component/Emoji/Resources/data/* linguist-generated=true
/src/Symfony/Component/Intl/Resources/data/*/* linguist-generated=true
/.git* export-ignore
80 changes: 0 additions & 80 deletions .github/sync-packages.php

This file was deleted.

7 changes: 0 additions & 7 deletions .github/workflows/package-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ jobs:
done
exit $ok
- name: Verify symfony/deprecation-contracts requirements
run: |
set +e
Expand Down Expand Up @@ -142,9 +141,3 @@ jobs:
done
exit $ok
- name: Verify subtree-splits are auto-closed
run: |
php .github/sync-packages.php
git add src/
git diff --staged --exit-code || (echo '::error::Please run "php .github/sync-packages.php".' && exit 1)
3 changes: 2 additions & 1 deletion src/Symfony/Bridge/Doctrine/.gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/Tests export-ignore
/phpunit.xml.dist export-ignore
/.git* export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
8 changes: 0 additions & 8 deletions src/Symfony/Bridge/Doctrine/.github/PULL_REQUEST_TEMPLATE.md

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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;

use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\Id;

#[Entity]
class SingleIntIdWithPrivateNameEntity
{
public function __construct(
#[Id, Column(type: 'integer')]
protected int $id,

#[Column(type: 'string', nullable: true)]
private ?string $name,
) {
}

public function getName(): ?string
{
return $this->name;
}

public function __toString(): string
{
return (string) $this->name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity;
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity;
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdStringWrapperNameEntity;
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdWithPrivateNameEntity;
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleStringIdEntity;
use Symfony\Bridge\Doctrine\Tests\Fixtures\Type\StringWrapper;
use Symfony\Bridge\Doctrine\Tests\Fixtures\Type\StringWrapperType;
Expand Down Expand Up @@ -90,12 +91,17 @@ protected function createRegistryMock($em = null)
return $registry;
}

protected function createRepositoryMock()
protected function createRepositoryMock(string $className)
{
return $this->getMockBuilder(MockableRepository::class)
$repositoryMock = $this->getMockBuilder(MockableRepository::class)
->disableOriginalConstructor()
->onlyMethods(['find', 'findAll', 'findOneBy', 'findBy', 'getClassName', 'findByCustom'])
->getMock();

$repositoryMock->method('getClassName')
->willReturn($className);

return $repositoryMock;
}

protected function createEntityManagerMock($repositoryMock)
Expand All @@ -109,6 +115,10 @@ protected function createEntityManagerMock($repositoryMock)
$classMetadata = $this->createMock(
class_exists(ClassMetadataInfo::class) ? ClassMetadataInfo::class : ClassMetadata::class
);
$classMetadata
->method('getName')
->willReturn($repositoryMock->getClassName())
;
$classMetadata
->expects($this->any())
->method('hasField')
Expand Down Expand Up @@ -138,6 +148,7 @@ private function createSchema($em)
$schemaTool = new SchemaTool($em);
$schemaTool->createSchema([
$em->getClassMetadata(SingleIntIdEntity::class),
$em->getClassMetadata(SingleIntIdWithPrivateNameEntity::class),
$em->getClassMetadata(SingleIntIdNoToStringEntity::class),
$em->getClassMetadata(DoubleNameEntity::class),
$em->getClassMetadata(DoubleNullableNameEntity::class),
Expand Down Expand Up @@ -194,6 +205,25 @@ public static function provideUniquenessConstraints(): iterable
yield 'Named arguments' => [new UniqueEntity(message: 'myMessage', fields: ['name'], em: 'foo')];
}

public function testValidateEntityWithPrivatePropertyAndProxyObject()
{
$entity = new SingleIntIdWithPrivateNameEntity(1, 'Foo');
$this->em->persist($entity);
$this->em->flush();

$this->em->clear();

// this will load a proxy object
$entity = $this->em->getReference(SingleIntIdWithPrivateNameEntity::class, 1);

$this->validator->validate($entity, new UniqueEntity([
'fields' => ['name'],
'em' => self::EM_NAME,
]));

$this->assertNoViolation();
}

/**
* @dataProvider provideConstraintsWithCustomErrorPath
*/
Expand Down Expand Up @@ -387,7 +417,7 @@ public function testValidateUniquenessWithValidCustomErrorPath()
*/
public function testValidateUniquenessUsingCustomRepositoryMethod(UniqueEntity $constraint)
{
$repository = $this->createRepositoryMock();
$repository = $this->createRepositoryMock(SingleIntIdEntity::class);
$repository->expects($this->once())
->method('findByCustom')
->willReturn([])
Expand All @@ -411,7 +441,7 @@ public function testValidateUniquenessWithUnrewoundArray(UniqueEntity $constrain
{
$entity = new SingleIntIdEntity(1, 'foo');

$repository = $this->createRepositoryMock();
$repository = $this->createRepositoryMock(SingleIntIdEntity::class);
$repository->expects($this->once())
->method('findByCustom')
->willReturnCallback(
Expand Down Expand Up @@ -459,7 +489,7 @@ public function testValidateResultTypes($entity1, $result)
'repositoryMethod' => 'findByCustom',
]);

$repository = $this->createRepositoryMock();
$repository = $this->createRepositoryMock($entity1::class);
$repository->expects($this->once())
->method('findByCustom')
->willReturn($result)
Expand Down Expand Up @@ -581,7 +611,7 @@ public function testAssociatedEntityWithNull()

public function testValidateUniquenessWithArrayValue()
{
$repository = $this->createRepositoryMock();
$repository = $this->createRepositoryMock(SingleIntIdEntity::class);
$this->repositoryFactory->setRepository($this->em, SingleIntIdEntity::class, $repository);

$constraint = new UniqueEntity([
Expand Down Expand Up @@ -662,7 +692,7 @@ public function testEntityManagerNullObject()

public function testValidateUniquenessOnNullResult()
{
$repository = $this->createRepositoryMock();
$repository = $this->createRepositoryMock(SingleIntIdEntity::class);
$repository
->method('find')
->willReturn(null)
Expand Down Expand Up @@ -850,7 +880,7 @@ public function testValidateUniquenessWithEmptyIterator($entity, $result)
'repositoryMethod' => 'findByCustom',
]);

$repository = $this->createRepositoryMock();
$repository = $this->createRepositoryMock($entity::class);
$repository->expects($this->once())
->method('findByCustom')
->willReturn($result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,9 @@ private function getFieldValues(mixed $object, ClassMetadata $class, array $fiel
throw new ConstraintDefinitionException(sprintf('The field "%s" is not a property of class "%s".', $fieldName, $objectClass));
}

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

return $fieldValues;
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Bridge/Monolog/.gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/Tests export-ignore
/phpunit.xml.dist export-ignore
/.git* export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
8 changes: 0 additions & 8 deletions src/Symfony/Bridge/Monolog/.github/PULL_REQUEST_TEMPLATE.md

This file was deleted.

This file was deleted.

3 changes: 2 additions & 1 deletion src/Symfony/Bridge/PhpUnit/.gitattributes
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/Tests export-ignore
/phpunit.xml.dist export-ignore
/.git* export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
Loading

0 comments on commit d45e6d6

Please sign in to comment.