Skip to content

Commit

Permalink
Merge branch '5.4' into 6.4
Browse files Browse the repository at this point in the history
* 5.4:
  [PropertyInfo] Update DoctrineExtractor for new DBAL 4 BIGINT type
  Update security.nl.xlf
  [Validator] IBAN Check digits should always between 2 and 98
  [Security] Populate translations for trans-unit 20
  add missing plural translation messages
  filter out empty HTTP header parts
  [String] Fix folded in compat mode
  Remove calls to `getMockForAbstractClass()`
  [ErrorHandler] Do not call xdebug_get_function_stack() with xdebug >= 3.0 when not in develop mode
  [Serializer] Fix type for missing property
  add test for JSON response with null as content
  [Filesystem] Fix dumpFile `stat failed` error hitting custom handler
  Remove calls to `TestCase::iniSet()` and calls to deprecated methods of `MockBuilder`
  [PhpUnitBridge] Fix `DeprecationErrorHandler` with PhpUnit 10
  • Loading branch information
fabpot committed May 17, 2024
2 parents ef00f27 + fe0fbd4 commit 04737c5
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 14 deletions.
10 changes: 10 additions & 0 deletions PropertyInfo/DoctrineExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Symfony\Bridge\Doctrine\PropertyInfo;

use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\BigIntType;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\AssociationMapping;
Expand Down Expand Up @@ -132,6 +133,15 @@ public function getTypes(string $class, string $property, array $context = []):
}

$nullable = $metadata instanceof ClassMetadata && $metadata->isNullable($property);

// DBAL 4 has a special fallback strategy for BINGINT (int -> string)
if (Types::BIGINT === $typeOfField && !method_exists(BigIntType::class, 'getName')) {
return [
new Type(Type::BUILTIN_TYPE_INT, $nullable),
new Type(Type::BUILTIN_TYPE_STRING, $nullable),
];
}

$enumType = null;
if (null !== $enumClass = self::getMappingValue($metadata->getFieldMapping($property), 'enumType') ?? null) {
$enumType = new Type(Type::BUILTIN_TYPE_OBJECT, $nullable, $enumClass);
Expand Down
21 changes: 21 additions & 0 deletions Tests/Fixtures/MockableRepository.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* 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\EntityRepository;

class MockableRepository extends EntityRepository
{
public function findByCustom()
{
}
}
10 changes: 9 additions & 1 deletion Tests/PropertyInfo/DoctrineExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Doctrine\Common\EventManager;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Schema\DefaultSchemaManagerFactory;
use Doctrine\DBAL\Types\BigIntType;
use Doctrine\DBAL\Types\Type as DBALType;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
Expand Down Expand Up @@ -143,10 +144,17 @@ public function testExtractEnum()

public static function typesProvider(): array
{
// DBAL 4 has a special fallback strategy for BINGINT (int -> string)
if (!method_exists(BigIntType::class, 'getName')) {
$expectedBingIntType = [new Type(Type::BUILTIN_TYPE_INT), new Type(Type::BUILTIN_TYPE_STRING)];
} else {
$expectedBingIntType = [new Type(Type::BUILTIN_TYPE_STRING)];
}

return [
['id', [new Type(Type::BUILTIN_TYPE_INT)]],
['guid', [new Type(Type::BUILTIN_TYPE_STRING)]],
['bigint', [new Type(Type::BUILTIN_TYPE_STRING)]],
['bigint', $expectedBingIntType],
['time', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateTime')]],
['timeImmutable', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateTimeImmutable')]],
['dateInterval', [new Type(Type::BUILTIN_TYPE_OBJECT, false, 'DateInterval')]],
Expand Down
9 changes: 3 additions & 6 deletions Tests/Security/User/EntityUserProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,14 +236,11 @@ private function getManager($em, $name = null)

private function getObjectManager($repository)
{
$em = $this->getMockBuilder(ObjectManager::class)
->onlyMethods(['getClassMetadata', 'getRepository'])
->getMockForAbstractClass();
$em->expects($this->any())
->method('getRepository')
$objectManager = $this->createMock(ObjectManager::class);
$objectManager->method('getRepository')
->willReturn($repository);

return $em;
return $objectManager;
}

private function createSchema($em)
Expand Down
11 changes: 4 additions & 7 deletions Tests/Validator/Constraints/UniqueEntityValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
use Symfony\Bridge\Doctrine\Tests\Fixtures\DoubleNameEntity;
use Symfony\Bridge\Doctrine\Tests\Fixtures\DoubleNullableNameEntity;
use Symfony\Bridge\Doctrine\Tests\Fixtures\Employee;
use Symfony\Bridge\Doctrine\Tests\Fixtures\MockableRepository;
use Symfony\Bridge\Doctrine\Tests\Fixtures\Person;
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdEntity;
use Symfony\Bridge\Doctrine\Tests\Fixtures\SingleIntIdNoToStringEntity;
Expand Down Expand Up @@ -85,14 +86,10 @@ protected function createRegistryMock($em = null)

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

return $repository;
->onlyMethods(['find', 'findAll', 'findOneBy', 'findBy', 'getClassName', 'findByCustom'])
->getMock();
}

protected function createEntityManagerMock($repositoryMock)
Expand Down

0 comments on commit 04737c5

Please sign in to comment.