From: Michael J. Rubinsky Date: Wed, 14 Apr 2010 19:56:50 +0000 (-0400) Subject: Use phpunit's mock object for the connector. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=52a57b986d430641bb8e7b01245de5eb242284fe;p=horde.git Use phpunit's mock object for the connector. 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. --- diff --git a/framework/ActiveSync/test/Horde/ActiveSync/ContactTest.php b/framework/ActiveSync/test/Horde/ActiveSync/ContactTest.php new file mode 100644 index 000000000..e54be9c29 --- /dev/null +++ b/framework/ActiveSync/test/Horde/ActiveSync/ContactTest.php @@ -0,0 +1,15 @@ + + * @category Horde + * @package Horde_ActiveSync + */ +class Horde_ActiveSync_ContactTest extends Horde_Test_Case +{ + public function testBlah() + { + $this->markTestIncomplete(); + } +} diff --git a/framework/ActiveSync/test/Horde/ActiveSync/FileStateTest.php b/framework/ActiveSync/test/Horde/ActiveSync/FileStateTest.php index 562258751..1ba54e356 100644 --- a/framework/ActiveSync/test/Horde/ActiveSync/FileStateTest.php +++ b/framework/ActiveSync/test/Horde/ActiveSync/FileStateTest.php @@ -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)); diff --git a/framework/ActiveSync/test/Horde/ActiveSync/FolderSyncTest.php b/framework/ActiveSync/test/Horde/ActiveSync/FolderSyncTest.php index 4fc053b9a..e60189231 100644 Binary files a/framework/ActiveSync/test/Horde/ActiveSync/FolderSyncTest.php and b/framework/ActiveSync/test/Horde/ActiveSync/FolderSyncTest.php differ diff --git a/framework/ActiveSync/test/Horde/ActiveSync/HordeDriverTest.php b/framework/ActiveSync/test/Horde/ActiveSync/HordeDriverTest.php index d7bf5cc03..430bcd70b 100644 --- a/framework/ActiveSync/test/Horde/ActiveSync/HordeDriverTest.php +++ b/framework/ActiveSync/test/Horde/ActiveSync/HordeDriverTest.php @@ -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 index 7fe479732..000000000 --- a/framework/ActiveSync/test/Horde/ActiveSync/fixtures/MockConnector.php +++ /dev/null @@ -1,76 +0,0 @@ - - * @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