Skip to content

Add test about enum values #673

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions tests/Rules/Doctrine/ORM/EntityColumnRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use PHPStan\Type\Doctrine\Descriptors\DateTimeType;
use PHPStan\Type\Doctrine\Descriptors\DateType;
use PHPStan\Type\Doctrine\Descriptors\DecimalType;
use PHPStan\Type\Doctrine\Descriptors\EnumType;
use PHPStan\Type\Doctrine\Descriptors\IntegerType;
use PHPStan\Type\Doctrine\Descriptors\JsonType;
use PHPStan\Type\Doctrine\Descriptors\Ramsey\UuidTypeDescriptor;
Expand All @@ -26,6 +27,7 @@
use PHPStan\Type\Doctrine\Descriptors\StringType;
use PHPStan\Type\Doctrine\ObjectMetadataResolver;
use function array_unshift;
use function defined;
use function strpos;
use const PHP_VERSION_ID;

Expand Down Expand Up @@ -74,6 +76,7 @@ protected function getRule(): Rule
new IntegerType(),
new StringType(),
new SimpleArrayType(),
new EnumType(),
new UuidTypeDescriptor(FakeTestingUuidType::class),
new ReflectionDescriptor(CarbonImmutableType::class, $this->createReflectionProvider(), self::getContainer()),
new ReflectionDescriptor(CarbonType::class, $this->createReflectionProvider(), self::getContainer()),
Expand Down Expand Up @@ -413,6 +416,20 @@ public function testEnumType(?string $objectManagerLoader): void
]);
}

/**
* @dataProvider dataObjectManagerLoader
*/
public function testEnumValues(?string $objectManagerLoader): void
{
if (!defined('\Doctrine\DBAL\Types\Types::ENUM')) {
self::markTestSkipped('Test requires ENUM type.');
}

$this->allowNullablePropertyForRequiredField = false;
$this->objectManagerLoader = $objectManagerLoader;
$this->analyse([__DIR__ . '/data-attributes/enum-values.php'], []);
}

/**
* @dataProvider dataObjectManagerLoader
*/
Expand Down
21 changes: 21 additions & 0 deletions tests/Rules/Doctrine/ORM/data-attributes/enum-values.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace PHPStan\Rules\Doctrine\ORMAttributes;

use Doctrine\ORM\Mapping as ORM;

#[ORM\Entity]
class FooValues
{
/** @var string */
#[ORM\Column(type: "string", options: ['values' => ['a', 'b', 'c']])]
public $type1;

/** @var 'a'|'b'|'c' */
#[ORM\Column(type: "string", options: ['values' => ['a', 'b', 'c']])]
public $type2;

/** @var 'a'|'b' */
#[ORM\Column(type: "string", options: ['values' => ['a', 'b', 'c']])]
public $type3;
}
Loading