Add a log decorator and a stop watch decorator.
authorGunnar Wrobel <p@rdus.de>
Wed, 22 Dec 2010 14:03:40 +0000 (15:03 +0100)
committerGunnar Wrobel <p@rdus.de>
Tue, 4 Jan 2011 07:54:13 +0000 (08:54 +0100)
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Decorator/Base.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Decorator/Log.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Decorator/Timer.php [new file with mode: 0644]
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Imap.php
framework/Kolab_Storage/lib/Horde/Kolab/Storage/Factory.php
framework/Kolab_Storage/package.xml
framework/Kolab_Storage/test/Horde/Kolab/Storage/TestCase.php
framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/Driver/Decorator/LogTest.php [new file with mode: 0644]
framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/Driver/Decorator/TimerTest.php [new file with mode: 0644]
framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/FactoryTest.php

index 585640d..f4a9875 100644 (file)
@@ -35,6 +35,13 @@ interface Horde_Kolab_Storage_Driver
     public function getAuth();
 
     /**
+     * Retrieves a list of mailboxes from the server.
+     *
+     * @return array The list of mailboxes.
+     */
+    public function getMailboxes();
+
+    /**
      * Does the given folder exist?
      *
      * @param string $folder The folder to check.
index e7aef4e..3c9a30a 100644 (file)
@@ -29,12 +29,50 @@ class Horde_Kolab_Storage_Driver_Decorator_Base
 implements Horde_Kolab_Storage_Driver
 {
     /**
+     * The decorated driver.
+     *
+     * @var Horde_Kolab_Storage_Driver
+     */
+    private $_driver;
+
+    /**
+     * Constructor.
+     *
+     * @param Horde_Kolab_Storage_Driver $driver The decorated driver.
+     */
+    public function __construct(Horde_Kolab_Storage_Driver $driver)
+    {
+        $this->_driver = $driver;
+    }
+
+    /**
+     * Return the class name of the decorated driver.
+     *
+     * @return string The class name of the decorated driver.
+     */
+    public function getDriverName()
+    {
+        return get_class($this->_driver);
+    }
+
+    /**
      * Return the id of the user currently authenticated.
      *
      * @return string The id of the user that opened the connection.
      */
     public function getAuth()
     {
+        return $this->_driver->getAuth();
+    }
+
+    /**
+     * Retrieves a list of mailboxes from the server.
+     *
+     * @return array The list of mailboxes.
+     */
+    public function getMailboxes()
+    {
+        return $this->_driver->getMailboxes();
     }
 
     /**
index 1f9c8b9..1e6910c 100644 (file)
@@ -12,7 +12,7 @@
  */
 
 /**
- * The basic driver decorator definition for accessing Kolab storage.
+ * A log decorator definition for the Kolab storage drivers.
  *
  * Copyright 2010 The Horde Project (http://www.horde.org/)
  *
@@ -29,12 +29,43 @@ class Horde_Kolab_Storage_Driver_Decorator_Log
 extends Horde_Kolab_Storage_Driver_Decorator_Base
 {
     /**
-     * Return the id of the user currently authenticated.
+     * A log handler.
+     *
+     * @var mixed
+     */
+    private $_logger;
+
+    /**
+     * Constructor.
+     *
+     * @param Horde_Kolab_Storage_Driver $driver The decorated driver.
+     * @param mixed                      $logger The log handler. This instance
+     *                                           must provide the info() method.
+     */
+    public function __construct(Horde_Kolab_Storage_Driver $driver, $logger)
+    {
+        $this->_logger = $logger;
+        parent::__construct($driver);
+    }
+
+    /**
+     * Retrieves a list of mailboxes from the server.
      *
-     * @return string The id of the user that opened the connection.
+     * @return array The list of mailboxes.
      */
-    public function getAuth()
+    public function getMailboxes()
     {
+        $this->_logger->info(
+            sprintf('Driver "%s": Listing folders.', $this->getDriverName())
+        );
+        $result = parent::getMailboxes();
+        $this->_logger->info(
+            sprintf(
+                'Driver "%s": List contained %s folders.',
+                $this->getDriverName(),
+                count($result))
+        );
+        return $result;
     }
 
     /**
diff --git a/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Decorator/Timer.php b/framework/Kolab_Storage/lib/Horde/Kolab/Storage/Driver/Decorator/Timer.php
new file mode 100644 (file)
index 0000000..4362098
--- /dev/null
@@ -0,0 +1,316 @@
+<?php
+/**
+ * A stop watch decorator for outgoing requests from the Kolab storage drivers.
+ *
+ * PHP version 5
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * A stop watch decorator for outgoing requests from the Kolab storage drivers.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category Kolab
+ * @package  Kolab_Storage
+ * @author   Gunnar Wrobel <wrobel@pardus.de>
+ * @license  http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link     http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Driver_Decorator_Timer
+extends Horde_Kolab_Storage_Driver_Decorator_Base
+{
+    /**
+     * A log handler.
+     *
+     * @var mixed
+     */
+    private $_logger;
+
+    /**
+     * A stop watch.
+     *
+     * @var Horde_Support_Timer
+     */
+    private $_timer;
+
+    /**
+     * Constructor.
+     *
+     * @param Horde_Kolab_Storage_Driver $driver The decorated driver.
+     * @param Horde_Support_Timer        $timer  A stop watch.
+     * @param mixed                      $logger The log handler. This instance
+     *                                           must provide the info() method.
+     */
+    public function __construct(
+        Horde_Kolab_Storage_Driver $driver,
+        Horde_Support_Timer $timer,
+        $logger
+    ) {
+        $this->_logger = $logger;
+        $this->_timer = $timer;
+        parent::__construct($driver);
+    }
+
+    /**
+     * Retrieves a list of mailboxes from the server.
+     *
+     * @return array The list of mailboxes.
+     */
+    public function getMailboxes()
+    {
+        $this->_timer->push();
+        $result = parent::getMailboxes();
+        $this->_logger->info(
+            sprintf(
+                'REQUEST OUT IMAP: %s ms [getMailboxes]',
+                floor($this->_timer->pop() * 1000)
+            )
+        );
+        return $result;
+    }
+
+    /**
+     * Does the given folder exist?
+     *
+     * @param string $folder The folder to check.
+     *
+     * @return boolean True in case the folder exists, false otherwise.
+     */
+    public function exists($folder)
+    {
+    }
+
+    /**
+     * Opens the given folder.
+     *
+     * @param string $folder  The folder to open
+     *
+     * @return mixed  True in case the folder was opened successfully, a PEAR
+     *                error otherwise.
+     */
+    public function select($folder)
+    {
+    }
+
+    /**
+     * Returns the status of the current folder.
+     *
+     * @param string $folder Check the status of this folder.
+     *
+     * @return array  An array that contains 'uidvalidity' and 'uidnext'.
+     */
+    public function status($folder)
+    {
+    }
+
+    /**
+     * Returns the message ids of the messages in this folder.
+     *
+     * @param string $folder Check the status of this folder.
+     *
+     * @return array  The message ids.
+     */
+    public function getUids($folder)
+    {
+    }
+
+    /**
+     * Create the specified folder.
+     *
+     * @param string $folder The folder to create.
+     *
+     * @return mixed True in case the operation was successfull, a
+     *               PEAR error otherwise.
+     */
+    public function create($folder)
+    {
+    }
+
+    /**
+     * Delete the specified folder.
+     *
+     * @param string $folder  The folder to delete.
+     *
+     * @return mixed True in case the operation was successfull, a
+     *               PEAR error otherwise.
+     */
+    public function delete($folder)
+    {
+    }
+
+    /**
+     * Rename the specified folder.
+     *
+     * @param string $old  The folder to rename.
+     * @param string $new  The new name of the folder.
+     *
+     * @return mixed True in case the operation was successfull, a
+     *               PEAR error otherwise.
+     */
+    public function rename($old, $new)
+    {
+    }
+
+    /**
+     * Appends a message to the current folder.
+     *
+     * @param string $mailbox The mailbox to append the message(s) to. Either
+     *                        in UTF7-IMAP or UTF-8.
+     * @param string $msg     The message to append.
+     *
+     * @return mixed  True or a PEAR error in case of an error.
+     */
+    public function appendMessage($mailbox, $msg)
+    {
+    }
+
+    /**
+     * Deletes messages from the current folder.
+     *
+     * @param integer $uids  IMAP message ids.
+     *
+     * @return mixed  True or a PEAR error in case of an error.
+     */
+    public function deleteMessages($mailbox, $uids)
+    {
+    }
+
+    /**
+     * Moves a message to a new folder.
+     *
+     * @param integer $uid        IMAP message id.
+     * @param string $new_folder  Target folder.
+     *
+     * @return mixed  True or a PEAR error in case of an error.
+     */
+    public function moveMessage($old_folder, $uid, $new_folder)
+    {
+    }
+
+    /**
+     * Expunges messages in the current folder.
+     *
+     * @param string $mailbox The mailbox to append the message(s) to. Either
+     *                        in UTF7-IMAP or UTF-8.
+     *
+     * @return mixed  True or a PEAR error in case of an error.
+     */
+    public function expunge($mailbox)
+    {
+    }
+
+    /**
+     * Retrieves the message headers for a given message id.
+     *
+     * @param string $mailbox The mailbox to append the message(s) to. Either
+     *                        in UTF7-IMAP or UTF-8.
+     * @param int $uid                The message id.
+     * @param boolean $peek_for_body  Prefetch the body.
+     *
+     * @return mixed  The message header or a PEAR error in case of an error.
+     */
+    public function getMessageHeader($mailbox, $uid, $peek_for_body = true)
+    {
+    }
+
+    /**
+     * Retrieves the message body for a given message id.
+     *
+     * @param string $mailbox The mailbox to append the message(s) to. Either
+     *                        in UTF7-IMAP or UTF-8.
+     * @param integet $uid  The message id.
+     *
+     * @return mixed  The message body or a PEAR error in case of an error.
+     */
+    public function getMessageBody($mailbox, $uid)
+    {
+    }
+
+    /**
+     * Retrieve the access rights for a folder.
+     *
+     * @param Horde_Kolab_Storage_Folder $folder The folder to retrieve the ACL for.
+     *
+     * @return An array of rights.
+     */
+    public function getAcl(Horde_Kolab_Storage_Folder $folder)
+    {
+    }
+
+    /**
+     * Set the access rights for a folder.
+     *
+     * @param string $folder  The folder to act upon.
+     * @param string $user    The user to set the ACL for.
+     * @param string $acl     The ACL.
+     *
+     * @return NULL
+     */
+    public function setAcl($folder, $user, $acl)
+    {
+    }
+
+    /**
+     * Delete the access rights for user on a folder.
+     *
+     * @param string $folder  The folder to act upon.
+     * @param string $user    The user to delete the ACL for
+     *
+     * @return NULL
+     */
+    public function deleteAcl($folder, $user)
+    {
+    }
+
+    /**
+     * Fetches the annotation on a folder.
+     *
+     * @param string $entry  The entry to fetch.
+     * @param string $folder The name of the folder.
+     *
+     * @return string The annotation value.
+     */
+    public function getAnnotation($entry, $folder)
+    {
+    }
+
+    /**
+     * Sets the annotation on a folder.
+     *
+     * @param string $entry  The entry to set.
+     * @param array  $value  The values to set
+     * @param string $folder The name of the folder.
+     *
+     * @return NULL
+     */
+    public function setAnnotation($entry, $value, $folder)
+    {
+    }
+
+    /**
+     * Retrieve the namespace information for this connection.
+     *
+     * @return Horde_Kolab_Storage_Driver_Namespace The initialized namespace handler.
+     */
+    public function getNamespace()
+    {
+    }
+
+    /**
+     * Get the group handler for this connection.
+     *
+     * @return Horde_Group The group handler.
+     */
+    public function getGroupHandler()
+    {
+    }
+}
\ No newline at end of file
index f8f3bbd..fecfb65 100644 (file)
@@ -62,7 +62,7 @@ extends Horde_Kolab_Storage_Driver_Base
     }
 
     /**
-     * Retrieves a list of mailboxes on the server.
+     * Retrieves a list of mailboxes from the server.
      *
      * @return array The list of mailboxes.
      */
index 677f695..41506b5 100644 (file)
@@ -59,7 +59,7 @@ class Horde_Kolab_Storage_Factory
         $storage = new Horde_Kolab_Storage_Base(
             $this->createDriverFromParams($params)
         );
-        if (isset($params['logger'])) {
+        if (!empty($params['logger'])) {
             $storage = new Horde_Kolab_Storage_Decorator_Log(
                 $storage, $params['logger']
             );
@@ -72,11 +72,11 @@ class Horde_Kolab_Storage_Factory
      *
      * @param array $params The parameters for the backend access. See create().
      * <pre>
-     *  - driver : The type of backend driver. One of "mock", "php", "pear",
-     *             "horde", "horde-socket", and "roundcube".
-     *  - params : Backend specific connection parameters.
-     *
-     *    
+     *  - driver  : The type of backend driver. One of "mock", "php", "pear",
+     *              "horde", "horde-socket", and "roundcube".
+     *  - params  : Backend specific connection parameters.
+     *  - logger  : An optional log handler.
+     *  - timelog : An optional time keeping log handler.
      * </pre>
      *
      * @return Horde_Kolab_Storage_Driver The storage handler.
@@ -95,38 +95,47 @@ class Horde_Kolab_Storage_Factory
         } else {
             $config = array();
         }
+        if (!empty($params['timelog'])) {
+            $timer = new Horde_Support_Timer();
+            $timer->push();
+        }
         switch ($params['driver']) {
         case 'mock':
             $config['data'] = array('user/test' => array());
-            return new Horde_Kolab_Storage_Driver_Mock($this, $config);
+            $driver = new Horde_Kolab_Storage_Driver_Mock($this, $config);
+            break;
         case 'horde':
             $config['hostspec'] = $config['host'];
             unset($config['host']);
-            return new Horde_Kolab_Storage_Driver_Imap(
+            $driver = new Horde_Kolab_Storage_Driver_Imap(
                 new Horde_Imap_Client_Socket(
                     $config
                 ),
                 $this
             );
+            break;
         case 'horde-php':
             $config['hostspec'] = $config['host'];
             unset($config['host']);
-            return new Horde_Kolab_Storage_Driver_Imap(
+            $driver = new Horde_Kolab_Storage_Driver_Imap(
                 new Horde_Imap_Client_Cclient(
                     $config
                 ),
                 $this
             );
+            break;
         case 'php':
-            return new Horde_Kolab_Storage_Driver_Cclient($this, $config);
+            $driver = new Horde_Kolab_Storage_Driver_Cclient($this, $config);
+            break;
         case 'pear':
             $client = new Net_IMAP($config['host']);
             Horde_Kolab_Storage_Exception_Pear::catchError(
                 $client->login($config['username'], $config['password'])
             );
-            return new Horde_Kolab_Storage_Driver_Pear(
+            $driver = new Horde_Kolab_Storage_Driver_Pear(
                 $client, $this, $config
             );
+            break;
         case 'roundcube':
             $client = new rcube_imap_generic();
             $client->connect(
@@ -139,9 +148,10 @@ class Horde_Kolab_Storage_Factory
                     'force_caps' => false,
                 )
             );
-            return new Horde_Kolab_Storage_Driver_Rcube(
+            $driver = new Horde_Kolab_Storage_Driver_Rcube(
                 $client, $this, $config
             );
+            break;
         default:
             throw new Horde_Kolab_Storage_Exception(
                 sprintf(
@@ -152,6 +162,23 @@ class Horde_Kolab_Storage_Factory
                 )
             );
         }
+        if (!empty($params['logger'])) {
+            $driver = new Horde_Kolab_Storage_Driver_Decorator_Log(
+                $driver, $params['logger']
+            );
+        }
+        if (!empty($params['timelog'])) {
+            $params['timelog']->info(
+                sprintf(
+                    'REQUEST OUT IMAP: %s ms [construct]',
+                    floor($timer->pop() * 1000)
+                )
+            );
+            $driver = new Horde_Kolab_Storage_Driver_Decorator_Timer(
+                $driver, $timer, $params['timelog']
+            );
+        }
+        return $driver;
     }
 
     /**
index a3a74c0..8dc40a2 100644 (file)
@@ -31,8 +31,8 @@
   <email>jan@horde.org</email>
   <active>yes</active>
  </lead>
- <date>2010-12-21</date>
- <time>20:59:39</time>
+ <date>2010-12-22</date>
+ <time>06:20:15</time>
  <version>
   <release>0.4.0</release>
   <api>0.1.0</api>
@@ -80,6 +80,7 @@
         <dir name="Decorator">
          <file name="Base.php" role="php" />
          <file name="Log.php" role="php" />
+         <file name="Timer.php" role="php" />
         </dir> <!-- /lib/Horde/Kolab/Storage/Driver/Decorator -->
         <file name="Base.php" role="php" />
         <file name="Cclient.php" role="php" />
         </dir> <!-- /lib/Horde/Kolab/Storage/List/Decorator -->
         <file name="Base.php" role="php" />
        </dir> <!-- /lib/Horde/Kolab/Storage/List -->
+       <file name="#Factory.php#" role="php" />
        <file name="Base.php" role="php" />
        <file name="Cache.php" role="php" />
        <file name="Data.php" role="php" />
          <file name="LogTest.php" role="test" />
         </dir> <!-- /test/Horde/Kolab/Storage/Unit/Decorator -->
         <dir name="Driver">
+         <dir name="Decorator">
+          <file name="LogTest.php" role="test" />
+         </dir> <!-- /test/Horde/Kolab/Storage/Unit/Driver/Decorator -->
          <file name="CclientTest.php" role="test" />
          <file name="ImapTest.php" role="test" />
          <file name="MockTest.php" role="test" />
     <name>Imap_Client</name>
     <channel>pear.horde.org</channel>
    </package>
+   <package>
+    <name>Support</name>
+    <channel>pear.horde.org</channel>
+   </package>
    <extension>
     <name>imap</name>
    </extension>
    <install as="Horde/Kolab/Storage/list.php" name="examples/Horde/Kolab/Storage/list.php" />
    <install as="Horde/Kolab/Storage.php" name="lib/Horde/Kolab/Storage.php" />
    <install as="Horde/Kolab/Storage_Old.php" name="lib/Horde/Kolab/Storage_Old.php" />
+   <install as="Horde/Kolab/Storage/#Factory.php#" name="lib/Horde/Kolab/Storage/#Factory.php#" />
    <install as="Horde/Kolab/Storage/Base.php" name="lib/Horde/Kolab/Storage/Base.php" />
    <install as="Horde/Kolab/Storage/Cache.php" name="lib/Horde/Kolab/Storage/Cache.php" />
    <install as="Horde/Kolab/Storage/Data.php" name="lib/Horde/Kolab/Storage/Data.php" />
    <install as="Horde/Kolab/Storage/Driver/Rcube.php" name="lib/Horde/Kolab/Storage/Driver/Rcube.php" />
    <install as="Horde/Kolab/Storage/Driver/Decorator/Base.php" name="lib/Horde/Kolab/Storage/Driver/Decorator/Base.php" />
    <install as="Horde/Kolab/Storage/Driver/Decorator/Log.php" name="lib/Horde/Kolab/Storage/Driver/Decorator/Log.php" />
+   <install as="Horde/Kolab/Storage/Driver/Decorator/Timer.php" name="lib/Horde/Kolab/Storage/Driver/Decorator/Timer.php" />
    <install as="Horde/Kolab/Storage/Exception/Pear.php" name="lib/Horde/Kolab/Storage/Exception/Pear.php" />
    <install as="Horde/Kolab/Storage/Folder/Base.php" name="lib/Horde/Kolab/Storage/Folder/Base.php" />
    <install as="Horde/Kolab/Storage/Folder/Cached.php" name="lib/Horde/Kolab/Storage/Folder/Cached.php" />
    <install as="Horde/Kolab/Storage/Unit/Driver/ImapTest.php" name="test/Horde/Kolab/Storage/Unit/Driver/ImapTest.php" />
    <install as="Horde/Kolab/Storage/Unit/Driver/MockTest.php" name="test/Horde/Kolab/Storage/Unit/Driver/MockTest.php" />
    <install as="Horde/Kolab/Storage/Unit/Driver/PearTest.php" name="test/Horde/Kolab/Storage/Unit/Driver/PearTest.php" />
+   <install as="Horde/Kolab/Storage/Unit/Driver/Decorator/LogTest.php" name="test/Horde/Kolab/Storage/Unit/Driver/Decorator/LogTest.php" />
    <install as="Horde/Kolab/Storage/Unit/Folder/NamespaceTest.php" name="test/Horde/Kolab/Storage/Unit/Folder/NamespaceTest.php" />
    <install as="Horde/Kolab/Storage/Unit/List/BaseTest.php" name="test/Horde/Kolab/Storage/Unit/List/BaseTest.php" />
    <install as="Horde/Kolab/Storage/Unit/List/Decorator/LogTest.php" name="test/Horde/Kolab/Storage/Unit/List/Decorator/LogTest.php" />
     <release>alpha</release>
     <api>alpha</api>
    </stability>
-   <date>2010-12-21</date>
+   <date>2010-12-22</date>
    <license uri="http://www.gnu.org/copyleft/lesser.html">LGPL</license>
    <notes>
 * Added namespace support (Bug #6691).
index 12ca1f2..e60601a 100644 (file)
@@ -94,4 +94,16 @@ extends PHPUnit_Framework_TestCase
         }
         $this->assertTrue($found);
     }
+
+    protected function assertLogRegExp($regular_expression)
+    {
+        $found = false;
+        foreach ($this->logHandler->events as $event) {
+            if (preg_match($regular_expression, $event['message'], $matches) !== false) {
+                $found = true;
+                break;
+            }
+        }
+        $this->assertTrue($found);
+    }
 }
diff --git a/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/Driver/Decorator/LogTest.php b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/Driver/Decorator/LogTest.php
new file mode 100644 (file)
index 0000000..1753035
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+/**
+ * Test the log decorator for the backend drivers.
+ *
+ * PHP version 5
+ *
+ * @category   Kolab
+ * @package    Kolab_Storage
+ * @subpackage UnitTests
+ * @author     Gunnar Wrobel <wrobel@pardus.de>
+ * @license    http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link       http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../../../Autoload.php';
+
+/**
+ * Test the log decorator for the backend drivers.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category   Kolab
+ * @package    Kolab_Storage
+ * @subpackage UnitTests
+ * @author     Gunnar Wrobel <wrobel@pardus.de>
+ * @license    http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link       http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Unit_Driver_Decorator_LogTest
+extends Horde_Kolab_Storage_TestCase
+{
+    public function testGetMailboxesLogsEntry()
+    {
+        $driver = new Horde_Kolab_Storage_Driver_Decorator_Log(
+            $this->getNullMock(),
+            $this->getMockLogger()
+        );
+        $driver->getMailboxes();
+        $this->assertLogCount(2);
+    }
+
+    public function testGetMailboxesFolderCount()
+    {
+        $driver = new Horde_Kolab_Storage_Driver_Decorator_Log(
+            $this->getTwoFolderMock(),
+            $this->getMockLogger()
+        );
+        $driver->getMailboxes();
+        $this->assertLogContains('Driver "Horde_Kolab_Storage_Driver_Mock": List contained 2 folders.');
+    }
+}
diff --git a/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/Driver/Decorator/TimerTest.php b/framework/Kolab_Storage/test/Horde/Kolab/Storage/Unit/Driver/Decorator/TimerTest.php
new file mode 100644 (file)
index 0000000..7724bca
--- /dev/null
@@ -0,0 +1,66 @@
+<?php
+/**
+ * Test the stop watch decorator for the backend drivers.
+ *
+ * PHP version 5
+ *
+ * @category   Kolab
+ * @package    Kolab_Storage
+ * @subpackage UnitTests
+ * @author     Gunnar Wrobel <wrobel@pardus.de>
+ * @license    http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link       http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+
+/**
+ * Prepare the test setup.
+ */
+require_once dirname(__FILE__) . '/../../../Autoload.php';
+
+/**
+ * Test the stop watch decorator for the backend drivers.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (LGPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/lgpl.html.
+ *
+ * @category   Kolab
+ * @package    Kolab_Storage
+ * @subpackage UnitTests
+ * @author     Gunnar Wrobel <wrobel@pardus.de>
+ * @license    http://www.fsf.org/copyleft/lgpl.html LGPL
+ * @link       http://pear.horde.org/index.php?package=Kolab_Storage
+ */
+class Horde_Kolab_Storage_Unit_Driver_Decorator_TimerTest
+extends Horde_Kolab_Storage_TestCase
+{
+    public function setUp()
+    {
+        if (!class_exists('Horde_Support_Timer')) {
+            $this->markTestSkipped('The "Horde_Support" package seems to be missing!');
+        }
+    }
+
+    public function testGetMailboxesLogsEntry()
+    {
+        $driver = new Horde_Kolab_Storage_Driver_Decorator_Timer(
+            $this->getNullMock(),
+            new Horde_Support_Timer(),
+            $this->getMockLogger()
+        );
+        $driver->getMailboxes();
+        $this->assertLogCount(1);
+    }
+
+    public function testGetMailboxesFolderCount()
+    {
+        $driver = new Horde_Kolab_Storage_Driver_Decorator_Timer(
+            $this->getTwoFolderMock(),
+            new Horde_Support_Timer(),
+            $this->getMockLogger()
+        );
+        $driver->getMailboxes();
+        $this->assertLogRegExp('/REQUEST OUT IMAP:.*getMailboxes.*/');
+    }
+}
index e8098d4..d3cfd70 100644 (file)
@@ -122,5 +122,35 @@ extends Horde_Kolab_Storage_TestCase
         );
     }
 
+    public function testTimerDecoration()
+    {
+        $factory = new Horde_Kolab_Storage_Factory();
+        $logger = $this->getMockLogger();
+        $this->assertInstanceOf(
+            'Horde_Kolab_Storage_Driver_Decorator_Timer',
+            $factory->createDriverFromParams(
+                array(
+                    'driver' => 'mock',
+                    'logger' => $logger,
+                    'timelog' => $logger,
+                )
+            )
+        );
+    }
+
+    public function testTimedDriverConstruction()
+    {
+        $factory = new Horde_Kolab_Storage_Factory();
+        $logger = $this->getMockLogger();
+        $factory->createDriverFromParams(
+            array(
+                'driver' => 'mock',
+                'logger' => $logger,
+                'timelog' => $logger,
+            )
+        );
+        $this->assertLogRegExp('/REQUEST OUT IMAP:.*construct.*/');
+    }
+
 
 }