Skip to content

Commit 93b2d73

Browse files
committed
[DoctrineBridge] Fix UniqueEntityValidator for fields (simple_array, json, ONE_TO_MANY ,MANY_TO_MANY)
1 parent f4ca886 commit 93b2d73

File tree

6 files changed

+438
-0
lines changed

6 files changed

+438
-0
lines changed
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
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+
use Doctrine\DBAL\Types\Types;
15+
use Doctrine\ORM\Mapping as ORM;
16+
use Doctrine\Common\Collections\ArrayCollection;
17+
use Doctrine\Common\Collections\Collection;
18+
19+
#[ORM\Entity(repositoryClass: AllTypesEntityRepository::class)]
20+
class AllTypesEntity
21+
{
22+
#[ORM\Id]
23+
#[ORM\Column(type: Types::STRING)]
24+
public string $id;
25+
26+
#[ORM\Column(type: Types::SMALLINT)]
27+
public int $smallint;
28+
29+
#[ORM\Column(type: Types::INTEGER)]
30+
public int $integer;
31+
32+
#[ORM\Column(type: Types::BIGINT, options: ['unsigned' => true])]
33+
public string $bigint;
34+
35+
#[ORM\Column(type: Types::DECIMAL, precision: 10, scale: 2)]
36+
public string $decimal;
37+
38+
#[ORM\Column(type: Types::SMALLFLOAT)]
39+
public float $smallfloat;
40+
41+
#[ORM\Column(type: Types::FLOAT)]
42+
public float $float;
43+
44+
#[ORM\Column(type: Types::STRING)]
45+
public string $string;
46+
47+
#[ORM\Column(type: Types::ASCII_STRING)]
48+
public string $asciiString;
49+
50+
#[ORM\Column(type: Types::TEXT)]
51+
public string $text;
52+
53+
#[ORM\Column(type: Types::GUID)]
54+
public string $guid;
55+
56+
#[ORM\Column(type: Types::ENUM)]
57+
public EntityEnum $enum;
58+
59+
#[ORM\Column(type: Types::BINARY)]
60+
public mixed $binaryAsResource;
61+
62+
#[ORM\Column(type: Types::BLOB)]
63+
public mixed $blobAsResource;
64+
65+
#[ORM\Column(type: Types::BOOLEAN)]
66+
public bool $boolean;
67+
68+
#[ORM\Column(type: Types::DATE_MUTABLE)]
69+
public \DateTime $date;
70+
71+
#[ORM\Column(type: Types::DATE_IMMUTABLE)]
72+
public \DateTimeImmutable $dateImmutable;
73+
74+
#[ORM\Column(type: Types::DATETIME_MUTABLE)]
75+
public \DateTime $datetime;
76+
77+
#[ORM\Column(type: Types::DATETIME_IMMUTABLE)]
78+
public \DateTimeImmutable $datetimeImmutable;
79+
80+
#[ORM\Column(type: Types::DATETIMETZ_MUTABLE)]
81+
public \DateTime $datetimetz;
82+
83+
#[ORM\Column(type: Types::DATETIMETZ_IMMUTABLE)]
84+
public \DateTimeImmutable $datetimetzImmutable;
85+
86+
#[ORM\Column(type: Types::TIME_MUTABLE)]
87+
public \DateTime $time;
88+
89+
#[ORM\Column(type: Types::TIME_IMMUTABLE)]
90+
public \DateTimeImmutable $timeImmutable;
91+
92+
#[ORM\Column(type: Types::DATEINTERVAL)]
93+
public \DateInterval $dateinterval;
94+
95+
#[ORM\ManyToOne(targetEntity: RelatedEntity::class)]
96+
#[ORM\JoinColumn(name: 'many_to_one_id', referencedColumnName: 'id')]
97+
public RelatedEntity $manyToOne;
98+
99+
#[ORM\OneToOne(targetEntity: RelatedEntity::class)]
100+
#[ORM\JoinColumn(name: 'one_to_one_id', referencedColumnName: 'id')]
101+
public RelatedEntity $oneToOne;
102+
103+
#[ORM\Column(type: Types::SIMPLE_ARRAY)]
104+
public array $simpleArray;
105+
106+
#[ORM\Column(type: Types::JSON, nullable: true)]
107+
public mixed $json = [];
108+
109+
#[ORM\OneToMany(targetEntity: RelatedEntity::class, mappedBy: 'allEntity')]
110+
public Collection $oneToMany;
111+
112+
#[ORM\ManyToMany(targetEntity: RelatedEntity::class)]
113+
#[ORM\JoinTable(name: 'allentity_related')]
114+
public Collection $manyToMany;
115+
116+
public function __construct(RelatedEntity $related)
117+
{
118+
$this->id = '1';
119+
$this->smallint = 1;
120+
$this->integer = 42;
121+
$this->bigint = PHP_INT_MAX;
122+
$this->decimal = '1234.56';
123+
$this->smallfloat = 1.23;
124+
$this->float = 3.1415;
125+
$this->string = 'Iñtërńâtiônàlizætiøn';
126+
$this->asciiString = 'ASCII text';
127+
$this->text = 'This is a large text block.';
128+
$this->guid = '4bb4f8f5-ea8d-4000-abf7-bb5b07dc2322';
129+
$this->enum = EntityEnum::VALUE;
130+
131+
$this->binaryAsResource = fopen('php://memory', 'r+');
132+
fwrite($this->binaryAsResource, 'binary data');
133+
rewind($this->binaryAsResource);
134+
135+
$this->blobAsResource = fopen('php://memory', 'r+');
136+
fwrite($this->blobAsResource, 'blob data');
137+
rewind($this->blobAsResource);
138+
139+
$this->boolean = true;
140+
$this->date = new \DateTime('2025-01-01');
141+
$this->dateImmutable = new \DateTimeImmutable('2025-01-01');
142+
$this->datetime = new \DateTime('2025-01-01 12:34:56');
143+
$this->datetimeImmutable = new \DateTimeImmutable('2025-01-01 12:34:56');
144+
$this->datetimetz = new \DateTime('2025-01-01 12:00:00', new \DateTimeZone('UTC'));
145+
$this->datetimetzImmutable = new \DateTimeImmutable('2025-01-01 12:34:56', new \DateTimeZone('UTC'));
146+
$this->time = new \DateTime('12:34:56');
147+
$this->timeImmutable = new \DateTimeImmutable('12:34:56');
148+
$this->dateinterval = new \DateInterval('P2D');
149+
150+
$this->manyToOne = $related;
151+
$this->oneToOne = $related;
152+
153+
$this->simpleArray = ['foo', 'bar'];
154+
$this->json = ['key' => 'value', 'list' => [1, 2, 3]];
155+
156+
$this->oneToMany = new ArrayCollection([$related]);
157+
$this->manyToMany = new ArrayCollection([$related]);
158+
}
159+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
use Doctrine\ORM\EntityRepository;
15+
16+
class AllTypesEntityRepository extends EntityRepository
17+
{
18+
public ?AllTypesEntity $result = null;
19+
20+
public function findByCustom(): ?AllTypesEntity
21+
{
22+
return $this->result;
23+
}
24+
}
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+
enum EntityEnum: string
15+
{
16+
case VALUE = 'value';
17+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
use Doctrine\ORM\Mapping as ORM;
15+
16+
#[ORM\Entity]
17+
class RelatedEntity
18+
{
19+
#[ORM\Id]
20+
#[ORM\GeneratedValue]
21+
#[ORM\Column(type: 'integer')]
22+
public int $id;
23+
24+
#[ORM\Column(type: 'string', length: 255)]
25+
public string $name = 'Related';
26+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy