Use phpunit's mock object for the connector.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 14 Apr 2010 19:56:50 +0000 (15:56 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 14 Apr 2010 19:56:50 +0000 (15:56 -0400)
No longer need this special mock connector now that we don't do the
various conversions in this package.  Also clean up some of the tests a bit.

framework/ActiveSync/test/Horde/ActiveSync/ContactTest.php [new file with mode: 0644]
framework/ActiveSync/test/Horde/ActiveSync/FileStateTest.php
framework/ActiveSync/test/Horde/ActiveSync/FolderSyncTest.php
framework/ActiveSync/test/Horde/ActiveSync/HordeDriverTest.php
framework/ActiveSync/test/Horde/ActiveSync/fixtures/MockConnector.php [deleted file]

diff --git a/framework/ActiveSync/test/Horde/ActiveSync/ContactTest.php b/framework/ActiveSync/test/Horde/ActiveSync/ContactTest.php
new file mode 100644 (file)
index 0000000..e54be9c
--- /dev/null
@@ -0,0 +1,15 @@
+<?php
+/*
+ * Unit tests for the horde backend
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @category Horde
+ * @package Horde_ActiveSync
+ */
+class Horde_ActiveSync_ContactTest extends Horde_Test_Case
+{
+    public function testBlah()
+    {
+        $this->markTestIncomplete();
+    }
+}
index 5622587..1ba54e3 100644 (file)
@@ -6,8 +6,6 @@
  * @category Horde
  * @package Horde_ActiveSync
  */
-require_once dirname(__FILE__) . '/fixtures/MockConnector.php';
-
 //FIXME: This can be removed once all the constants are class-constants
 require_once dirname(__FILE__) . '/../../../lib/Horde/ActiveSync.php';
 class Horde_ActiveSync_FileStateTest extends Horde_Test_Case
@@ -18,55 +16,19 @@ class Horde_ActiveSync_FileStateTest extends Horde_Test_Case
      */
     public function testCollectionSyncState()
     {
-        $contact = array(
-            '__key' => '9b07c14b086932e69cc7eb1baed0cc87',
-            '__owner' => 'mike',
-            '__type' => 'Object',
-            '__members' => '',
-            '__uid' => '20070112030611.62g1lg5nry80@test.theupstairsroom.com',
-            'firstname' => 'Michael',
-            'lastname' => 'Rubinsky',
-            'middlenames' => 'Joseph',
-            'namePrefix' => 'Dr',
-            'nameSuffix' => 'PharmD',
-            'name' => 'Michael Joseph Rubinsky',
-            'alias' => 'Me',
-            'birthday' => '1970-03-20',
-            'homeStreet' => '123 Main St.',
-            'homePOBox' => '',
-            'homeCity' => 'Anywhere',
-            'homeProvince' => 'NJ',
-            'homePostalCode' => '08080',
-            'homeCountry' => 'US',
-            'workStreet' => 'Kings Hwy',
-            'workPOBox' => '',
-            'workCity' => 'Somewhere',
-            'workProvince' => 'NJ',
-            'workPostalCode' => '08052',
-            'workCountry' => 'US',
-            'timezone' => 'America/New_York',
-            'email' => 'mrubinsk@horde.org',
-            'homePhone' => '(856)555-1234',
-            'workPhone' => '(856)555-5678',
-            'cellPhone' => '(609)555-9876',
-            'fax' => '',
-            'pager' => '',
-            'title' => '',
-            'role' => '',
-            'company' => '',
-            'category' => '',
-            'notes' => '',
-            'website' => '',
-            'freebusyUrl' => '',
-            'pgpPublicKey' => '',
-            'smimePublicKey' => '',
-        );
-
         /* Create a mock driver with desired return values */
         $fixture = array('contacts_list' => array('20070112030611.62g1lg5nry80@test.theupstairsroom.com'),
-                         'contacts_getActionTimestamp' => 0,
-                         'contacts_export' => $contact);
-        $connector = new Horde_ActiveSync_MockConnector(array('fixture' => $fixture));
+                         'contacts_getActionTimestamp' => 0);
+
+        $connector = $this->getMockSkipConstructor('Horde_ActiveSync_Driver_Horde_Connector_Registry');
+        $connector->expects($this->exactly(2))
+                ->method('contacts_list')
+                ->will($this->returnValue($fixture['contacts_list']));
+
+        $connector->expects($this->exactly(1))
+                ->method('contacts_getActionTimestamp')
+                ->will($this->returnValue($fixture['contacts_getActionTimestamp']));
+
         $state = new Horde_ActiveSync_State_File(array('stateDir' => './'));
         $driver = new Horde_ActiveSync_Driver_Horde(array('connector' => $connector,
                                                           'state_basic' => $state));
index 4fc053b..e601892 100644 (file)
Binary files a/framework/ActiveSync/test/Horde/ActiveSync/FolderSyncTest.php and b/framework/ActiveSync/test/Horde/ActiveSync/FolderSyncTest.php differ
index d7bf5cc..430bcd7 100644 (file)
@@ -6,7 +6,6 @@
  * @category Horde
  * @package Horde_ActiveSync
  */
-require_once dirname(__FILE__) . '/fixtures/MockConnector.php';
 class Horde_ActiveSync_HordeDriverTest extends Horde_Test_Case
 {
     /**
@@ -38,17 +37,20 @@ class Horde_ActiveSync_HordeDriverTest extends Horde_Test_Case
 
     /**
      * Test that Horde_ActiveSync_Driver_Horde#getMessageList() returns expected
-     * data structures. Uses mock data via the MockConnector
+     * data structures.
      *
      */
     public function testGetMessageList()
     {
         // Test Contacts - simulates returning two contacts, both of which have no history modify entries.
         $fixture = array('contacts_list' => array('20070112030603.249j42k3k068@test.theupstairsroom.com',
-                                                          '20070112030611.62g1lg5nry80@test.theupstairsroom.com'),
+                                                  '20070112030611.62g1lg5nry80@test.theupstairsroom.com'),
                          'contacts_getActionTimestamp' => 0);
 
-        $connector = new Horde_ActiveSync_MockConnector(array('fixture' => $fixture));
+        $connector = $this->getMockSkipConstructor('Horde_ActiveSync_Driver_Horde_Connector_Registry');
+        $connector->expects($this->once())->method('contacts_list')->will($this->returnValue($fixture['contacts_list']));
+        $connector->expects($this->exactly(2))->method('contacts_getActionTimestamp')->will($this->returnValue($fixture['contacts_getActionTimestamp']));
+
         $state = $this->getMockSkipConstructor('Horde_ActiveSync_State_File');
         $driver = new Horde_ActiveSync_Driver_Horde(array('connector' => $connector,
                                                           'state_basic' => $state));
@@ -91,12 +93,18 @@ class Horde_ActiveSync_HordeDriverTest extends Horde_Test_Case
         }
 
         /* Mock the registry connector */
-        $fixture = array(
-            'contacts_export' => $contact,
-            'calendar_export' => $event,
-            'tasks_export' => $task
-        );
-        $connector = new Horde_ActiveSync_MockConnector(array('fixture' => $fixture));
+        $connector = $this->getMockSkipConstructor('Horde_ActiveSync_Driver_Horde_Connector_Registry');
+        $connector->expects($this->once())
+                ->method('contacts_export')
+                ->will($this->returnValue($contact));
+
+        $connector->expects($this->once())
+                ->method('calendar_export')
+                ->will($this->returnValue($event));
+
+        $connector->expects($this->once())
+                ->method('tasks_export')
+                ->will($this->returnValue($task));
 
         /* We don't need to remember any state for this test, mock it */
         $state = $this->getMockSkipConstructor('Horde_ActiveSync_State_File');
@@ -126,12 +134,22 @@ class Horde_ActiveSync_HordeDriverTest extends Horde_Test_Case
         $this->markTestIncomplete('Test still being written');
         /* Setup mock connector method return values for adding a new contact */
         $connector = $this->getMockSkipConstructor('Horde_ActiveSync_Driver_Horde_Connector_Registry');
-        $connector->expects($this->once())->method('contacts_import')->will($this->returnValue(1));
-        $connector->expects($this->at(1))->method('contacts_getActionTimestamp')->will($this->returnValue(array('todo')));
+        $connector->expects($this->once())
+                ->method('contacts_import')
+                ->will($this->returnValue(1));
+
+        $connector->expects($this->at(1))
+                ->method('contacts_getActionTimestamp')
+                ->will($this->returnValue(array('todo')));
 
         /* Setup mock connector return for modifying an existing contact */
-        $connector->expects($this->once())->method('contacts_replace')->will($this->returnValue(2));
-        $connector->expects($this->at(1))->method('contacts_getActionTimestamp')->will($this->returnValue(array('todo')));
+        $connector->expects($this->once())
+                ->method('contacts_replace')
+                ->will($this->returnValue(2));
+
+        $connector->expects($this->at(1))
+                ->method('contacts_getActionTimestamp')
+                ->will($this->returnValue(array('todo')));
 
         /* TODO: appointments and todos */
 
@@ -185,7 +203,13 @@ class Horde_ActiveSync_HordeDriverTest extends Horde_Test_Case
     {
         $registry = $this->getMockSkipConstructor('Horde_Registry');
         $state = $this->getMockSkipConstructor('Horde_ActiveSync_State_File');
-        $connector = new Horde_ActiveSync_MockConnector(array('fixture' => array('horde_listApis' => array('horde', 'contacts', 'calendar', 'tasks'))));
+
+        /* Mock registry connector */
+        $connector = $this->getMockSkipConstructor('Horde_ActiveSync_Driver_Horde_Connector_Registry');
+        $connector->expects($this->once())
+                ->method('horde_listApis')
+                ->will($this->returnValue(array('horde', 'contacts', 'calendar', 'tasks')));
+
         $driver = new Horde_ActiveSync_Driver_Horde(array('connector' => $connector,
                                                           'state_basic' => $state));
         $results = $driver->getFolderList();
diff --git a/framework/ActiveSync/test/Horde/ActiveSync/fixtures/MockConnector.php b/framework/ActiveSync/test/Horde/ActiveSync/fixtures/MockConnector.php
deleted file mode 100644 (file)
index 7fe4797..0000000
+++ /dev/null
@@ -1,76 +0,0 @@
-<?php
-/**
- * Mock connector for unit testing horde backend.
- *
- * @author Michael J. Rubinsky <mrubinsk@horde.org>
- * @category Horde
- * @package Horde_ActiveSync
- */
-class Horde_ActiveSync_MockConnector
-{
-    public function __construct($params = array())
-    {
-        $this->_fixture = $params['fixture'];
-    }
-
-    public function __call($name, $args)
-    {
-        if (empty($this->_fixture[$name])) {
-            return 0;
-        }
-        return $this->_fixture[$name];
-    }
-
-    public function contacts_import($content)
-    {
-        // $content is a vCard that should eq:
-        $expected = array(
-            'firstname' => 'Michael',
-            'lastname' => 'Rubinsky',
-            'middlenames' => 'Joseph',
-            'namePrefix' => '',
-            'nameSuffix' => '',
-            'name' => 'Michael Joseph Rubinsky',
-            'birthday' => '1970-03-20',
-            'homeStreet' => '123 Main St.',
-            'homeCity' => 'Anywhere',
-            'homeProvince' => 'NJ',
-            'homePostalCode' => '08080',
-            'homeCountry' => '',
-            'workStreet' => '',
-            'workCity' => '',
-            'workProvince' => '',
-            'workCountry' => '',
-            //'timezone' => '',
-            'email' => 'mrubinsk@horde.org',
-            'homePhone' => '(856)555-1234',
-            'workPhone' => '(856)555-5678',
-            'cellPhone' => '(609)555-9876',
-            'fax' => '',
-            'pager' => '',
-            'title' => '',
-            'company' => '',
-            //'category' => '',
-            'notes' => '',
-            'website' => '',
-        );
-
-        foreach ($expected as $key => $value) {
-            if ($content[$key] != $value) {
-                throw new Horde_ActiveSync_Exception('Expected value ' . $value . ' did not match received value ' . $content[$key]);
-            }
-        }
-
-        return 'xx.xx@localhost';
-    }
-
-    public function contacts_replace()
-    {
-        
-    }
-
-    public function calendar_import()
-    {
-
-    }
-}
\ No newline at end of file