Skip to content

Commit

Permalink
tests swagger and redoc index
Browse files Browse the repository at this point in the history
  • Loading branch information
cnizzardini committed Oct 4, 2020
1 parent 9c9c0d7 commit 73ca3e2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
36 changes: 36 additions & 0 deletions tests/TestCase/ControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace SwaggerBake\Test\TestCase;

use Cake\TestSuite\IntegrationTestTrait;
use Cake\TestSuite\TestCase;

class ControllerTest extends TestCase
{
use IntegrationTestTrait;

/**
* @var string[]
*/
public $fixtures = [
'plugin.SwaggerBake.Departments',
];

public function setUp(): void
{
parent::setUp(); // TODO: Change the autogenerated stub
static::setAppNamespace('SwaggerBakeTest\App');
}

public function testSwaggerIndex()
{
$this->get('/');
$this->assertResponseOk();
}

public function testRedocIndex()
{
$this->get('/?doctype=redoc');
$this->assertResponseOk();
}
}
17 changes: 16 additions & 1 deletion tests/test_app/src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@
use Bake\Command\EntryCommand;
use Cake\Console\CommandCollection;
use Cake\Http\BaseApplication;
use Cake\Http\Middleware\BodyParserMiddleware;
use Cake\Http\MiddlewareQueue;
use Cake\Routing\Middleware\RoutingMiddleware;
use Cake\Routing\RouteBuilder;

class Application extends BaseApplication
{
public function middleware(MiddlewareQueue $middleware): MiddlewareQueue
{
return $middleware;
return $middleware->add(new RoutingMiddleware($this))->add(new BodyParserMiddleware());
}

public function bootstrap(): void
Expand All @@ -27,4 +29,17 @@ public function console(CommandCollection $commands): CommandCollection
$commands->add('bake', EntryCommand::class);
return $commands;
}

public function routes(RouteBuilder $routes): void
{
$routes->scope('/', function (RouteBuilder $builder) {
$builder->fallbacks();
$builder->setExtensions(['json','xml']);
$builder->resources('Departments');
$builder->connect('/', [
'plugin' => 'SwaggerBake', 'controller' => 'Swagger', 'action' => 'index'
]);
});
parent::routes($routes);
}
}

0 comments on commit 73ca3e2

Please sign in to comment.