From fa3e72e6e3601c62f7ed1a5ce847d556f2186361 Mon Sep 17 00:00:00 2001 From: Akihito Nakano Date: Sun, 7 Jan 2018 12:21:53 +0900 Subject: [PATCH] [PHP] Cleanup AnimalFarmTest (#7279) * Move test codes in "test" to "tests" * Regenerate test/Model/AnimalFarmTest.php --- .../test/Model/AnimalFarmTest.php | 104 +----------------- .../tests/ModelInheritanceTest.php | 96 ++++++++++++++++ 2 files changed, 102 insertions(+), 98 deletions(-) create mode 100644 samples/client/petstore/php/SwaggerClient-php/tests/ModelInheritanceTest.php diff --git a/samples/client/petstore/php/SwaggerClient-php/test/Model/AnimalFarmTest.php b/samples/client/petstore/php/SwaggerClient-php/test/Model/AnimalFarmTest.php index 37e736a5d2d..8f4500cebef 100644 --- a/samples/client/petstore/php/SwaggerClient-php/test/Model/AnimalFarmTest.php +++ b/samples/client/petstore/php/SwaggerClient-php/test/Model/AnimalFarmTest.php @@ -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); - } } } diff --git a/samples/client/petstore/php/SwaggerClient-php/tests/ModelInheritanceTest.php b/samples/client/petstore/php/SwaggerClient-php/tests/ModelInheritanceTest.php new file mode 100644 index 00000000000..658e60ba638 --- /dev/null +++ b/samples/client/petstore/php/SwaggerClient-php/tests/ModelInheritanceTest.php @@ -0,0 +1,96 @@ +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); + } + } +}