-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from wol-soft/issue77_dynamicProperty
Fix creation of dynamic property for composed item validators on properties
- Loading branch information
Showing
7 changed files
with
125 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace PHPModelGenerator\Tests\Issues\Issue; | ||
|
||
use PHPModelGenerator\Model\GeneratorConfiguration; | ||
use PHPModelGenerator\Tests\Issues\AbstractIssueTest; | ||
|
||
class Issue77Test extends AbstractIssueTest | ||
{ | ||
public function testCompositionValidatorOnPropertyGeneratesNoDynamicProperty(): void | ||
{ | ||
$className = $this->generateClassFromFile('dynamicProperty.json', (new GeneratorConfiguration())->setImmutable(false)); | ||
|
||
$object = new $className(['values' => [1, 10, 1000], 'pet' => ['type' => 'dog', 'age' => 0, 'name' => 'Hans']]); | ||
|
||
$this->assertSame([1, 10, 1000], $object->getValues()); | ||
$this->assertSame('dog', $object->getPet()->getType()); | ||
$this->assertSame(0, $object->getPet()->getAge()); | ||
$this->assertSame('Hans', $object->getPet()->getName()); | ||
|
||
$this->expectExceptionMessage('Value for item of array values must not be smaller than 1'); | ||
|
||
new $className(['values' => [0]]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
{ | ||
"type": "object", | ||
"definitions": { | ||
"number": { | ||
"type": "integer", | ||
"minimum": 0, | ||
"maximum": 1000 | ||
}, | ||
"values": { | ||
"type": "array", | ||
"items": { | ||
"allOf": [ | ||
{ | ||
"$ref": "#/definitions/number" | ||
}, | ||
{ | ||
"type": "integer", | ||
"minimum": 1 | ||
} | ||
] | ||
} | ||
}, | ||
"pet": { | ||
"oneOf": [ | ||
{ | ||
"$ref": "#/definitions/pets/dog" | ||
}, | ||
{ | ||
"$ref": "#/definitions/pets/spider" | ||
} | ||
] | ||
}, | ||
"pets": { | ||
"dog": { | ||
"type": "object", | ||
"$id": "dog", | ||
"properties": { | ||
"age": { | ||
"$ref": "#/definitions/number" | ||
}, | ||
"name": { | ||
"type": "string" | ||
}, | ||
"type": { | ||
"const": "dog" | ||
} | ||
}, | ||
"required": [ | ||
"type" | ||
] | ||
}, | ||
"spider": { | ||
"type": "object", | ||
"properties": { | ||
"age": { | ||
"$ref": "#/definitions/number" | ||
}, | ||
"weight": { | ||
"type": "number" | ||
}, | ||
"type": { | ||
"const": "spider" | ||
} | ||
}, | ||
"required": [ | ||
"type" | ||
] | ||
} | ||
} | ||
}, | ||
"properties": { | ||
"values": { | ||
"$ref": "#/definitions/values" | ||
}, | ||
"pet": { | ||
"$ref": "#/definitions/pet" | ||
} | ||
} | ||
} |