Skip to content

Commit 13e4175

Browse files
Try
1 parent 6271e66 commit 13e4175

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

tests/Rules/Doctrine/ORM/EntityColumnRuleTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use PHPStan\Type\Doctrine\Descriptors\DateTimeType;
1919
use PHPStan\Type\Doctrine\Descriptors\DateType;
2020
use PHPStan\Type\Doctrine\Descriptors\DecimalType;
21+
use PHPStan\Type\Doctrine\Descriptors\EnumType;
2122
use PHPStan\Type\Doctrine\Descriptors\IntegerType;
2223
use PHPStan\Type\Doctrine\Descriptors\JsonType;
2324
use PHPStan\Type\Doctrine\Descriptors\Ramsey\UuidTypeDescriptor;
@@ -26,6 +27,7 @@
2627
use PHPStan\Type\Doctrine\Descriptors\StringType;
2728
use PHPStan\Type\Doctrine\ObjectMetadataResolver;
2829
use function array_unshift;
30+
use function defined;
2931
use function strpos;
3032
use const PHP_VERSION_ID;
3133

@@ -74,6 +76,7 @@ protected function getRule(): Rule
7476
new IntegerType(),
7577
new StringType(),
7678
new SimpleArrayType(),
79+
new EnumType(),
7780
new UuidTypeDescriptor(FakeTestingUuidType::class),
7881
new ReflectionDescriptor(CarbonImmutableType::class, $this->createReflectionProvider(), self::getContainer()),
7982
new ReflectionDescriptor(CarbonType::class, $this->createReflectionProvider(), self::getContainer()),
@@ -413,6 +416,20 @@ public function testEnumType(?string $objectManagerLoader): void
413416
]);
414417
}
415418

419+
/**
420+
* @dataProvider dataObjectManagerLoader
421+
*/
422+
public function testEnumValues(?string $objectManagerLoader): void
423+
{
424+
if (!defined('\Doctrine\DBAL\Types\Types::ENUM')) {
425+
self::markTestSkipped('Test requires ENUM type.');
426+
}
427+
428+
$this->allowNullablePropertyForRequiredField = false;
429+
$this->objectManagerLoader = $objectManagerLoader;
430+
$this->analyse([__DIR__ . '/data-attributes/enum-values.php'], []);
431+
}
432+
416433
/**
417434
* @dataProvider dataObjectManagerLoader
418435
*/
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
namespace PHPStan\Rules\Doctrine\ORMAttributes;
4+
5+
use Doctrine\ORM\Mapping as ORM;
6+
7+
#[ORM\Entity]
8+
class FooValues
9+
{
10+
/** @var string */
11+
#[ORM\Column(type: "string", options: ['values' => ['a', 'b', 'c']])]
12+
public $type1;
13+
14+
/** @var 'a'|'b'|'c' */
15+
#[ORM\Column(type: "string", options: ['values' => ['a', 'b', 'c']])]
16+
public $type2;
17+
18+
/** @var 'a'|'b' */
19+
#[ORM\Column(type: "string", options: ['values' => ['a', 'b', 'c']])]
20+
public $type3;
21+
}

0 commit comments

Comments
 (0)