Permalink
Browse files

Added a NullHandler (named "BlackHole", since Null is a reserved word)

  • Loading branch information...
1 parent 8893aa6 commit cd8d47bd0eaa70be40bebdb665d69a8bac802952 @bzikarsky bzikarsky committed Oct 23, 2012
Showing with 130 additions and 0 deletions.
  1. +77 −0 src/Stash/Handler/BlackHole.php
  2. +53 −0 tests/Stash/Test/Handler/BlackHoleTest.php
@@ -0,0 +1,77 @@
+<?php
+
+/*
+ * This file is part of the Stash package.
+*
+* (c) Robert Hafner <tedivm@tedivm.com>
+*
+* For the full copyright and license information, please view the LICENSE
+* file that was distributed with this source code.
+*/
+
+namespace Stash\Handler;
+
+/**
+ * This class provides a NULL caching handler, it always takes values, but never saves them
+ * Can be used as an default save handler
+ *
+ * @author Benjamin Zikarsky <benjamin.zikarsky@perbility.de>
+ */
+class BlackHole implements HandlerInterface
+{
+
+ /**
+ * NOOP constructor
+ */
+ public function __construct(array $options = array())
+ {
+ // empty
+ }
+
+
+ /*
+ * (non-PHPdoc)
+ * @see \Stash\Handler\HandlerInterface::clear()
+ */
+ public function clear($key = null)
+ {
+ return true;
+ }
+
+ /*
+ * (non-PHPdoc)
+ * @see \Stash\Handler\HandlerInterface::getData()
+ */
+ public function getData($key)
+ {
+ return false;
+ }
+
+ /*
+ * (non-PHPdoc)
+ * @see \Stash\Handler\HandlerInterface::purge()
+ */
+ public function purge()
+ {
+ return true;
+ }
+
+ /*
+ * (non-PHPdoc)
+ * @see \Stash\Handler\HandlerInterface::storeData()
+ */
+ public function storeData($key, $data, $expiration)
+ {
+ return true;
+ }
+
+ /*
+ * (non-PHPdoc)
+ * @see \Stash\Handler\HandlerInterface::isAvailable()
+ */
+ public static function isAvailable()
+ {
+ return true;
+ }
+
+}
@@ -0,0 +1,53 @@
+<?php
+
+/*
+ * This file is part of the Stash package.
+ *
+ * (c) Robert Hafner <tedivm@tedivm.com>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Stash\Test\Handler;
+
+use Stash\Handler\BlackHole;
+
+/**
+ * @author Benjamin Zikarsky <benjamin.zikarsky@perbility.de>
+ */
+class BlackHoleTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * @var Stash\Handler\BlackHole
+ */
+ private $handler = null;
+
+ public function setUp()
+ {
+ $this->handler = new BlackHole();
+ }
+
+ public function testPurge()
+ {
+ $this->assertTrue($this->handler->purge());
+ }
+
+ public function testStoreData()
+ {
+ $this->assertTrue($this->handler->storeData("test", "data", 0));
+ $this->assertFalse($this->handler->getData("test"));
+ }
+
+ public function testGetData()
+ {
+ $this->assertFalse($this->handler->getData("test"));
+ }
+
+ public function testClear()
+ {
+ $this->assertTrue($this->handler->clear());
+ $this->assertTrue($this->handler->clear(null));
+ $this->assertTrue($this->handler->clear("test"));
+ }
+}

0 comments on commit cd8d47b

Please sign in to comment.