|
6 | 6 |
|
7 | 7 | use Doctrine\Common\Collections\ArrayCollection; |
8 | 8 | use Doctrine\Common\Collections\Collection; |
| 9 | +use Doctrine\DBAL\Types\BigIntType; |
| 10 | +use Doctrine\DBAL\Types\Types; |
9 | 11 | use Doctrine\ORM\EntityManagerInterface; |
10 | 12 | use Doctrine\ORM\Mapping\Column; |
11 | 13 | use Doctrine\ORM\Mapping\DiscriminatorMap; |
|
30 | 32 | use PHPUnit\Framework\Attributes\DataProvider; |
31 | 33 | use PHPUnit\Framework\Attributes\Group; |
32 | 34 |
|
| 35 | +use function method_exists; |
| 36 | + |
33 | 37 | class SchemaValidatorTest extends OrmTestCase |
34 | 38 | { |
35 | 39 | private EntityManagerInterface|null $em = null; |
@@ -228,6 +232,47 @@ public function testInvalidAssociationTowardsMappedSuperclass(): void |
228 | 232 | $ce, |
229 | 233 | ); |
230 | 234 | } |
| 235 | + |
| 236 | + public function testBigintMappedToStringInt(): void |
| 237 | + { |
| 238 | + $class = $this->em->getClassMetadata(BigintMappedToStringInt::class); |
| 239 | + $ce = $this->validator->validateClass($class); |
| 240 | + |
| 241 | + $this->assertEquals([], $ce); // Same for DBAL 3 and 4+ |
| 242 | + } |
| 243 | + |
| 244 | + public function testBigintMappedToInt(): void |
| 245 | + { |
| 246 | + $class = $this->em->getClassMetadata(BigintMappedToInt::class); |
| 247 | + $ce = $this->validator->validateClass($class); |
| 248 | + |
| 249 | + if (method_exists(BigIntType::class, 'getName')) { // DBAL 3 |
| 250 | + $this->assertEquals( |
| 251 | + ["The field 'Doctrine\Tests\ORM\Tools\BigintMappedToInt#bigint' has the property type 'int' that differs from the metadata field type 'string' returned by the 'bigint' DBAL type."], |
| 252 | + $ce, |
| 253 | + ); |
| 254 | + } else { // DBAL 4+ |
| 255 | + $this->assertEquals( |
| 256 | + ["The field 'Doctrine\Tests\ORM\Tools\BigintMappedToInt#bigint' has the property type 'int' that differs from the metadata field type 'string|int' returned by the 'bigint' DBAL type."], |
| 257 | + $ce, |
| 258 | + ); |
| 259 | + } |
| 260 | + } |
| 261 | + |
| 262 | + public function testBigintMappedToString(): void |
| 263 | + { |
| 264 | + $class = $this->em->getClassMetadata(BigintMappedToString::class); |
| 265 | + $ce = $this->validator->validateClass($class); |
| 266 | + |
| 267 | + if (method_exists(BigIntType::class, 'getName')) { // DBAL 3 |
| 268 | + $this->assertEquals([], $ce); |
| 269 | + } else { // DBAL 4+ |
| 270 | + $this->assertEquals( |
| 271 | + ["The field 'Doctrine\Tests\ORM\Tools\BigintMappedToString#bigint' has the property type 'string' that differs from the metadata field type 'string|int' returned by the 'bigint' DBAL type."], |
| 272 | + $ce, |
| 273 | + ); |
| 274 | + } |
| 275 | + } |
231 | 276 | } |
232 | 277 |
|
233 | 278 | #[MappedSuperclass] |
@@ -547,3 +592,39 @@ class InvalidMappedSuperClass |
547 | 592 | #[ManyToMany(targetEntity: 'InvalidMappedSuperClass', mappedBy: 'invalid')] |
548 | 593 | private $selfWhatever; |
549 | 594 | } |
| 595 | + |
| 596 | +#[Entity] |
| 597 | +class BigintMappedToStringInt |
| 598 | +{ |
| 599 | + #[Id] |
| 600 | + #[Column] |
| 601 | + #[GeneratedValue] |
| 602 | + private int $id; |
| 603 | + |
| 604 | + #[Column(type: Types::BIGINT)] |
| 605 | + private string|int $bigint; |
| 606 | +} |
| 607 | + |
| 608 | +#[Entity] |
| 609 | +class BigintMappedToInt |
| 610 | +{ |
| 611 | + #[Id] |
| 612 | + #[Column] |
| 613 | + #[GeneratedValue] |
| 614 | + private int $id; |
| 615 | + |
| 616 | + #[Column(type: Types::BIGINT)] |
| 617 | + private int $bigint; |
| 618 | +} |
| 619 | + |
| 620 | +#[Entity] |
| 621 | +class BigintMappedToString |
| 622 | +{ |
| 623 | + #[Id] |
| 624 | + #[Column] |
| 625 | + #[GeneratedValue] |
| 626 | + private int $id; |
| 627 | + |
| 628 | + #[Column(type: Types::BIGINT)] |
| 629 | + private string $bigint; |
| 630 | +} |
0 commit comments