From 74ba2dabf0a6462f4b0801b1c3f2ae0e45faaa93 Mon Sep 17 00:00:00 2001 From: chris cnizzardini Date: Fri, 17 Apr 2020 14:29:02 -0400 Subject: [PATCH] @SwagEntityAttribute tests --- tests/TestCase/Lib/SwaggerEntityTest.php | 25 ++++++++++++++++++++ tests/test_app/src/Model/Entity/Employee.php | 13 ++-------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/tests/TestCase/Lib/SwaggerEntityTest.php b/tests/TestCase/Lib/SwaggerEntityTest.php index 7e638d34..03191f50 100644 --- a/tests/TestCase/Lib/SwaggerEntityTest.php +++ b/tests/TestCase/Lib/SwaggerEntityTest.php @@ -83,4 +83,29 @@ public function testEntityInvisible() $this->assertArrayNotHasKey('EmployeeSalary', $arr['components']['schemas']); } + + public function testEntityAttribute() + { + $config = new Configuration([ + 'prefix' => '/api', + 'yml' => '/config/swagger-bare-bones.yml', + 'json' => '/webroot/swagger.json', + 'webPath' => '/swagger.json', + 'hotReload' => false, + 'namespaces' => [ + 'controllers' => ['\SwaggerBakeTest\App\\'], + 'entities' => ['\SwaggerBakeTest\App\\'] + ] + ], SWAGGER_BAKE_TEST_APP); + + $cakeRoute = new CakeRoute($this->router, $config); + + $swagger = new Swagger(new CakeModel($cakeRoute, $config)); + + $arr = json_decode($swagger->toString(), true); + + $employee = $arr['components']['schemas']['Employee']; + + $this->assertTrue($employee['properties']['gender']['readOnly']); + } } \ No newline at end of file diff --git a/tests/test_app/src/Model/Entity/Employee.php b/tests/test_app/src/Model/Entity/Employee.php index 9564b3e2..1388f1bc 100644 --- a/tests/test_app/src/Model/Entity/Employee.php +++ b/tests/test_app/src/Model/Entity/Employee.php @@ -4,20 +4,11 @@ namespace SwaggerBakeTest\App\Model\Entity; use Cake\ORM\Entity; +use SwaggerBake\Lib\Annotation as SwagAnnotation; /** * Employee Entity - * - * @property int $id - * @property \Cake\I18n\FrozenDate $birth_date - * @property string $first_name - * @property string $last_name - * @property string $gender - * @property \Cake\I18n\FrozenDate $hire_date - * - * @property \SwaggerBake\Test\Model\Entity\DepartmentEmployee[] $department_employees - * @property \SwaggerBake\Test\Model\Entity\EmployeeSalary[] $employee_salaries - * @property \SwaggerBake\Test\Model\Entity\EmployeeTitle[] $employee_titles + * @SwagAnnotation\SwagEntityAttribute(name="gender", type="string", readOnly=true, required=false) */ class Employee extends Entity {