forked from loafle/openapi-generator-original
[php-nextgen] add php-nextgen client generator (#16480)
* php-nextgen first commit * [php] Set minimal PHP version to ^8.0 (#14500) * Set minimal PHP version to ^8.0 * Fix php-nextgen config * Change stability to BETA * Add phplint package (#15054) * [php-nextgen] Rename folders to follow PDS skeleton (#15102) * Change lib -> src, test -> tests folder This will make build compliant to PHP-PDS skeleton. Ref: https://github.com/php-pds/skeleton * Refresh samples * Exclude composer.lock from codebase (#15105) Since client generator is library and not a project it makes sense to exclude composer.lock from codebase by default. Ref: http://getcomposer.org/doc/02-libraries.md#lock-file * Add @generated tag to DocBlocks (#15106) This tag in draft status right now(PSR-19), but I think we can leverage from it already. Ref: https://github.com/php-fig/fig-standards/blob/master/proposed/phpdoc-tags.md#55-generated * update samples, doc * update samples --------- Co-authored-by: Yuriy Belenko <yura-bely@mail.ru>
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace OpenAPI\Client;
|
||||
|
||||
use OpenAPI\Client\Model\Animal;
|
||||
use OpenAPI\Client\Model\Cat;
|
||||
use OpenAPI\Client\Model\Dog;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Test that Dog properly inherit Animal
|
||||
*
|
||||
* @package OpenAPI\Client
|
||||
*/
|
||||
class ModelInheritanceTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* test if default values works
|
||||
*/
|
||||
public function testDefaultValues()
|
||||
{
|
||||
// add some animals to the farm to make sure the ArrayAccess
|
||||
// interface works
|
||||
$dog = new Dog();
|
||||
$animal = new Animal();
|
||||
|
||||
// assert we can look up the animals in the farm by array
|
||||
// indices (let's try a random order)
|
||||
$this->assertSame('red', $dog->getColor());
|
||||
$this->assertSame('red', $animal->getColor());
|
||||
}
|
||||
|
||||
/**
|
||||
* test inheritance in the model
|
||||
*/
|
||||
public function testInheritance()
|
||||
{
|
||||
$newDog = new Dog;
|
||||
// the object should be an instance of the derived class
|
||||
$this->assertInstanceOf(Dog::class, $newDog);
|
||||
// the object should also be an instance of the parent class
|
||||
$this->assertInstanceOf(Animal::class, $newDog);
|
||||
}
|
||||
|
||||
/**
|
||||
* test inheritance constructor is working with data initialization
|
||||
*/
|
||||
public function testInheritanceConstructorDataInitialization()
|
||||
{
|
||||
// initialize the object with data in the constructor
|
||||
$data = [
|
||||
'class_name' => 'Dog',
|
||||
'breed' => 'Great Dane',
|
||||
];
|
||||
$newDog = new Dog($data);
|
||||
|
||||
// the property on the derived class should be set
|
||||
$this->assertSame('Great Dane', $newDog->getBreed());
|
||||
// the property on the parent class should be set
|
||||
$this->assertSame('Dog', $newDog->getClassName());
|
||||
}
|
||||
|
||||
/**
|
||||
* test if discriminator is initialized automatically
|
||||
*/
|
||||
public function testDiscriminatorInitialization()
|
||||
{
|
||||
$newDog = new Dog();
|
||||
$this->assertSame('Dog', $newDog->getClassName());
|
||||
}
|
||||
|
||||
/**
|
||||
* test if ArrayAccess interface works
|
||||
*/
|
||||
public function testArrayStuff()
|
||||
{
|
||||
// create an array of Animal
|
||||
$farm = array();
|
||||
|
||||
// add some animals to the farm to make sure the ArrayAccess interface works
|
||||
$farm[] = new Dog();
|
||||
$farm[] = new Cat();
|
||||
$farm[] = new Animal();
|
||||
|
||||
// assert we can look up the animals in the farm by array indices (let's try a random order)
|
||||
$this->assertInstanceOf(Cat::class, $farm[1]);
|
||||
$this->assertInstanceOf(Dog::class, $farm[0]);
|
||||
$this->assertInstanceOf(Animal::class, $farm[2]);
|
||||
|
||||
// let's try to `foreach` the animals in the farm and let's try to use the objects we loop through
|
||||
foreach ($farm as $animal) {
|
||||
$this->assertContains($animal->getClassName(), ['Dog', 'Cat', 'Animal']);
|
||||
$this->assertInstanceOf('OpenAPI\Client\Model\Animal', $animal);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user