Skip to content

Commit c3bc920

Browse files
authored
Merge pull request #698 from phpDocumentor/fix/zero-string-expression
Fix allow zero as expression value.
2 parents 5a64f2b + 3f13982 commit c3bc920

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

src/phpDocumentor/Reflection/Php/Expression.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public static function generatePlaceholder(string $name): string
8787
/** @param array<string, Fqsen|Type> $parts */
8888
public function __construct(string $expression, array $parts = [])
8989
{
90-
Assert::notEmpty($expression);
90+
Assert::stringNotEmpty($expression);
9191
Assert::allIsInstanceOfAny($parts, [Fqsen::class, Type::class]);
9292

9393
$this->expression = $expression;

tests/integration/EnumTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function testEnumWithConstant(): void
6161

6262
$enum = $file->getEnums()['\MyNamespace\MyEnumWithConstant'];
6363
self::assertInstanceOf(Enum_::class, $enum);
64-
self::assertCount(1, $enum->getConstants());
64+
self::assertCount(2, $enum->getConstants());
6565
self::assertArrayHasKey('\MyNamespace\MyEnumWithConstant::MYCONST', $enum->getConstants());
6666
self::assertSame("'MyConstValue'", $enum->getConstants()['\MyNamespace\MyEnumWithConstant::MYCONST']->getValue());
6767
}

tests/integration/data/Enums/enumWithConstant.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,6 @@
77
enum MyEnumWithConstant
88
{
99
public const MYCONST = 'MyConstValue';
10+
11+
public const INT_CONST = 0;
1012
}

tests/unit/phpDocumentor/Reflection/Php/ExpressionTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313

1414
namespace phpDocumentor\Reflection\Php;
1515

16+
use Generator;
1617
use InvalidArgumentException;
1718
use phpDocumentor\Reflection\Fqsen;
1819
use PHPUnit\Framework\Attributes\CoversClass;
20+
use PHPUnit\Framework\Attributes\DataProvider;
1921
use PHPUnit\Framework\TestCase;
2022

2123
use function sprintf;
@@ -110,4 +112,21 @@ public function testOverridePartsWhenRenderingExpression(): void
110112

111113
self::assertSame(sprintf('This is an %s expression', $replacement), $result);
112114
}
115+
116+
#[DataProvider('expressionValues')]
117+
public function testExpressionTemplateCreation(string $expression): void
118+
{
119+
$actual = new Expression($expression, []);
120+
self::assertSame($expression, $actual->getExpression());
121+
}
122+
123+
/** @return Generator<string, array{expression: string} */
124+
public static function expressionValues(): Generator
125+
{
126+
$values = ['0', 'null', 'false'];
127+
128+
foreach ($values as $value) {
129+
yield $value => ['expression' => $value];
130+
}
131+
}
113132
}

0 commit comments

Comments
 (0)