From 772184cfa19c2c87d58c28441ee03a22a7d7e9f3 Mon Sep 17 00:00:00 2001 From: Florent DUBOST Date: Wed, 27 Mar 2013 16:20:42 +0100 Subject: [PATCH] Add some tests for the cache annotation --- Annotation/ApiDoc.php | 4 ++++ Tests/Annotation/ApiDocTest.php | 12 ++++++++++++ Tests/Extractor/ApiDocExtratorTest.php | 13 +++++++++++++ Tests/Fixtures/Controller/TestController.php | 9 +++++++++ composer.json | 4 +++- 5 files changed, 41 insertions(+), 1 deletion(-) diff --git a/Annotation/ApiDoc.php b/Annotation/ApiDoc.php index cd49bdc..28a8f24 100644 --- a/Annotation/ApiDoc.php +++ b/Annotation/ApiDoc.php @@ -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']; } diff --git a/Tests/Annotation/ApiDocTest.php b/Tests/Annotation/ApiDocTest.php index f1fece7..6a7750a 100644 --- a/Tests/Annotation/ApiDocTest.php +++ b/Tests/Annotation/ApiDocTest.php @@ -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']); + } } diff --git a/Tests/Extractor/ApiDocExtratorTest.php b/Tests/Extractor/ApiDocExtratorTest.php index b4217fa..eee99dd 100644 --- a/Tests/Extractor/ApiDocExtratorTest.php +++ b/Tests/Extractor/ApiDocExtratorTest.php @@ -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() + ); + } } diff --git a/Tests/Fixtures/Controller/TestController.php b/Tests/Fixtures/Controller/TestController.php index 1c33286..4c42042 100644 --- a/Tests/Fixtures/Controller/TestController.php +++ b/Tests/Fixtures/Controller/TestController.php @@ -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() + { + } } diff --git a/composer.json b/composer.json index 408ba0c..d04b3d0 100644 --- a/composer.json +++ b/composer.json @@ -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": {