Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasLandauer committed Mar 23, 2024
1 parent e44b245 commit c976c10
Showing 1 changed file with 69 additions and 3 deletions.
72 changes: 69 additions & 3 deletions tests/Tests/ORM/Tools/SchemaValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\BigIntType;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\Column;
Expand All @@ -31,6 +32,8 @@
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Group;

use function method_exists;

class SchemaValidatorTest extends OrmTestCase
{
private EntityManagerInterface|null $em = null;
Expand Down Expand Up @@ -234,8 +237,45 @@ public function testBigintMappedToStringInt(): void
{
$class = $this->em->getClassMetadata(BigintMappedToStringInt::class);
$ce = $this->validator->validateClass($class);

$this->assertEquals([], $ce);

if (method_exists(BigIntType::class, 'getName')) { // DBAL 3
$this->assertEquals([], $ce);
} else { // DBAL 4+
$this->assertEquals([], $ce);
}
}

public function testBigintMappedToInt(): void
{
$class = $this->em->getClassMetadata(BigintMappedToInt::class);
$ce = $this->validator->validateClass($class);

if (method_exists(BigIntType::class, 'getName')) { // DBAL 3
$this->assertEquals(
["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."],
$ce,
);
} else { // DBAL 4+
$this->assertEquals(
["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."],
$ce,
);
}
}

public function testBigintMappedToString(): void
{
$class = $this->em->getClassMetadata(BigintMappedToString::class);
$ce = $this->validator->validateClass($class);

if (method_exists(BigIntType::class, 'getName')) { // DBAL 3
$this->assertEquals([], $ce);
} else { // DBAL 4+
$this->assertEquals(
["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."],
$ce,
);
}
}
}

Expand Down Expand Up @@ -560,9 +600,35 @@ class InvalidMappedSuperClass
#[Entity]
class BigintMappedToStringInt
{
#[Id, Column, GeneratedValue]
#[Id]
#[Column]
#[GeneratedValue]
private int $id;

#[Column(type: Types::BIGINT)]
private string|int $bigint;
}

#[Entity]
class BigintMappedToInt
{
#[Id]
#[Column]
#[GeneratedValue]
private int $id;

#[Column(type: Types::BIGINT)]
private int $bigint;
}

#[Entity]
class BigintMappedToString
{
#[Id]
#[Column]
#[GeneratedValue]
private int $id;

#[Column(type: Types::BIGINT)]
private string $bigint;
}

0 comments on commit c976c10

Please sign in to comment.