Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/phpDocumentor/Reflection/Php/Factory/Define.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ private function determineFqsen(?Context $context, Arg $name) : Fqsen
$nameString = $name->value;
$namespace = $context ? $context->getNamespace() : '';

if (empty($namespace)) {
return new Fqsen(sprintf('\\%s', $nameString->value));
}

return new Fqsen(sprintf('\\%s\\%s', $namespace, $nameString->value));
}
}
3 changes: 3 additions & 0 deletions tests/integration/ClassesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public function testItHasAllConstants() : void
$constant = $class->getConstants()[$constantName];

$this->assertInstanceOf(Constant::class, $constant);

$this->assertArrayHasKey('\\OVEN_TEMPERATURE', $file->getConstants());
$this->assertArrayHasKey('\\MAX_OVEN_TEMPERATURE', $file->getConstants());
}

public function testTypedPropertiesReturnTheirType() : void
Expand Down
6 changes: 6 additions & 0 deletions tests/integration/data/Pizza.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@
* @link http://phpdoc.org
*/

/**
* This needs a docblock to separate from
* file docblock
*/
const OVEN_TEMPERATURE = 9001;
define('MAX_OVEN_TEMPERATURE', 9002);

/**
* Pizza base class
Expand Down
22 changes: 18 additions & 4 deletions tests/unit/phpDocumentor/Reflection/Php/Factory/DefineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,21 @@ public function testCreate() : void
new Context('Space\MyClass')
);

$this->assertConstant($constant);
$this->assertConstant($constant, '\\Space\\MyClass');
}

public function testCreateGlobal() : void
{
$constantStub = $this->buildDefineStub();

/** @var ConstantDescriptor $constant */
$constant = $this->fixture->create(
$constantStub,
new ProjectFactoryStrategies([]),
new Context('')
);

$this->assertConstant($constant, '');
}

public function testCreateWithDocBlock() : void
Expand Down Expand Up @@ -105,7 +119,7 @@ public function testCreateWithDocBlock() : void
$context
);

$this->assertConstant($constant);
$this->assertConstant($constant, '\\Space\\MyClass');
$this->assertSame($docBlock, $constant->getDocBlock());
}

Expand All @@ -122,10 +136,10 @@ private function buildDefineStub() : Expression
);
}

private function assertConstant(ConstantDescriptor $constant) : void
private function assertConstant(ConstantDescriptor $constant, string $namespace) : void
{
$this->assertInstanceOf(ConstantDescriptor::class, $constant);
$this->assertEquals('\Space\MyClass\MY_CONST1', (string) $constant->getFqsen());
$this->assertEquals($namespace . '\\MY_CONST1', (string) $constant->getFqsen());
$this->assertEquals('\'a\'', $constant->getValue());
$this->assertEquals('public', (string) $constant->getVisibility());
}
Expand Down