Add __isset() and __unset() to the provider.
authorGunnar Wrobel <p@rdus.de>
Wed, 16 Sep 2009 12:22:56 +0000 (14:22 +0200)
committerGunnar Wrobel <p@rdus.de>
Wed, 16 Sep 2009 12:22:56 +0000 (14:22 +0200)
framework/Provider/lib/Horde/Provider/Base.php
framework/Provider/test/Horde/Provider/ProviderScenario.php
framework/Provider/test/Horde/Provider/ProviderTest.php

index 7687f95..0d1ba7a 100644 (file)
@@ -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
index 335f69f..76e4084 100644 (file)
@@ -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);
         }
index 4dd7c26..54edf1a 100644 (file)
@@ -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