Skip to content

Commit

Permalink
Add missing proxy methods
Browse files Browse the repository at this point in the history
I somehow thought I had a green build for the ORM after e70bc39, but I
really didn't.
  • Loading branch information
greg0ire committed Mar 1, 2024
1 parent f75d11b commit 139c0e0
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 3 deletions.
10 changes: 10 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ parameters:
count: 1
path: src/Persistence/Reflection/EnumReflectionProperty.php

-
message: "#^Method Doctrine\\\\Persistence\\\\Reflection\\\\EnumReflectionProperty\\:\\:getDeclaringClass\\(\\) return type with generic class ReflectionClass does not specify its types\\: T$#"
count: 1
path: src/Persistence/Reflection/EnumReflectionProperty.php

-
message: "#^Method Doctrine\\\\Persistence\\\\Reflection\\\\EnumReflectionProperty\\:\\:getType\\(\\) should return ReflectionNamedType\\|ReflectionUnionType\\|null but returns ReflectionType\\|null\\.$#"
count: 1
path: src/Persistence/Reflection/EnumReflectionProperty.php

-
message: "#^Method Doctrine\\\\Persistence\\\\Reflection\\\\EnumReflectionProperty\\:\\:toEnum\\(\\) should return array\\<BackedEnum\\>\\|BackedEnum but returns array\\<BackedEnum\\|int\\|string\\>\\.$#"
count: 1
Expand Down
38 changes: 38 additions & 0 deletions src/Persistence/Reflection/EnumReflectionProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
namespace Doctrine\Persistence\Reflection;

use BackedEnum;
use ReflectionClass;
use ReflectionProperty;
use ReflectionType;
use ReturnTypeWillChange;

use function array_map;
Expand All @@ -30,6 +32,42 @@ public function __construct(ReflectionProperty $originalReflectionProperty, stri
$this->enumType = $enumType;
}

/**
* {@inheritDoc}
*
* @psalm-immutable
*/
public function getDeclaringClass(): ReflectionClass

Check failure on line 40 in src/Persistence/Reflection/EnumReflectionProperty.php

View workflow job for this annotation

GitHub Actions / Static Analysis / Psalm (8.2)

MissingImmutableAnnotation

src/Persistence/Reflection/EnumReflectionProperty.php:40:5: MissingImmutableAnnotation: ReflectionProperty::getDeclaringClass is marked @psalm-immutable, but Doctrine\Persistence\Reflection\EnumReflectionProperty::getDeclaringClass is not marked @psalm-immutable (see https://psalm.dev/213)
{

Check warning on line 41 in src/Persistence/Reflection/EnumReflectionProperty.php

View check run for this annotation

Codecov / codecov/patch

src/Persistence/Reflection/EnumReflectionProperty.php#L41

Added line #L41 was not covered by tests
return $this->originalReflectionProperty->getDeclaringClass();
}

Check warning on line 43 in src/Persistence/Reflection/EnumReflectionProperty.php

View check run for this annotation

Codecov / codecov/patch

src/Persistence/Reflection/EnumReflectionProperty.php#L43

Added line #L43 was not covered by tests

/**
* {@inheritDoc}
*
* @psalm-immutable
*/
public function getName(): string

Check failure on line 50 in src/Persistence/Reflection/EnumReflectionProperty.php

View workflow job for this annotation

GitHub Actions / Static Analysis / Psalm (8.2)

MissingImmutableAnnotation

src/Persistence/Reflection/EnumReflectionProperty.php:50:5: MissingImmutableAnnotation: ReflectionProperty::getName is marked @psalm-immutable, but Doctrine\Persistence\Reflection\EnumReflectionProperty::getName is not marked @psalm-immutable (see https://psalm.dev/213)
{

Check warning on line 51 in src/Persistence/Reflection/EnumReflectionProperty.php

View check run for this annotation

Codecov / codecov/patch

src/Persistence/Reflection/EnumReflectionProperty.php#L51

Added line #L51 was not covered by tests
return $this->originalReflectionProperty->getName();
}

Check warning on line 53 in src/Persistence/Reflection/EnumReflectionProperty.php

View check run for this annotation

Codecov / codecov/patch

src/Persistence/Reflection/EnumReflectionProperty.php#L53

Added line #L53 was not covered by tests

/**
* {@inheritDoc}
*
* @psalm-immutable
*/
public function getType(): ?ReflectionType

Check failure on line 60 in src/Persistence/Reflection/EnumReflectionProperty.php

View workflow job for this annotation

GitHub Actions / Static Analysis / Psalm (8.2)

MissingImmutableAnnotation

src/Persistence/Reflection/EnumReflectionProperty.php:60:5: MissingImmutableAnnotation: ReflectionProperty::getType is marked @psalm-immutable, but Doctrine\Persistence\Reflection\EnumReflectionProperty::getType is not marked @psalm-immutable (see https://psalm.dev/213)
{

Check warning on line 61 in src/Persistence/Reflection/EnumReflectionProperty.php

View check run for this annotation

Codecov / codecov/patch

src/Persistence/Reflection/EnumReflectionProperty.php#L61

Added line #L61 was not covered by tests
return $this->originalReflectionProperty->getType();
}

Check warning on line 63 in src/Persistence/Reflection/EnumReflectionProperty.php

View check run for this annotation

Codecov / codecov/patch

src/Persistence/Reflection/EnumReflectionProperty.php#L63

Added line #L63 was not covered by tests

/** @psalm-immutable */
public function getAttributes(?string $name = null, int $flags = 0): array

Check failure on line 66 in src/Persistence/Reflection/EnumReflectionProperty.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.2)

Method \Doctrine\Persistence\Reflection\EnumReflectionProperty::getAttributes() does not have @return annotation for its traversable return value.
{

Check warning on line 67 in src/Persistence/Reflection/EnumReflectionProperty.php

View check run for this annotation

Codecov / codecov/patch

src/Persistence/Reflection/EnumReflectionProperty.php#L67

Added line #L67 was not covered by tests
return $this->originalReflectionProperty->getAttributes($name, $flags);
}

Check warning on line 69 in src/Persistence/Reflection/EnumReflectionProperty.php

View check run for this annotation

Codecov / codecov/patch

src/Persistence/Reflection/EnumReflectionProperty.php#L69

Added line #L69 was not covered by tests

/**
* {@inheritDoc}
*
Expand Down
43 changes: 40 additions & 3 deletions tests_php81/Persistence/Reflection/EnumReflectionPropertyTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests_PHP81\Persistence\Reflection;

use Attribute;
use Doctrine\Persistence\Reflection\EnumReflectionProperty;
use PHPUnit\Framework\TestCase;
use ReflectionNamedType;
use ReflectionProperty;
use ValueError;

Expand All @@ -20,6 +24,33 @@ public function testGetValue(): void
self::assertNull($reflProperty->getValue($object));
}

public function testGetDeclaringClass(): void
{
$reflProperty = new EnumReflectionProperty(new ReflectionProperty(TypedEnumClass::class, 'suit'), Suit::class);
self::assertSame(TypedEnumClass::class, $reflProperty->getDeclaringClass()->getName());
}

public function testGetName(): void
{
$reflProperty = new EnumReflectionProperty(new ReflectionProperty(TypedEnumClass::class, 'suit'), Suit::class);
self::assertSame('suit', $reflProperty->getName());
}

public function testGetType(): void
{
$reflProperty = new EnumReflectionProperty(new ReflectionProperty(TypedEnumClass::class, 'suit'), Suit::class);
$type = $reflProperty->getType();
self::assertInstanceOf(ReflectionNamedType::class, $type);
self::assertSame(Suit::class, $type->getName());
}

public function testGetAttributes(): void
{
$reflProperty = new EnumReflectionProperty(new ReflectionProperty(TypedEnumClass::class, 'suit'), Suit::class);
self::assertCount(1, $reflProperty->getAttributes());
self::assertSame(MyAttribute::class, $reflProperty->getAttributes()[0]->getName());
}

public function testSetValidValue(): void
{
$object = new TypedEnumClass();
Expand Down Expand Up @@ -84,17 +115,23 @@ public function testSetEnumArray(): void
}
}

#[Attribute(Attribute::TARGET_PROPERTY)]
class MyAttribute
{
}

class TypedEnumClass
{
#[MyAttribute]
public ?Suit $suit = null;

public ?array $suits = null;
}

enum Suit: string
{
case Hearts = 'H';
case Hearts = 'H';
case Diamonds = 'D';
case Clubs = 'C';
case Spades = 'S';
case Clubs = 'C';
case Spades = 'S';
}

0 comments on commit 139c0e0

Please sign in to comment.