[PHP] Cleanup AnimalFarmTest (#7279)

* Move test codes in "test" to "tests"

* Regenerate test/Model/AnimalFarmTest.php
This commit is contained in:
Akihito Nakano 2018-01-07 12:21:53 +09:00 committed by William Cheng
parent 4bb6d8993c
commit fa3e72e6e3
2 changed files with 102 additions and 98 deletions

View File

@ -6,8 +6,7 @@
*
* @category Class
* @package Swagger\Client
* @author http://github.com/swagger-api/swagger-codegen
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License v2
* @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen
*/
@ -19,18 +18,7 @@
* OpenAPI spec version: 1.0.0
* Contact: apiteam@swagger.io
* Generated by: https://github.com/swagger-api/swagger-codegen.git
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Swagger Codegen version: 2.3.0-SNAPSHOT
*/
/**
@ -44,11 +32,11 @@ namespace Swagger\Client;
/**
* AnimalFarmTest Class Doc Comment
*
* @category Class
* @description AnimalFarm
* @category Class */
// * @description AnimalFarm
/**
* @package Swagger\Client
* @author http://github.com/swagger-api/swagger-codegen
* @license http://www.apache.org/licenses/LICENSE-2.0 Apache License v2
* @author Swagger Codegen team
* @link https://github.com/swagger-api/swagger-codegen
*/
class AnimalFarmTest extends \PHPUnit_Framework_TestCase
@ -59,7 +47,6 @@ class AnimalFarmTest extends \PHPUnit_Framework_TestCase
*/
public static function setUpBeforeClass()
{
}
/**
@ -67,7 +54,6 @@ class AnimalFarmTest extends \PHPUnit_Framework_TestCase
*/
public function setUp()
{
}
/**
@ -75,7 +61,6 @@ class AnimalFarmTest extends \PHPUnit_Framework_TestCase
*/
public function tearDown()
{
}
/**
@ -83,7 +68,6 @@ class AnimalFarmTest extends \PHPUnit_Framework_TestCase
*/
public static function tearDownAfterClass()
{
}
/**
@ -91,81 +75,5 @@ class AnimalFarmTest extends \PHPUnit_Framework_TestCase
*/
public function testAnimalFarm()
{
}
// test if default values works
public function testDefaultValues()
{
// add some animals to the farm to make sure the ArrayAccess
// interface works
$dog = new Model\Dog();
$animal = new Model\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()
{
$new_dog = new 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 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());
}
// test if discriminator is initialized automatically
public function testDiscriminatorInitialization()
{
$new_dog = new Model\Dog();
$this->assertSame('Dog', $new_dog->getClassName());
}
// test if ArrayAccess interface works
public function testArrayStuff()
{
// create an AnimalFarm which is an object implementing the
// ArrayAccess interface
$farm = new Model\AnimalFarm();
// add some animals to the farm to make sure the ArrayAccess
// interface works
$farm[] = new Model\Dog();
$farm[] = new Model\Cat();
$farm[] = new Model\Animal();
// assert we can look up the animals in the farm by array
// indices (let's try a random order)
$this->assertInstanceOf('Swagger\Client\Model\Cat', $farm[1]);
$this->assertInstanceOf('Swagger\Client\Model\Dog', $farm[0]);
$this->assertInstanceOf('Swagger\Client\Model\Animal', $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(), array('Dog', 'Cat', 'Animal'));
$this->assertInstanceOf('Swagger\Client\Model\Animal', $animal);
}
}
}

View File

@ -0,0 +1,96 @@
<?php
namespace Swagger\Client;
use Swagger\Client\Model\Animal;
use Swagger\Client\Model\AnimalFarm;
use Swagger\Client\Model\Cat;
use Swagger\Client\Model\Dog;
/**
* Test that Dog properly inherit Animal
*
* @package Swagger\Client
*/
class ModelInheritanceTest extends \PHPUnit_Framework_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 AnimalFarm which is an object implementing the ArrayAccess interface
$farm = new AnimalFarm();
// 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('Swagger\Client\Model\Animal', $animal);
}
}
}