forked from loafle/openapi-generator-original
[PHP] Use parent constructor when inheriting
This commit is contained in:
@@ -114,6 +114,7 @@ class {{classname}} {{#parent}}extends {{{parent}}} {{/parent}}implements ArrayA
|
||||
*/
|
||||
public function __construct(array $data = null)
|
||||
{
|
||||
{{#parent}}parent::__construct($data);{{/parent}}
|
||||
if ($data != null) {
|
||||
{{#vars}}$this->{{name}} = $data["{{name}}"];{{#hasMore}}
|
||||
{{/hasMore}}{{/vars}}
|
||||
|
||||
@@ -1339,6 +1339,42 @@
|
||||
"xml": {
|
||||
"name": "Name"
|
||||
}
|
||||
},
|
||||
"Dog" : {
|
||||
"allOf" : [ {
|
||||
"$ref" : "#/definitions/Animal"
|
||||
}, {
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"breed" : {
|
||||
"type" : "string"
|
||||
}
|
||||
}
|
||||
} ]
|
||||
},
|
||||
"Cat" : {
|
||||
"allOf" : [ {
|
||||
"$ref" : "#/definitions/Animal"
|
||||
}, {
|
||||
"type" : "object",
|
||||
"properties" : {
|
||||
"declawed" : {
|
||||
"type" : "boolean"
|
||||
}
|
||||
}
|
||||
} ]
|
||||
},
|
||||
"Animal" : {
|
||||
"type" : "object",
|
||||
"discriminator": "className",
|
||||
"required": [
|
||||
"className"
|
||||
],
|
||||
"properties" : {
|
||||
"className" : {
|
||||
"type" : "string"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -375,6 +375,33 @@ class PetApiTest extends \PHPUnit_Framework_TestCase
|
||||
|
||||
}
|
||||
|
||||
// test inheritance in the model
|
||||
public function testInheritance()
|
||||
{
|
||||
$new_dog = new Swagger\Client\Model\Dog;
|
||||
// the object should be an instance of the derived class
|
||||
$this->assertInstanceOf('Swagger\Client\Model\Dog', $new_dog);
|
||||
// the object should also be an instance of the parent class
|
||||
$this->assertInstanceOf('Swagger\Client\Model\Animal', $new_dog);
|
||||
}
|
||||
|
||||
// test inheritance constructor is working with data
|
||||
// initialization
|
||||
public function testInheritanceConstructorDataInitialization()
|
||||
{
|
||||
// initialize the object with data in the constructor
|
||||
$data = array(
|
||||
'class_name' => 'Dog',
|
||||
'breed' => 'Great Dane'
|
||||
);
|
||||
$new_dog = new Swagger\Client\Model\Dog($data);
|
||||
|
||||
// the property on the derived class should be set
|
||||
$this->assertSame('Great Dane', $new_dog->getBreed());
|
||||
// the property on the parent class should be set
|
||||
$this->assertSame('Dog', $new_dog->getClassName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user