Add some tests for the cache annotation

This commit is contained in:
Florent DUBOST 2013-03-27 16:20:42 +01:00
parent 5ec931185f
commit 772184cfa1
5 changed files with 41 additions and 1 deletions

View File

@ -152,6 +152,10 @@ class ApiDoc
$this->setAuthentication((bool) $data['authentication']);
}
if (isset($data['cache'])) {
$this->setCache($data['cache']);
}
if (isset($data['section'])) {
$this->section = $data['section'];
}

View File

@ -210,4 +210,16 @@ class ApiDocTest extends TestCase
$this->assertTrue($array['authentication']);
}
public function testConstructWithCache()
{
$data = array(
'cache' => '60'
);
$annot = new ApiDoc($data);
$array = $annot->toArray();
$this->assertEquals($data['cache'], $array['cache']);
}
}

View File

@ -166,4 +166,17 @@ class ApiDocExtractorTest extends WebTestCase
$annotation->getAuthentication()
);
}
public function testGetWithCache()
{
$container = $this->getContainer();
$extractor = $container->get('nelmio_api_doc.extractor.api_doc_extractor');
$annotation = $extractor->get('Nelmio\ApiDocBundle\Tests\Fixtures\Controller\TestController::CachedAction', 'test_route_14');
$this->assertNotNull($annotation);
$this->assertEquals(
60,
$annotation->getCache()
);
}
}

View File

@ -15,6 +15,7 @@ use FOS\RestBundle\Controller\Annotations\QueryParam;
use FOS\RestBundle\Controller\Annotations\RequestParam;
use Nelmio\ApiDocBundle\Annotation\ApiDoc;
use Symfony\Component\HttpFoundation\Response;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Cache;
class TestController
{
@ -145,4 +146,12 @@ class TestController
public function authenticatedAction()
{
}
/**
* @ApiDoc()
* @Cache(maxage=60, public=1)
*/
public function cachedAction()
{
}
}

View File

@ -29,7 +29,9 @@
"symfony/validator": "~2.1",
"symfony/yaml": "~2.1",
"friendsofsymfony/rest-bundle": "dev-master",
"jms/serializer-bundle": ">=0.11"
"jms/serializer-bundle": ">=0.11",
"phpunit/phpunit-mock-objects": "dev-master",
"sensio/framework-extra-bundle": "dev-master"
},
"minimum-stability": "dev",
"autoload": {