-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds metadata field type validation against Entity property type
- Loading branch information
1 parent
a2d2e17
commit 860b1ee
Showing
4 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
tests/Doctrine/Tests/ORM/Functional/Ticket/GH10661/GH10661Test.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?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; | ||
|
||
/** | ||
* @requires PHP >= 7.4 | ||
*/ | ||
final class GH10661Test extends OrmTestCase | ||
{ | ||
/** @var EntityManagerInterface */ | ||
private $em; | ||
|
||
/** @var SchemaValidator */ | ||
private $validator; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->em = $this->getTestEntityManager(); | ||
$this->validator = new SchemaValidator($this->em); | ||
} | ||
|
||
public function testMetadataFieldTypeNotCoherentWithEntityPropertyType(): void | ||
{ | ||
$class = $this->em->getClassMetadata(InvalidEntity::class); | ||
$ce = $this->validator->validateClass($class); | ||
|
||
self::assertEquals( | ||
["The field 'Doctrine\Tests\ORM\Functional\Ticket\GH10661\InvalidEntity#property1' has the property type 'int' that differs from the metadata field type 'bool'."], | ||
$ce | ||
); | ||
} | ||
|
||
public function testMetadataFieldTypeNotCoherentWithEntityPropertyTypeWithInheritance(): void | ||
{ | ||
$class = $this->em->getClassMetadata(InvalidChildEntity::class); | ||
$ce = $this->validator->validateClass($class); | ||
|
||
self::assertEquals( | ||
[ | ||
"The field 'Doctrine\Tests\ORM\Functional\Ticket\GH10661\InvalidChildEntity#property1' has the property type 'int' that differs from the metadata field type 'bool'.", | ||
"The field 'Doctrine\Tests\ORM\Functional\Ticket\GH10661\InvalidChildEntity#property2' has the property type 'int' that differs from the metadata field type 'string'.", | ||
"The field 'Doctrine\Tests\ORM\Functional\Ticket\GH10661\InvalidChildEntity#anotherProperty' has the property type 'string' that differs from the metadata field type 'bool'.", | ||
], | ||
$ce | ||
); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
tests/Doctrine/Tests/ORM/Functional/Ticket/GH10661/InvalidChildEntity.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket\GH10661; | ||
|
||
use Doctrine\ORM\Mapping\Column; | ||
use Doctrine\ORM\Mapping\Entity; | ||
|
||
/** @Entity */ | ||
class InvalidChildEntity extends InvalidEntity | ||
{ | ||
/** @Column(type="string") */ | ||
protected int $property2; | ||
|
||
/** | ||
* @Column(type="boolean") | ||
*/ | ||
private string $anotherProperty; | ||
} |
25 changes: 25 additions & 0 deletions
25
tests/Doctrine/Tests/ORM/Functional/Ticket/GH10661/InvalidEntity.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket\GH10661; | ||
|
||
use Doctrine\ORM\Mapping\Column; | ||
use Doctrine\ORM\Mapping\Entity; | ||
use Doctrine\ORM\Mapping\Id; | ||
|
||
/** @Entity */ | ||
class InvalidEntity | ||
{ | ||
/** | ||
* @var int | ||
* @Id | ||
* @Column | ||
*/ | ||
protected $key; | ||
|
||
/** | ||
* @Column(type="boolean") | ||
*/ | ||
protected int $property1; | ||
} |