Skip to content

Commit

Permalink
Merge pull request #349 from doctrine/3.3.x-merge-up-into-3.4.x_d9fwXgRs
Browse files Browse the repository at this point in the history
Merge release 3.3.1 into 3.4.x
  • Loading branch information
greg0ire authored Mar 1, 2024
2 parents f75d11b + b6fd1f1 commit 1878aac
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 16 deletions.
16 changes: 9 additions & 7 deletions .doctrine-project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,22 @@
"docsSlug": "doctrine-persistence",
"versions": [
{
"name": "3.3",
"branchName": "3.3.x",
"name": "3.4",
"branchName": "3.4.x",
"slug": "latest",
"upcoming": true
},
{
"name": "3.3",
"branchName": "3.3.x",
"slug": "3.3",
"current": true
},
{
"name": "3.2",
"branchName": "3.2.x",
"slug": "3.2",
"current": true,
"aliases": [
"current",
"stable"
]
"maintained": false
},
{
"name": "3.1",
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Doctrine Persistence

[![GitHub Actions][GA 3.2 image]][GA 3.2]
[![Code Coverage][Coverage 3.2 image]][CodeCov 3.2]
[![GitHub Actions][GA 3.3 image]][GA 3.3]
[![Code Coverage][Coverage 3.3 image]][CodeCov 3.3]

The Doctrine Persistence project is a library that provides common abstractions for object mapper persistence.

Expand All @@ -11,7 +11,7 @@ The Doctrine Persistence project is a library that provides common abstractions
* [Documentation](https://www.doctrine-project.org/projects/doctrine-persistence/en/latest/index.html)
* [Downloads](https://github.com/doctrine/persistence/releases)

[Coverage 3.2 image]: https://codecov.io/gh/doctrine/persistence/branch/3.2.x/graph/badge.svg
[CodeCov 3.2]: https://codecov.io/gh/doctrine/persistence/branch/3.2.x
[GA 3.2 image]: https://github.com/doctrine/persistence/workflows/Continuous%20Integration/badge.svg?branch=3.2.x
[GA 3.2]: https://github.com/doctrine/persistence/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A3.2.x
[Coverage 3.3 image]: https://codecov.io/gh/doctrine/persistence/branch/3.3.x/graph/badge.svg
[CodeCov 3.3]: https://codecov.io/gh/doctrine/persistence/branch/3.3.x
[GA 3.3 image]: https://github.com/doctrine/persistence/workflows/Continuous%20Integration/badge.svg?branch=3.3.x
[GA 3.3]: https://github.com/doctrine/persistence/actions?query=workflow%3A%22Continuous+Integration%22+branch%3A3.3.x
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
40 changes: 40 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,44 @@ public function __construct(ReflectionProperty $originalReflectionProperty, stri
$this->enumType = $enumType;
}

/**
* {@inheritDoc}
*
* @psalm-external-mutation-free
*/
public function getDeclaringClass(): ReflectionClass
{
return $this->originalReflectionProperty->getDeclaringClass();
}

/**
* {@inheritDoc}
*
* @psalm-external-mutation-free
*/
public function getName(): string
{
return $this->originalReflectionProperty->getName();
}

/**
* {@inheritDoc}
*
* @psalm-external-mutation-free
*/
public function getType(): ?ReflectionType
{
return $this->originalReflectionProperty->getType();
}

/**
* {@inheritDoc}
*/
public function getAttributes(?string $name = null, int $flags = 0): array
{
return $this->originalReflectionProperty->getAttributes($name, $flags);
}

/**
* {@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 1878aac

Please sign in to comment.