Skip to content

Commit

Permalink
Merge pull request silverstripe#126 from unclecheese/pulls/1.0/defaul…
Browse files Browse the repository at this point in the history
…t-in-our-stars

BUGFIX: Prevent defaultValue from being added to args when null
  • Loading branch information
flamerohr authored Jan 15, 2018
2 parents 8dae954 + 8981b68 commit 4e75efe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Scaffolding/Scaffolders/ArgumentScaffolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,15 @@ public function applyConfig(array $config)
*/
public function toArray()
{
return [
$args = [
'description' => $this->description,
'type' => $this->required ? Type::nonNull($this->type) : $this->type,
'defaultValue' => $this->defaultValue
];

if ($this->defaultValue !== null) {
$args['defaultValue'] = $this->defaultValue;
}

return $args;
}
}
4 changes: 4 additions & 0 deletions tests/Scaffolding/Scaffolders/ArgumentScaffolderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,9 @@ public function testArgumentScaffolder()
$this->assertEquals('Bar', $arr['defaultValue']);
$this->assertInstanceOf(NonNull::class, $arr['type']);
$this->assertInstanceOf(StringType::class, $arr['type']->getWrappedType());

$scaffolder->setDefaultValue(null);
$arr = $scaffolder->toArray();
$this->assertArrayNotHasKey('defaultValue', $arr);
}
}

0 comments on commit 4e75efe

Please sign in to comment.