Skip to content

Commit 7c84f13

Browse files
Try
1 parent 6271e66 commit 7c84f13

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

tests/Rules/Doctrine/ORM/EntityColumnRuleTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Carbon\Doctrine\CarbonType;
77
use Composer\InstalledVersions;
88
use Doctrine\DBAL\Types\Type;
9+
use Doctrine\DBAL\Types\Types;
910
use Iterator;
1011
use PHPStan\Doctrine\Driver\DriverDetector;
1112
use PHPStan\Rules\Rule;
@@ -18,11 +19,13 @@
1819
use PHPStan\Type\Doctrine\Descriptors\DateTimeType;
1920
use PHPStan\Type\Doctrine\Descriptors\DateType;
2021
use PHPStan\Type\Doctrine\Descriptors\DecimalType;
22+
use PHPStan\Type\Doctrine\Descriptors\EnumType;
2123
use PHPStan\Type\Doctrine\Descriptors\IntegerType;
2224
use PHPStan\Type\Doctrine\Descriptors\JsonType;
2325
use PHPStan\Type\Doctrine\Descriptors\Ramsey\UuidTypeDescriptor;
2426
use PHPStan\Type\Doctrine\Descriptors\ReflectionDescriptor;
2527
use PHPStan\Type\Doctrine\Descriptors\SimpleArrayType;
28+
use PHPStan\Type\Doctrine\Descriptors\SmallFloatType;
2629
use PHPStan\Type\Doctrine\Descriptors\StringType;
2730
use PHPStan\Type\Doctrine\ObjectMetadataResolver;
2831
use function array_unshift;
@@ -74,6 +77,7 @@ protected function getRule(): Rule
7477
new IntegerType(),
7578
new StringType(),
7679
new SimpleArrayType(),
80+
new EnumType(),
7781
new UuidTypeDescriptor(FakeTestingUuidType::class),
7882
new ReflectionDescriptor(CarbonImmutableType::class, $this->createReflectionProvider(), self::getContainer()),
7983
new ReflectionDescriptor(CarbonType::class, $this->createReflectionProvider(), self::getContainer()),
@@ -413,6 +417,20 @@ public function testEnumType(?string $objectManagerLoader): void
413417
]);
414418
}
415419

420+
/**
421+
* @dataProvider dataObjectManagerLoader
422+
*/
423+
public function testEnumValues(?string $objectManagerLoader): void
424+
{
425+
if (!defined('Types::ENUM')) {
426+
self::markTestSkipped('Test requires ENUM type.');
427+
}
428+
429+
$this->allowNullablePropertyForRequiredField = false;
430+
$this->objectManagerLoader = $objectManagerLoader;
431+
$this->analyse([__DIR__ . '/data-attributes/enum-values.php'], []);
432+
}
433+
416434
/**
417435
* @dataProvider dataObjectManagerLoader
418436
*/
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 string $type1;
13+
14+
/** @var 'a'|'b'|'c' */
15+
#[ORM\Column(type: "string", options: ['values' => ['a', 'b', 'c']])]
16+
public string $type2;
17+
18+
/** @var 'a'|'b' */
19+
#[ORM\Column(type: "string", options: ['values' => ['a', 'b', 'c']])]
20+
public string $type3;
21+
}

0 commit comments

Comments
 (0)