improved test config handling
authorPhilipp Schüle <p.schuele@metaways.de>
Thu, 12 May 2016 15:22:14 +0000 (17:22 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 12 May 2016 15:48:15 +0000 (17:48 +0200)
* adds lazy loading for config
* use test credentials in caldav test
* always use getConfig of TestServer instance

Change-Id: If8e33fcd99030bfdb7a9902d3a103161f6b69f7a
Reviewed-on: http://gerrit.tine20.com/customers/3152
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Calendar/Import/CalDAVTest.php
tests/tine20/TestCase.php
tests/tine20/TestServer.php

index 5371fcc..94b4644 100644 (file)
@@ -28,11 +28,12 @@ class Calendar_Import_CalDAVTest extends Calendar_TestCase
      */
     protected function _getUit()
     {
+        $testCredentials = TestServer::getInstance()->getTestCredentials();
         if ($this->_uit === null) {
             $caldavClientOptions = array(
                 'baseUri' => 'localhost',
                 'userName' => Tinebase_Core::getUser()->accountLoginName,
-                'password' => Zend_Registry::get('testConfig')->password, // TODO use credential cache?
+                'password' => $testCredentials['password'],
             );
             $this->_uit = new Calendar_Import_CalDAV_ClientMock($caldavClientOptions, 'MacOSX');
             $this->_uit->setVerifyPeer(false);
index 6ae7211..a68624a 100644 (file)
@@ -330,7 +330,7 @@ abstract class TestCase extends PHPUnit_Framework_TestCase
      */
     protected function _getEmailAddress()
     {
-        $testConfig = Zend_Registry::get('testConfig');
+        $testConfig = TestServer::getInstance()->getConfig();
         return ($testConfig->email) ? $testConfig->email : Tinebase_Core::getUser()->accountEmailAddress;
     }
     
index dd49b1d..c511d6d 100644 (file)
@@ -51,22 +51,9 @@ class TestServer
     public function initFramework()
     {
         $this->setWhiteAndBlacklists();
-        
-        // get config
-        $configData = @include('phpunitconfig.inc.php');
-        if ($configData === false) {
-            $configData = include('config.inc.php');
-        }
-        if ($configData === false) {
-            die ('central configuration file config.inc.php not found in includepath: ' . get_include_path());
-        }
-        $config = new Zend_Config($configData);
 
-        Zend_Registry::set('testConfig', $config);
+        $config = $this->getConfig();
 
-        $_SERVER['DOCUMENT_ROOT'] = $config->docroot;
-        $_SERVER['REQUEST_URI'] = '';
-        
         Tinebase_Core::startCoreSession();
         
         Tinebase_Core::initFramework();
@@ -150,10 +137,10 @@ class TestServer
      */
     public function setTestUserEmail()
     {
-        if (Zend_Registry::get('testConfig')->email) {
+        if ($this->getConfig()->email) {
             // set email of test user contact
             $testUserContact = Addressbook_Controller_Contact::getInstance()->getContactByUserId(Tinebase_Core::getUser()->getId());
-            $testUserContact->email = Zend_Registry::get('testConfig')->email;
+            $testUserContact->email = $this->getConfig()->email;
             Addressbook_Controller_Contact::getInstance()->update($testUserContact, FALSE);
         }
     }
@@ -165,6 +152,23 @@ class TestServer
      */
     public function getConfig()
     {
+        if (! Zend_Registry::isRegistered('testConfig')) {
+            // get config
+            $configData = @include('phpunitconfig.inc.php');
+            if ($configData === false) {
+                $configData = include('config.inc.php');
+            }
+            if ($configData === false) {
+                die ('central configuration file config.inc.php not found in includepath: ' . get_include_path());
+            }
+            $config = new Zend_Config($configData);
+
+            Zend_Registry::set('testConfig', $config);
+
+            $_SERVER['DOCUMENT_ROOT'] = $config->docroot;
+            $_SERVER['REQUEST_URI'] = '';
+        }
+
         return Zend_Registry::get('testConfig');
     }