Skip to content

Commit c5b1fc4

Browse files
committed
Merge pull request #5 from moufmouf/master
Making sure a default value for a property or parameter can contain a non empty array.
2 parents aec54ea + 249ffb9 commit c5b1fc4

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/visitor/DefaultVisitor.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -224,18 +224,11 @@ public function visitProperty(PhpProperty $property) {
224224
}
225225

226226
protected function getPhpExport($value) {
227-
if (is_bool($value)) {
228-
return $value ? 'true' : 'false';
229-
}
230-
227+
// Simply to be sure a null value is displayed in lowercase.
231228
if (null === $value) {
232229
return 'null';
233230
}
234231

235-
if (is_array($value)) {
236-
return 'array()';
237-
}
238-
239232
return var_export($value, true);
240233
}
241234

tests/Visitor/DefaultVisitorTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use gossi\codegen\model\PhpFunction;
55
use gossi\codegen\model\PhpParameter;
6+
use gossi\codegen\model\PhpProperty;
67
use gossi\codegen\visitor\DefaultVisitor;
78
use gossi\codegen\model\PhpMethod;
89
use gossi\codegen\utils\Writer;
@@ -52,6 +53,17 @@ public function testVisitMethodWithCallable() {
5253
$this->assertEquals($this->getContent('callable_parameter.php'), $visitor->getContent());
5354
}
5455

56+
public function testDefaultNotEmptyArray() {
57+
$property = new PhpProperty('fooArray');
58+
$visitor = new DefaultVisitor();
59+
60+
$property->setDefaultValue(array("some value"));
61+
$visitor->visitProperty($property);
62+
63+
$this->assertContains("some value", $visitor->getContent());
64+
}
65+
66+
5567
/**
5668
*
5769
* @param string $filename

0 commit comments

Comments
 (0)