Skip to content

Commit 447dd6b

Browse files
committed
added ConstantsAware::getConstant()
1 parent bcb74f3 commit 447dd6b

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/PhpGenerator/Traits/ConstantsAware.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ public function getConstants(): array
4242
}
4343

4444

45+
public function getConstant(string $name): Constant
46+
{
47+
return $this->consts[$name] ?? throw new Nette\InvalidArgumentException("Constant '$name' not found.");
48+
}
49+
50+
4551
public function addConstant(string $name, mixed $value): Constant
4652
{
4753
if (isset($this->consts[$name])) {

tests/PhpGenerator/ClassType.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ Assert::true($class->isAbstract());
4848
Assert::same('ParentClass', $class->getExtends());
4949
Assert::same(['ObjectTrait' => $trait1, 'AnotherTrait' => $trait2], $class->getTraits());
5050
Assert::count(2, $class->getConstants());
51-
Assert::type(Nette\PhpGenerator\Constant::class, $class->getConstants()['ROLE']);
51+
Assert::type(Nette\PhpGenerator\Constant::class, $class->getConstant('ROLE'));
5252

5353
$class->addConstant('FORCE_ARRAY', new Literal('Nette\Utils\Json::FORCE_ARRAY'))
5454
->setVisibility('private')

0 commit comments

Comments
 (0)