From 3f1398259a48b75793aebcc4bf63afbbdfa59900 Mon Sep 17 00:00:00 2001 From: Jaapio Date: Wed, 12 Nov 2025 22:41:19 +0100 Subject: [PATCH] Fix allow zero as expression value. --- .../Reflection/Php/Expression.php | 2 +- tests/integration/EnumTest.php | 2 +- .../data/Enums/enumWithConstant.php | 2 ++ .../Reflection/Php/ExpressionTest.php | 19 +++++++++++++++++++ 4 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/phpDocumentor/Reflection/Php/Expression.php b/src/phpDocumentor/Reflection/Php/Expression.php index d1a253cf..d1e12d41 100644 --- a/src/phpDocumentor/Reflection/Php/Expression.php +++ b/src/phpDocumentor/Reflection/Php/Expression.php @@ -87,7 +87,7 @@ public static function generatePlaceholder(string $name): string /** @param array $parts */ public function __construct(string $expression, array $parts = []) { - Assert::notEmpty($expression); + Assert::stringNotEmpty($expression); Assert::allIsInstanceOfAny($parts, [Fqsen::class, Type::class]); $this->expression = $expression; diff --git a/tests/integration/EnumTest.php b/tests/integration/EnumTest.php index 8d42d1e4..03e2c30f 100644 --- a/tests/integration/EnumTest.php +++ b/tests/integration/EnumTest.php @@ -61,7 +61,7 @@ public function testEnumWithConstant(): void $enum = $file->getEnums()['\MyNamespace\MyEnumWithConstant']; self::assertInstanceOf(Enum_::class, $enum); - self::assertCount(1, $enum->getConstants()); + self::assertCount(2, $enum->getConstants()); self::assertArrayHasKey('\MyNamespace\MyEnumWithConstant::MYCONST', $enum->getConstants()); self::assertSame("'MyConstValue'", $enum->getConstants()['\MyNamespace\MyEnumWithConstant::MYCONST']->getValue()); } diff --git a/tests/integration/data/Enums/enumWithConstant.php b/tests/integration/data/Enums/enumWithConstant.php index 9df17bb8..9da1f97a 100644 --- a/tests/integration/data/Enums/enumWithConstant.php +++ b/tests/integration/data/Enums/enumWithConstant.php @@ -7,4 +7,6 @@ enum MyEnumWithConstant { public const MYCONST = 'MyConstValue'; + + public const INT_CONST = 0; } diff --git a/tests/unit/phpDocumentor/Reflection/Php/ExpressionTest.php b/tests/unit/phpDocumentor/Reflection/Php/ExpressionTest.php index 48b65702..ac7f6b9c 100644 --- a/tests/unit/phpDocumentor/Reflection/Php/ExpressionTest.php +++ b/tests/unit/phpDocumentor/Reflection/Php/ExpressionTest.php @@ -13,9 +13,11 @@ namespace phpDocumentor\Reflection\Php; +use Generator; use InvalidArgumentException; use phpDocumentor\Reflection\Fqsen; use PHPUnit\Framework\Attributes\CoversClass; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use function sprintf; @@ -110,4 +112,21 @@ public function testOverridePartsWhenRenderingExpression(): void self::assertSame(sprintf('This is an %s expression', $replacement), $result); } + + #[DataProvider('expressionValues')] + public function testExpressionTemplateCreation(string $expression): void + { + $actual = new Expression($expression, []); + self::assertSame($expression, $actual->getExpression()); + } + + /** @return Generator ['expression' => $value]; + } + } }