From e3e68421dddfddbb9fc8e64c8811c496fab5da29 Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel Date: Wed, 16 Sep 2009 14:22:56 +0200 Subject: [PATCH] Add __isset() and __unset() to the provider. --- framework/Provider/lib/Horde/Provider/Base.php | 26 ++++++++++++++++++++++ .../test/Horde/Provider/ProviderScenario.php | 10 +++++++++ .../Provider/test/Horde/Provider/ProviderTest.php | 18 +++++++++++++++ 3 files changed, 54 insertions(+) diff --git a/framework/Provider/lib/Horde/Provider/Base.php b/framework/Provider/lib/Horde/Provider/Base.php index 7687f9551..0d1ba7a21 100644 --- a/framework/Provider/lib/Horde/Provider/Base.php +++ b/framework/Provider/lib/Horde/Provider/Base.php @@ -74,4 +74,30 @@ class Horde_Provider_Base throw new Horde_Provider_Exception(sprintf("No such element: %s", $k)); } } + + /** + * Test if the element is available. + * + * @param string $k The key of the element to test for. + * + * @return boolean True if the element is sset, false otherwise. + */ + public function __isset($k) + { + return isset($this->elements[$k]); + } + + /** + * Delete the element. + * + * @param string $k The key of the element to delete. + * + * @return NULL + */ + public function __unset($k) + { + if (isset($this->elements[$k])) { + unset($this->elements[$k]); + } + } } \ No newline at end of file diff --git a/framework/Provider/test/Horde/Provider/ProviderScenario.php b/framework/Provider/test/Horde/Provider/ProviderScenario.php index 335f69fb2..76e4084dc 100644 --- a/framework/Provider/test/Horde/Provider/ProviderScenario.php +++ b/framework/Provider/test/Horde/Provider/ProviderScenario.php @@ -76,6 +76,13 @@ class Horde_Provider_ProviderScenario extends PHPUnit_Extensions_Story_TestCase $world['result'] = $e; } break; + case 'deleting the element': + try { + unset($world['provider']->{$arguments[0]}); + } catch (Exception $e) { + $world['result'] = $e; + } + break; default: return $this->notImplemented($action); } @@ -103,6 +110,9 @@ class Horde_Provider_ProviderScenario extends PHPUnit_Extensions_Story_TestCase $this->assertTrue($world['result'] instanceOf Exception); $this->assertEquals($arguments[0], $world['result']->getMessage()); break; + case 'the element exists': + $this->assertTrue(isset($world['provider']->{$arguments[0]})); + break; default: return $this->notImplemented($action); } diff --git a/framework/Provider/test/Horde/Provider/ProviderTest.php b/framework/Provider/test/Horde/Provider/ProviderTest.php index 4dd7c2671..54edf1a1e 100644 --- a/framework/Provider/test/Horde/Provider/ProviderTest.php +++ b/framework/Provider/test/Horde/Provider/ProviderTest.php @@ -61,10 +61,28 @@ class Horde_Provider_ProviderTest extends Horde_Provider_ProviderScenario $this->given('a provider') ->given('a registered element', 'key', 'value') ->when('retrieving the element', 'key') + ->then('the element exists', 'key') ->then('the result is', 'value'); } /** + * Test deleting a simple element. + * + * @scenario + * + * @return NULL + */ + public function deletingASimpleElement() + { + $this->given('a provider') + ->given('a registered element', 'key', 'value') + ->when('deleting the element', 'key') + ->when('retrieving the element', 'key') + ->then('the result is an error with the message', + 'No such element: key'); + } + + /** * Test retrieving a new element with invalid recursion. * * @scenario -- 2.11.0