Skip to content

Commit 90677d1

Browse files
committed
fix #3 - ensure constant value is returned as it is defined
1 parent 0c07c20 commit 90677d1

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

Element/PhpConstant.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,12 @@ public function getChildrenTypes()
111111
{
112112
return array();
113113
}
114+
/**
115+
* Always return null to avoid having value being detected as a potential function/method/variable
116+
* @see \WsdlToPhp\PhpGenerator\Element\AbstractAssignedValueElement::getScalarValue()
117+
*/
118+
protected function getScalarValue($value)
119+
{
120+
return null;
121+
}
114122
}

Tests/Element/PhpConstantTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ public function testGetPhpDeclarationNumberOneValue()
4444
$this->assertSame('define(\'foo\', 1);', $constant->getPhpDeclaration());
4545
}
4646

47+
public function testGetPhpDeclarationParenthesisValue()
48+
{
49+
$constant = new PhpConstant('foo', 'NCSA Common (Apache default)');
50+
51+
$this->assertSame('define(\'foo\', \'NCSA Common (Apache default)\');', $constant->getPhpDeclaration());
52+
}
53+
4754
/**
4855
* @expectedException InvalidArgumentException
4956
*/
@@ -59,6 +66,13 @@ public function testGetPhpDeclarationNullValueForClass()
5966
$this->assertSame('const FOO = null;', $constant->getPhpDeclaration());
6067
}
6168

69+
public function testGetPhpDeclarationParenthesisValueForClass()
70+
{
71+
$constant = new PhpConstant('foo', 'NCSA Common (Apache default)', new PhpClass('bar'));
72+
73+
$this->assertSame('const FOO = \'NCSA Common (Apache default)\';', $constant->getPhpDeclaration());
74+
}
75+
6276
public function testGetPhpDeclarationTrueValueForClass()
6377
{
6478
$constant = new PhpConstant('foo', true, new PhpClass('Bar'));

0 commit comments

Comments
 (0)