Skip to content

Commit

Permalink
Revert "Merge pull request #11399 from ThomasLandauer/issue-11377" (#…
Browse files Browse the repository at this point in the history
…11415)

This reverts commit cbb6c89, reversing
changes made to 9c56071.
  • Loading branch information
derrabus authored Apr 15, 2024
1 parent e0e55dc commit 9c22814
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 107 deletions.
29 changes: 3 additions & 26 deletions src/Tools/SchemaValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
use function in_array;
use function interface_exists;
use function is_a;
use function method_exists;
use function sprintf;

/**
Expand All @@ -50,29 +49,11 @@
class SchemaValidator
{
/**
* Map built-in Doctrine DBAL 3 types to PHP types
*/
private const BUILTIN_TYPES_MAP_DBAL3 = [
AsciiStringType::class => 'string',
BigIntType::class => 'string',
BooleanType::class => 'bool',
DecimalType::class => 'string',
FloatType::class => 'float',
GuidType::class => 'string',
IntegerType::class => 'int',
JsonType::class => 'array',
SimpleArrayType::class => 'array',
SmallIntType::class => 'int',
StringType::class => 'string',
TextType::class => 'string',
];

/**
* Map built-in Doctrine DBAL 4+ types to PHP types
* It maps built-in Doctrine types to PHP types
*/
private const BUILTIN_TYPES_MAP = [
AsciiStringType::class => 'string',
BigIntType::class => 'string|int',
BigIntType::class => 'string',
BooleanType::class => 'bool',
DecimalType::class => 'string',
FloatType::class => 'float',
Expand Down Expand Up @@ -455,10 +436,6 @@ private function findBuiltInType(Type $type): string|null
{
$typeName = $type::class;

if (method_exists(BigIntType::class, 'getName')) { // DBAL 3
return self::BUILTIN_TYPES_MAP_DBAL3[$typeName] ?? null;
} else { // DBAL 4+
return self::BUILTIN_TYPES_MAP[$typeName] ?? null;
}
return self::BUILTIN_TYPES_MAP[$typeName] ?? null;
}
}
81 changes: 0 additions & 81 deletions tests/Tests/ORM/Tools/SchemaValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@

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;
use Doctrine\ORM\Mapping\DiscriminatorMap;
Expand All @@ -32,8 +30,6 @@
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 @@ -232,47 +228,6 @@ public function testInvalidAssociationTowardsMappedSuperclass(): void
$ce,
);
}

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

$this->assertEquals([], $ce); // Same for DBAL 3 and 4+
}

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,
);
}
}
}

#[MappedSuperclass]
Expand Down Expand Up @@ -592,39 +547,3 @@ class InvalidMappedSuperClass
#[ManyToMany(targetEntity: 'InvalidMappedSuperClass', mappedBy: 'invalid')]
private $selfWhatever;
}

#[Entity]
class BigintMappedToStringInt
{
#[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 9c22814

Please sign in to comment.