1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
<?php
declare(strict_types=1);
namespace Doctrine\Tests\ORM\Functional\Ticket\GH10661;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Tools\SchemaValidator;
use Doctrine\Tests\OrmTestCase;
use PHPUnit\Framework\Attributes\RequiresPhpunit;
#[RequiresPhpunit('< 12')]
final class GH10661Test extends OrmTestCase
{
/** @var EntityManagerInterface */
private $em;
protected function setUp(): void
{
$this->em = $this->getTestEntityManager();
}
public function testMetadataFieldTypeNotCoherentWithEntityPropertyType(): void
{
$class = $this->em->getClassMetadata(InvalidEntity::class);
$ce = $this->bootstrapValidator()->validateClass($class);
self::assertSame(
["The field 'Doctrine\Tests\ORM\Functional\Ticket\GH10661\InvalidEntity#property1' has the property type 'float' that differs from the metadata field type 'string' returned by the 'decimal' DBAL type."],
$ce,
);
}
public function testPropertyTypeErrorsCanBeSilenced(): void
{
$class = $this->em->getClassMetadata(InvalidEntity::class);
$ce = $this->bootstrapValidator(false)->validateClass($class);
self::assertSame([], $ce);
}
public function testMetadataFieldTypeNotCoherentWithEntityPropertyTypeWithInheritance(): void
{
$class = $this->em->getClassMetadata(InvalidChildEntity::class);
$ce = $this->bootstrapValidator()->validateClass($class);
self::assertSame(
[
"The field 'Doctrine\Tests\ORM\Functional\Ticket\GH10661\InvalidChildEntity#property1' has the property type 'float' that differs from the metadata field type 'string' returned by the 'decimal' DBAL type.",
"The field 'Doctrine\Tests\ORM\Functional\Ticket\GH10661\InvalidChildEntity#property2' has the property type 'int' that differs from the metadata field type 'string' returned by the 'string' DBAL type.",
"The field 'Doctrine\Tests\ORM\Functional\Ticket\GH10661\InvalidChildEntity#anotherProperty' has the property type 'string' that differs from the metadata field type 'bool' returned by the 'boolean' DBAL type.",
],
$ce,
);
}
private function bootstrapValidator(bool $validatePropertyTypes = true): SchemaValidator
{
return new SchemaValidator($this->em, $validatePropertyTypes);
}
}
|