File: GH10661Test.php

package info (click to toggle)
doctrine 3.5.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 11,552 kB
  • sloc: php: 108,302; xml: 1,340; makefile: 35; sh: 14
file content (61 lines) | stat: -rw-r--r-- 2,430 bytes parent folder | download | duplicates (3)
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);
    }
}