2016-07-12 00:33:55 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This file is part of the ApiDocBundle package.
|
|
|
|
*
|
|
|
|
* (c) EXSyst
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view the LICENSE
|
|
|
|
* file that was distributed with this source code.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace EXSyst\Bundle\ApiDocBundle\Tests\Functional;
|
|
|
|
|
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
|
|
|
|
|
|
|
class FunctionalTest extends WebTestCase
|
|
|
|
{
|
2016-11-30 14:08:10 +01:00
|
|
|
public function testUndocumentedAction()
|
|
|
|
{
|
|
|
|
$paths = $this->getSwaggerDefinition()->getPaths();
|
|
|
|
$this->assertFalse($paths->has('/undocumented'));
|
|
|
|
$this->assertFalse($paths->has('/api/admin'));
|
|
|
|
}
|
|
|
|
|
2016-07-13 23:05:14 +02:00
|
|
|
public function testUserAction()
|
2016-07-12 00:33:55 +02:00
|
|
|
{
|
2016-11-30 14:08:10 +01:00
|
|
|
$operation = $this->getOperation('/api/test/{user}', 'get');
|
2016-07-12 00:33:55 +02:00
|
|
|
|
2016-07-29 18:40:56 +02:00
|
|
|
$this->assertEquals(['https'], $operation->getSchemes());
|
2016-07-13 23:05:14 +02:00
|
|
|
$this->assertEmpty($operation->getSummary());
|
|
|
|
$this->assertEmpty($operation->getDescription());
|
2016-08-01 19:58:57 +02:00
|
|
|
$this->assertNull($operation->getDeprecated());
|
2016-07-12 00:33:55 +02:00
|
|
|
|
|
|
|
$parameters = $operation->getParameters();
|
2016-07-29 18:40:56 +02:00
|
|
|
$this->assertTrue($parameters->has('user', 'path'));
|
2016-07-12 00:33:55 +02:00
|
|
|
|
2016-07-29 18:40:56 +02:00
|
|
|
$parameter = $parameters->get('user', 'path');
|
2016-07-12 00:33:55 +02:00
|
|
|
$this->assertTrue($parameter->getRequired());
|
|
|
|
$this->assertEquals('string', $parameter->getType());
|
|
|
|
$this->assertEquals('/foo/', $parameter->getFormat());
|
|
|
|
}
|
|
|
|
|
2016-11-30 16:21:03 +01:00
|
|
|
public function testFOSRestAction()
|
|
|
|
{
|
|
|
|
$operation = $this->getOperation('/api/fosrest', 'post');
|
|
|
|
|
|
|
|
$parameters = $operation->getParameters();
|
|
|
|
$this->assertTrue($parameters->has('foo', 'query'));
|
|
|
|
$this->assertTrue($parameters->has('bar', 'formData'));
|
2016-12-01 17:19:33 +01:00
|
|
|
|
|
|
|
// The _format path attribute should be removed
|
|
|
|
$this->assertFalse($parameters->has('_format', 'path'));
|
2016-11-30 16:21:03 +01:00
|
|
|
}
|
|
|
|
|
2016-07-13 23:05:14 +02:00
|
|
|
public function testNelmioAction()
|
|
|
|
{
|
2016-11-30 14:08:10 +01:00
|
|
|
$operation = $this->getOperation('/api/nelmio/{foo}', 'post');
|
2016-07-13 23:05:14 +02:00
|
|
|
|
|
|
|
$this->assertEquals('This action is described.', $operation->getDescription());
|
2016-08-04 22:27:10 +02:00
|
|
|
$this->assertNull($operation->getDeprecated());
|
2016-08-01 19:58:57 +02:00
|
|
|
|
|
|
|
$foo = $operation->getParameters()->get('foo', 'path');
|
|
|
|
$this->assertTrue($foo->getRequired());
|
|
|
|
$this->assertEquals('string', $foo->getType());
|
2016-07-13 23:05:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testDeprecatedAction()
|
|
|
|
{
|
2016-11-30 14:08:10 +01:00
|
|
|
$operation = $this->getOperation('/api/deprecated', 'get');
|
2016-07-13 23:05:14 +02:00
|
|
|
|
|
|
|
$this->assertEquals('This action is deprecated.', $operation->getSummary());
|
|
|
|
$this->assertEquals('Please do not use this action.', $operation->getDescription());
|
|
|
|
$this->assertTrue($operation->getDeprecated());
|
|
|
|
}
|
|
|
|
|
2016-08-01 19:58:57 +02:00
|
|
|
public function testApiPlatform()
|
2016-07-28 10:20:59 +02:00
|
|
|
{
|
2016-08-01 19:58:57 +02:00
|
|
|
$operation = $this->getOperation('/api/dummies', 'get');
|
|
|
|
$operation = $this->getOperation('/api/foo', 'get');
|
|
|
|
$operation = $this->getOperation('/api/foo', 'post');
|
|
|
|
$operation = $this->getOperation('/api/dummies/{id}', 'get');
|
2016-07-28 10:20:59 +02:00
|
|
|
}
|
|
|
|
|
2016-07-12 00:33:55 +02:00
|
|
|
private function getSwaggerDefinition()
|
|
|
|
{
|
|
|
|
static::createClient();
|
|
|
|
|
2016-11-18 22:16:53 +01:00
|
|
|
return static::$kernel->getContainer()->get('exsyst_api_doc.generator')->generate();
|
2016-07-12 00:33:55 +02:00
|
|
|
}
|
2016-07-13 23:05:14 +02:00
|
|
|
|
|
|
|
private function getOperation($path, $method)
|
|
|
|
{
|
|
|
|
$api = $this->getSwaggerDefinition();
|
|
|
|
$paths = $api->getPaths();
|
|
|
|
|
|
|
|
$this->assertTrue($paths->has($path));
|
|
|
|
$action = $paths->get($path);
|
|
|
|
|
|
|
|
$this->assertTrue($action->hasOperation($method));
|
|
|
|
|
|
|
|
return $action->getOperation($method);
|
|
|
|
}
|
2016-07-12 00:33:55 +02:00
|
|
|
}
|