0011856: setup tests: make phpunitconfig.inc.php optional
authorPhilipp Schüle <p.schuele@metaways.de>
Thu, 12 May 2016 15:24:11 +0000 (17:24 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Fri, 13 May 2016 12:49:49 +0000 (14:49 +0200)
improves setup tests bootstrap

* adds bootstrap.php
* extends "normal" TestServer
* allows to get test credentials from phpunit config
 OR config.inc.php

https://forge.tine20.org/view.php?id=11856

Change-Id: I05104b0bb847d24946d676da84ace6eed0e3335f
Reviewed-on: http://gerrit.tine20.com/customers/3153
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/setup/Setup/ControllerTest.php
tests/setup/Setup/JsonTest.php
tests/setup/Setup/TestServer.php
tests/setup/TestHelper.php
tests/setup/bootstrap.php [new file with mode: 0644]
tests/setup/phpunit.xml
tests/tine20/TestCase.php
tests/tine20/TestHelper.php
tests/tine20/TestServer.php
tine20/Setup/Controller.php

index 1b483a0..f9905a2 100644 (file)
@@ -25,18 +25,6 @@ class Setup_ControllerTest extends PHPUnit_Framework_TestCase
     protected $_uit = null;
     
     /**
-     * Runs the test methods of this class.
-     *
-     * @access public
-     * @static
-     */
-    public static function main()
-    {
-        $suite  = new PHPUnit_Framework_TestSuite('Tine 2.0 Setup Controller Tests');
-        PHPUnit_TextUI_TestRunner::run($suite);
-    }
-
-    /**
      * Sets up the fixture.
      * This method is called before a test is executed.
      *
@@ -55,11 +43,12 @@ class Setup_ControllerTest extends PHPUnit_Framework_TestCase
      */
     protected function tearDown()
     {
+        $testCredentials = Setup_TestServer::getInstance()->getTestCredentials();
         $this->_installAllApplications(array(
             'defaultAdminGroupName' => 'Administrators',
             'defaultUserGroupName'  => 'Users',
-            'adminLoginName'        => Tinebase_Core::get('testconfig')->username,
-            'adminPassword'         => Tinebase_Core::get('testconfig')->password,
+            'adminLoginName'        => $testCredentials['username'],
+            'adminPassword'         => $testCredentials['password'],
         ));
     }
        
@@ -173,11 +162,12 @@ class Setup_ControllerTest extends PHPUnit_Framework_TestCase
     public function testInstallGroupNameOptions()
     {
         $this->_uninstallAllApplications();
+        $testCredentials = Setup_TestServer::getInstance()->getTestCredentials();
         $this->_installAllApplications(array(
             'defaultAdminGroupName' => 'phpunit-admins',
             'defaultUserGroupName'  => 'phpunit-users',
-            'adminLoginName'        => Tinebase_Core::get('testconfig')->username,
-            'adminPassword'         => Tinebase_Core::get('testconfig')->password,
+            'adminLoginName'        => $testCredentials['username'],
+            'adminPassword'         => $testCredentials['password'],
         ));
         $adminUser = Tinebase_Core::get('currentAccount');
         $this->assertEquals('phpunit-admins', Tinebase_User::getBackendConfiguration(Tinebase_User::DEFAULT_ADMIN_GROUP_NAME_KEY));
index 867f61c..9b9e50f 100644 (file)
@@ -304,9 +304,10 @@ class Setup_JsonTest extends PHPUnit_Framework_TestCase
     {
         $installableApplications = Setup_Controller::getInstance()->getInstallableApplications();
         $installableApplications = array_keys($installableApplications);
+        $testCredentials = Setup_TestServer::getInstance()->getTestCredentials();
         $this->_json->installApplications($installableApplications, array(
-            'adminLoginName'        => Tinebase_Core::get('testconfig')->username,
-            'adminPassword'         => Tinebase_Core::get('testconfig')->password,
+            'adminLoginName'        => $testCredentials['username'],
+            'adminPassword'         => $testCredentials['password'],
         ));
     }
 }
index 19085a6..751fa71 100644 (file)
@@ -5,19 +5,18 @@
  * @package     setup tests
  * @subpackage  test root
  * @license     http://www.gnu.org/licenses/agpl.html AGPL3
- * @copyright   Copyright (c) 2008 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @copyright   Copyright (c) 2008-2016 Metaways Infosystems GmbH (http://www.metaways.de)
  * @author      Cornelius Weiss <c.weiss@metaways.de>
  * 
  */
 
 /**
  * helper class
- *
  */
-class Setup_TestServer
+class Setup_TestServer extends TestServer
 {
     /**
-     * holdes the instance of the singleton
+     * holds the instance of the singleton
      *
      * @var Setup_TestServer
      */
@@ -46,11 +45,17 @@ class Setup_TestServer
     }
 
     /**
-     * init the test framework
+     * init the test frameworks
      *
      */
     public function initFramework()
     {
         Setup_Core::initFramework();
+
+        //$this->getConfig();
+
+        Tinebase_Core::startCoreSession();
+
+        Tinebase_Core::set('frameworkInitialized', true);
     }
 }
index f2162a1..cd1a9a3 100644 (file)
@@ -5,66 +5,11 @@
  * @package     setup tests
  * @subpackage  test root
  * @license     http://www.gnu.org/licenses/agpl.html AGPL3
- * @copyright   Copyright (c) 2008-2015 Metaways Infosystems GmbH (http://www.metaways.de)
+ * @copyright   Copyright (c) 2008-2016 Metaways Infosystems GmbH (http://www.metaways.de)
  * @author      Philipp Schüle <p.schuele@metaways.de>
  * 
- * @todo        refactor setup tests bootstrap
  */
 
-/*
- * Set include path
- */
-define('PATH_TO_REAL_DIR', dirname(__FILE__). '/../../tine20');
-define('PATH_TO_TINE_LIBRARY', dirname(__FILE__). '/../../tine20/library');
-define('PATH_TO_SETUP_TEST_DIR', dirname(__FILE__));
-define('PATH_TO_TEST_DIR', dirname(__FILE__) . '/../tine20');
-
-$path = array(
-    PATH_TO_REAL_DIR,
-    get_include_path(),
-    PATH_TO_SETUP_TEST_DIR,
-    PATH_TO_TEST_DIR,
-    PATH_TO_TINE_LIBRARY
-);
-
-set_include_path(implode(PATH_SEPARATOR, $path));
-
-/*
- * Set parameters  for logging (call via browser)
- * 
- * @todo put that in config.inc as well or remove that?
- */
-define('CONFIGURATION', PATH_TO_TEST_DIR."/conf.xml");
-
-/*
- * Set up basic tine 2.0 environment
- */
-require_once 'bootstrap.php';
-
-// add test paths to autoloader
-$autoloader = require 'vendor/autoload.php';
-$autoloader->set('', $path);
-
-/*
- * Set white / black lists
- */
-$phpUnitVersion = explode(' ',PHPUnit_Runner_Version::getVersionString());
-if (version_compare($phpUnitVersion[1], "3.6.0") >= 0) {
-    $filter = new PHP_CodeCoverage_Filter();
-    $filter->addDirectoryToBlacklist(dirname(__FILE__));
-} else if (version_compare($phpUnitVersion[1], "3.5.0") >= 0) {
-    PHP_CodeCoverage_Filter::getInstance()->addDirectoryToBlacklist(dirname(__FILE__));
-} else {
-    PHPUnit_Util_Filter::addDirectoryToFilter(dirname(__FILE__));
-}
-
-// get config
-$configData = include('phpunitconfig.inc.php');
-$config = new Zend_Config($configData);
-
-$_SERVER['DOCUMENT_ROOT'] = $config->docroot;
+Tinebase_Session_Abstract::setSessionEnabled('TINE20SETUPSESSID');
 
 Setup_TestServer::getInstance()->initFramework();
-
-Tinebase_Core::set('locale', new Zend_Locale($config->locale));
-Tinebase_Core::set('testconfig', $config);
diff --git a/tests/setup/bootstrap.php b/tests/setup/bootstrap.php
new file mode 100644 (file)
index 0000000..84b9133
--- /dev/null
@@ -0,0 +1,20 @@
+<?php
+require_once __DIR__ . '/../../tine20/bootstrap.php';
+
+// add path the local directory and main tine20 test dir
+$autoloader->add('', array(__DIR__ . '/../tine20', __DIR__));
+
+// TODO is this required?
+define('PATH_TO_REAL_DIR', dirname(__FILE__). '/../../tine20');
+define('PATH_TO_TINE_LIBRARY', dirname(__FILE__). '/../../tine20/library');
+define('PATH_TO_TEST_DIR', dirname(__FILE__));
+
+// phpunit wants to handle the errors / report all errors + restore the default error handler
+error_reporting(E_ALL | E_STRICT);
+restore_error_handler();
+
+// disable sending cookies
+Zend_Session::setOptions(array(
+    'use_cookies'      => 0,
+    'use_only_cookies' => 0
+));
index d5577ff..20453d7 100644 (file)
@@ -5,5 +5,6 @@
          convertWarningsToExceptions="true"
          processIsolation="false"
          stopOnFailure="false"
-         syntaxCheck="false">
+         syntaxCheck="false"
+         bootstrap="bootstrap.php">
 </phpunit>
\ No newline at end of file
index a68624a..a38029e 100644 (file)
@@ -100,8 +100,10 @@ abstract class TestCase extends PHPUnit_Framework_TestCase
         $this->_transactionId = Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb());
         
         Addressbook_Controller_Contact::getInstance()->setGeoDataForContacts(false);
-        
-        $this->_personas = Zend_Registry::get('personas');
+
+        if (Zend_Registry::isRegistered('personas')) {
+            $this->_personas = Zend_Registry::get('personas');
+        }
         
         $this->_originalTestUser = Tinebase_Core::getUser();
     }
index 37c9c2a..d74c7c3 100644 (file)
@@ -9,15 +9,18 @@
  * @author      Matthias Greiling <m.greiling@metaways.de>
  */
 
-Tinebase_Session_Abstract::setSessionEnabled('TINE20SESSID');
 
-TestServer::getInstance()->initFramework();
+// only bootstrap once
+if (! Tinebase_Core::isRegistered('frameworkInitialized') || Tinebase_Core::get('frameworkInitialized') == false) {
+    Tinebase_Session_Abstract::setSessionEnabled('TINE20SESSID');
+    TestServer::getInstance()->initFramework();
 
-TestServer::getInstance()->login();
+    TestServer::getInstance()->login();
 
-// do this after login because we need the current user
-TestServer::getInstance()->initTestUsers();
-TestServer::getInstance()->setTestUserEmail();
+    // do this after login because we need the current user
+    TestServer::getInstance()->initTestUsers();
+    TestServer::getInstance()->setTestUserEmail();
 
-// speed up tests by disabling calendar notifications
-Calendar_Controller_Event::getInstance()->sendNotifications(false);
+    // speed up tests by disabling calendar notifications
+    Calendar_Controller_Event::getInstance()->sendNotifications(false);
+}
index c511d6d..2388e67 100644 (file)
@@ -70,6 +70,8 @@ class TestServer
         
         // this is needed for session handling in unittests (deactivate Zend_Session::writeClose and others)
         Zend_Session::$_unitTestEnabled = TRUE;
+
+        Tinebase_Core::set('frameworkInitialized', true);
     }
     
     /**
index c7f3f81..cf63595 100644 (file)
@@ -1353,7 +1353,7 @@ class Setup_Controller
         // check requirements for initial install / add required apps to list
         if (! $this->isInstalled('Tinebase')) {
     
-            $minimumRequirements = array('Tinebase', 'Addressbook', 'Admin');
+            $minimumRequirements = array('Addressbook', 'Tinebase', 'Admin');
             
             foreach ($minimumRequirements as $requiredApp) {
                 if (!in_array($requiredApp, $_applications) && !$this->isInstalled($requiredApp)) {