Skip to content

Commit

Permalink
increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
cnizzardini committed Jul 7, 2021
1 parent 5938731 commit a820a48
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 17 deletions.
15 changes: 15 additions & 0 deletions tests/TestCase/Lib/Annotations/AbstractSchemaPropertyTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace SwaggerBake\Test\TestCase\Lib\Annotations;

use Cake\TestSuite\TestCase;
use SwaggerBake\Lib\Annotation\SwagDtoRequestBody;

class AbstractSchemaPropertyTest extends TestCase
{
public function test_construct_invalid_argument_exception(): void
{
$this->expectException(\InvalidArgumentException::class);
new SwagDtoRequestBody(['']);
}
}
26 changes: 12 additions & 14 deletions tests/TestCase/Lib/Annotations/SwagPathParameterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,18 @@
use Cake\Routing\Router;
use Cake\Routing\RouteBuilder;
use Cake\TestSuite\TestCase;
use SwaggerBake\Lib\Annotation\SwagPathParameter;
use SwaggerBake\Lib\AnnotationLoader;
use SwaggerBake\Lib\Exception\SwaggerBakeRunTimeException;
use SwaggerBake\Lib\Model\ModelScanner;
use SwaggerBake\Lib\Route\RouteScanner;
use SwaggerBake\Lib\Configuration;
use SwaggerBake\Lib\Swagger;

class SwagPathParameterTest extends TestCase
{
/**
* @var Router
*/
private $router;

public function setUp(): void
public function test_swag_path_parameter(): void
{
parent::setUp(); // TODO: Change the autogenerated stub
$router = new Router();
$router::scope('/', function (RouteBuilder $builder) {
$builder->setExtensions(['json']);
Expand All @@ -36,9 +32,8 @@ public function setUp(): void
]
]);
});
$this->router = $router;

$this->config = new Configuration([
$config = new Configuration([
'prefix' => '/',
'yml' => '/config/swagger-bare-bones.yml',
'json' => '/webroot/swagger.json',
Expand All @@ -55,13 +50,10 @@ public function setUp(): void
], SWAGGER_BAKE_TEST_APP);

AnnotationLoader::load();
}

public function testSwagQuery()
{
$cakeRoute = new RouteScanner($this->router, $this->config);
$cakeRoute = new RouteScanner($router, $config);

$swagger = new Swagger(new ModelScanner($cakeRoute, $this->config));
$swagger = new Swagger(new ModelScanner($cakeRoute, $config));
$arr = json_decode($swagger->toString(), true);

$params = $arr['paths']['/operation-path/path-parameter/{id}']['get']['parameters'];
Expand All @@ -71,4 +63,10 @@ public function testSwagQuery()
$this->assertEquals('ID', $param['description']);
$this->assertEquals('int64', $param['schema']['format']);
}

public function test_constructor_invalid_arg_exception(): void
{
$this->expectException(SwaggerBakeRunTimeException::class);
new SwagPathParameter(['type' => 'bool']);
}
}
18 changes: 16 additions & 2 deletions tests/TestCase/Lib/Annotations/SwagSecurityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Cake\Routing\Router;
use Cake\Routing\RouteBuilder;
use Cake\TestSuite\TestCase;
use SwaggerBake\Lib\Annotation\SwagSecurity;
use SwaggerBake\Lib\AnnotationLoader;
use SwaggerBake\Lib\Model\ModelScanner;
use SwaggerBake\Lib\Route\RouteScanner;
Expand All @@ -18,8 +19,16 @@ class SwagSecurityTest extends TestCase
'plugin.SwaggerBake.Employees',
];

/**
* @var Router
*/
private $router;

/**
* @var Configuration
*/
private $config;

public function setUp(): void
{
parent::setUp(); // TODO: Change the autogenerated stub
Expand Down Expand Up @@ -57,14 +66,13 @@ public function setUp(): void
AnnotationLoader::load();
}

public function testSwagHeader()
public function test_swag_security(): void
{
$cakeRoute = new RouteScanner($this->router, $this->config);

$swagger = new Swagger(new ModelScanner($cakeRoute, $this->config));
$arr = json_decode($swagger->toString(), true);


$this->assertArrayHasKey('/employees/custom-get', $arr['paths']);
$this->assertArrayHasKey('get', $arr['paths']['/employees/custom-get']);
$operation = $arr['paths']['/employees/custom-get']['get'];
Expand All @@ -75,4 +83,10 @@ public function testSwagHeader()
return isset($param['BearerAuth']);
}));
}

public function test_constructor_invalid_arg_exception(): void
{
$this->expectException(\InvalidArgumentException::class);
new SwagSecurity(['']);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

namespace SwaggerBake\Test\TestCase\Lib\Extension\CakeSearch\Annotation;

use Cake\TestSuite\TestCase;
use SwaggerBake\Lib\Extension\CakeSearch\Annotation\SwagSearch;

class SwagSearchTest extends TestCase
{
public function test_construct_invalid_argument_exception(): void
{
$this->expectException(\InvalidArgumentException::class);
new SwagSearch(['']);
}
}
2 changes: 1 addition & 1 deletion tests/TestCase/Lib/Extension/CakeSearch/ExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function setUp(): void
ExtensionLoader::load();
}

public function testGetOperation()
public function test_get_operation(): void
{
$configuration = new Configuration($this->config, SWAGGER_BAKE_TEST_APP);

Expand Down

0 comments on commit a820a48

Please sign in to comment.