Skip to content

Commit f3cf462

Browse files
committed
Don't require a passed $modelData array, instead default to an empty array (which will be validated against the validation rules if no other value is provided)
1 parent 3abfeb6 commit f3cf462

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Templates/Model.phptpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class {{ class }} implements \PHPModelGenerator\Interfaces\JSONModelInterface
4242
* @throws {% if generatorConfiguration.collectErrors() %}{{ viewHelper.getSimpleClassName(generatorConfiguration.getErrorRegistryClass()) }}{% else %}{{ viewHelper.getSimpleClassName(generatorConfiguration.getExceptionClass()) }}{% endif %}
4343
*/
4444
public function __construct(
45-
array $modelData
45+
array $modelData = []
4646
{% if generatorConfiguration.collectErrors() %}
4747
{% if not initialClass %}
4848
, {{ viewHelper.getSimpleClassName(generatorConfiguration.getErrorRegistryClass()) }} $errorRegistry = null

tests/Basic/BasicSchemaGenerationTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ public function testImmutableGeneratorDoesntGenerateSetter(): void
4141
$this->assertNull($object->getProperty());
4242
}
4343

44+
public function testClassInstantiationWithoutParameter(): void
45+
{
46+
$className = $this->generateClassFromFile('BasicSchema.json');
47+
48+
$object = new $className();
49+
$this->assertNull($object->getProperty());
50+
51+
$object->setProperty('Hello');
52+
53+
$this->assertSame('Hello', $object->getProperty());
54+
55+
}
56+
4457
public function testReadOnlyPropertyDoesntGenerateSetter(): void
4558
{
4659
$className = $this->generateClassFromFile('ReadOnly.json');

0 commit comments

Comments
 (0)