-
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 and enumType validation against Entity prope…
…rty type
- Loading branch information
Showing
6 changed files
with
153 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
49 changes: 49 additions & 0 deletions
49
tests/Doctrine/Tests/ORM/Functional/Ticket/GH11037/GH11037Test.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,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket\GH11037; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use Doctrine\ORM\Tools\SchemaValidator; | ||
use Doctrine\Tests\OrmTestCase; | ||
|
||
/** | ||
* @requires PHP >= 8.1 | ||
*/ | ||
final class GH11037Test 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 testMetadataFieldTypeCoherentWithEntityPropertyType(): void | ||
{ | ||
$class = $this->em->getClassMetadata(ValidEntityWithTypedEnum::class); | ||
$ce = $this->validator->validateClass($class); | ||
|
||
self::assertEquals([], $ce); | ||
} | ||
|
||
public function testMetadataFieldTypeNotCoherentWithEntityPropertyType(): void | ||
{ | ||
$class = $this->em->getClassMetadata(InvalidEntityWithTypedEnum::class); | ||
$ce = $this->validator->validateClass($class); | ||
|
||
self::assertEquals( | ||
[ | ||
"The field 'Doctrine\Tests\ORM\Functional\Ticket\GH11037\InvalidEntityWithTypedEnum#status1' has the property type 'Doctrine\Tests\ORM\Functional\Ticket\GH11037\StringEntityStatus' that differs from the metadata field type 'int' returned by the 'integer' DBAL type.", | ||
"The field 'Doctrine\Tests\ORM\Functional\Ticket\GH11037\InvalidEntityWithTypedEnum#status2' has the property type 'Doctrine\Tests\ORM\Functional\Ticket\GH11037\IntEntityStatus' that differs from the metadata enumType 'Doctrine\Tests\ORM\Functional\Ticket\GH11037\StringEntityStatus'.", | ||
], | ||
$ce | ||
); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/Doctrine/Tests/ORM/Functional/Ticket/GH11037/IntEntityStatus.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,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket\GH11037; | ||
|
||
enum IntEntityStatus: int | ||
{ | ||
case ACTIVE = 0; | ||
case INACTIVE = 1; | ||
} |
31 changes: 31 additions & 0 deletions
31
tests/Doctrine/Tests/ORM/Functional/Ticket/GH11037/InvalidEntityWithTypedEnum.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,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket\GH11037; | ||
|
||
use Doctrine\ORM\Mapping\Column; | ||
use Doctrine\ORM\Mapping\Entity; | ||
use Doctrine\ORM\Mapping\Id; | ||
|
||
/** | ||
* @Entity | ||
*/ | ||
class InvalidEntityWithTypedEnum | ||
{ | ||
/** | ||
* @Id | ||
* @Column | ||
*/ | ||
protected int $id; | ||
|
||
/** | ||
* @Column(type="integer", enumType=StringEntityStatus::class) | ||
*/ | ||
protected StringEntityStatus $status1; | ||
|
||
/** | ||
* @Column(type="integer", enumType=StringEntityStatus::class) | ||
*/ | ||
protected IntEntityStatus $status2; | ||
} |
11 changes: 11 additions & 0 deletions
11
tests/Doctrine/Tests/ORM/Functional/Ticket/GH11037/StringEntityStatus.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,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket\GH11037; | ||
|
||
enum StringEntityStatus: string | ||
{ | ||
case ACTIVE = 'active'; | ||
case INACTIVE = 'inactive'; | ||
} |
31 changes: 31 additions & 0 deletions
31
tests/Doctrine/Tests/ORM/Functional/Ticket/GH11037/ValidEntityWithTypedEnum.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,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Tests\ORM\Functional\Ticket\GH11037; | ||
|
||
use Doctrine\ORM\Mapping\Column; | ||
use Doctrine\ORM\Mapping\Entity; | ||
use Doctrine\ORM\Mapping\Id; | ||
|
||
/** | ||
* @Entity | ||
*/ | ||
class ValidEntityWithTypedEnum | ||
{ | ||
/** | ||
* @Id | ||
* @Column | ||
*/ | ||
protected int $id; | ||
|
||
/** | ||
* @Column(type="string", enumType=StringEntityStatus::class) | ||
*/ | ||
protected StringEntityStatus $status1; | ||
|
||
/** | ||
* @Column(type="smallint", enumType=IntEntityStatus::class) | ||
*/ | ||
protected IntEntityStatus $status2; | ||
} |