Skip to content

[DoctrineBridge] Fix UniqueEntityValidator for fields (simple_array, json, ONE_TO_MANY ,MANY_TO_MANY) #61129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 7.4
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
159 changes: 159 additions & 0 deletions src/Symfony/Bridge/Doctrine/Tests/Fixtures/AllTypesEntity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
<?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\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;

#[ORM\Entity(repositoryClass: AllTypesEntityRepository::class)]
class AllTypesEntity
{
#[ORM\Id]
#[ORM\Column(type: Types::STRING)]
public string $id;

#[ORM\Column(type: Types::SMALLINT)]
public int $smallint;

#[ORM\Column(type: Types::INTEGER)]
public int $integer;

#[ORM\Column(type: Types::BIGINT, options: ['unsigned' => true])]
public string $bigint;

#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2)]
public string $decimal;

#[ORM\Column(type: Types::SMALLFLOAT)]
public float $smallfloat;

#[ORM\Column(type: Types::FLOAT)]
public float $float;

#[ORM\Column(type: Types::STRING)]
public string $string;

#[ORM\Column(type: Types::ASCII_STRING)]
public string $asciiString;

#[ORM\Column(type: Types::TEXT)]
public string $text;

#[ORM\Column(type: Types::GUID)]
public string $guid;

#[ORM\Column(type: Types::ENUM)]
public EntityEnum $enum;

#[ORM\Column(type: Types::BINARY)]
public mixed $binaryAsResource;

#[ORM\Column(type: Types::BLOB)]
public mixed $blobAsResource;

#[ORM\Column(type: Types::BOOLEAN)]
public bool $boolean;

#[ORM\Column(type: Types::DATE_MUTABLE)]
public \DateTime $date;

#[ORM\Column(type: Types::DATE_IMMUTABLE)]
public \DateTimeImmutable $dateImmutable;

#[ORM\Column(type: Types::DATETIME_MUTABLE)]
public \DateTime $datetime;

#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
public \DateTimeImmutable $datetimeImmutable;

#[ORM\Column(type: Types::DATETIMETZ_MUTABLE)]
public \DateTime $datetimetz;

#[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE)]
public \DateTimeImmutable $datetimetzImmutable;

#[ORM\Column(type: Types::TIME_MUTABLE)]
public \DateTime $time;

#[ORM\Column(type: Types::TIME_IMMUTABLE)]
public \DateTimeImmutable $timeImmutable;

#[ORM\Column(type: Types::DATEINTERVAL)]
public \DateInterval $dateinterval;

#[ORM\ManyToOne(targetEntity: RelatedEntity::class)]
#[ORM\JoinColumn(name: 'many_to_one_id', referencedColumnName: 'id')]
public RelatedEntity $manyToOne;

#[ORM\OneToOne(targetEntity: RelatedEntity::class)]
#[ORM\JoinColumn(name: 'one_to_one_id', referencedColumnName: 'id')]
public RelatedEntity $oneToOne;

#[ORM\Column(type: Types::SIMPLE_ARRAY)]
public array $simpleArray;

#[ORM\Column(type: Types::JSON, nullable: true)]
public mixed $json = [];

#[ORM\OneToMany(targetEntity: RelatedEntity::class, mappedBy: 'allEntity')]
public Collection $oneToMany;

#[ORM\ManyToMany(targetEntity: RelatedEntity::class)]
#[ORM\JoinTable(name: 'allentity_related')]
public Collection $manyToMany;

public function __construct(RelatedEntity $related)
{
$this->id = '1';
$this->smallint = 1;
$this->integer = 42;
$this->bigint = PHP_INT_MAX;
$this->decimal = '1234.56';
$this->smallfloat = 1.23;
$this->float = 3.1415;
$this->string = 'Iñtërńâtiônàlizætiøn';
$this->asciiString = 'ASCII text';
$this->text = 'This is a large text block.';
$this->guid = '4bb4f8f5-ea8d-4000-abf7-bb5b07dc2322';
$this->enum = EntityEnum::VALUE;

$this->binaryAsResource = fopen('php://memory', 'r+');
fwrite($this->binaryAsResource, 'binary data');
rewind($this->binaryAsResource);

$this->blobAsResource = fopen('php://memory', 'r+');
fwrite($this->blobAsResource, 'blob data');
rewind($this->blobAsResource);

$this->boolean = true;
$this->date = new \DateTime('2025-01-01');
$this->dateImmutable = new \DateTimeImmutable('2025-01-01');
$this->datetime = new \DateTime('2025-01-01 12:34:56');
$this->datetimeImmutable = new \DateTimeImmutable('2025-01-01 12:34:56');
$this->datetimetz = new \DateTime('2025-01-01 12:00:00', new \DateTimeZone('UTC'));
$this->datetimetzImmutable = new \DateTimeImmutable('2025-01-01 12:34:56', new \DateTimeZone('UTC'));
$this->time = new \DateTime('12:34:56');
$this->timeImmutable = new \DateTimeImmutable('12:34:56');
$this->dateinterval = new \DateInterval('P2D');

$this->manyToOne = $related;
$this->oneToOne = $related;

$this->simpleArray = ['foo', 'bar'];
$this->json = ['key' => 'value', 'list' => [1, 2, 3]];

$this->oneToMany = new ArrayCollection([$related]);
$this->manyToMany = new ArrayCollection([$related]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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 AllTypesEntityRepository extends EntityRepository
{
public ?AllTypesEntity $result = null;

public function findByCustom(): ?AllTypesEntity
{
return $this->result;
}
}
17 changes: 17 additions & 0 deletions src/Symfony/Bridge/Doctrine/Tests/Fixtures/EntityEnum.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 <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;

enum EntityEnum: string
{
case VALUE = 'value';
}
26 changes: 26 additions & 0 deletions src/Symfony/Bridge/Doctrine/Tests/Fixtures/RelatedEntity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?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\Mapping as ORM;

#[ORM\Entity]
class RelatedEntity
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column(type: 'integer')]
public int $id;

#[ORM\Column(type: 'string', length: 255)]
public string $name = 'Related';
}
Loading
Loading