From 0703555998b94ab83434cf8a919150818139b487 Mon Sep 17 00:00:00 2001 From: David Buchmann Date: Fri, 8 May 2015 10:27:31 +0200 Subject: [PATCH] Adding TagHandler::hasTags method --- src/Handler/TagHandler.php | 14 ++++++++++++-- tests/Unit/Handler/TagHandlerTest.php | 2 ++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Handler/TagHandler.php b/src/Handler/TagHandler.php index 6aa506ec..cf03cd63 100644 --- a/src/Handler/TagHandler.php +++ b/src/Handler/TagHandler.php @@ -77,9 +77,19 @@ public function getTagsHeaderValue() } /** - * Add tags to be sent. + * Check whether the tag handler has any tags to set on the response. * - * This must be called before any response is sent to the client. + * @return bool True if this handler will set at least one tag. + */ + public function hasTags() + { + return 0 < count($this->tags); + } + + /** + * Add tags to be set on the response. + * + * This must be called before any HTTP response is sent to the client. * * @param array $tags List of tags to add. * diff --git a/tests/Unit/Handler/TagHandlerTest.php b/tests/Unit/Handler/TagHandlerTest.php index f21b4781..ac56be2e 100644 --- a/tests/Unit/Handler/TagHandlerTest.php +++ b/tests/Unit/Handler/TagHandlerTest.php @@ -90,7 +90,9 @@ public function testTagResponse() ->getMock(); $tagHandler = new TagHandler($cacheInvalidator); + $this->assertFalse($tagHandler->hasTags()); $tagHandler->addTags(array('post-1', 'test,post')); + $this->assertTrue($tagHandler->hasTags()); $this->assertEquals('post-1,test_post', $tagHandler->getTagsHeaderValue()); } }