Add the possibility to initialize a test suite with a static init() method
authorGunnar Wrobel <wrobel@temple.(none)>
Wed, 10 Feb 2010 08:39:29 +0000 (09:39 +0100)
committerGunnar Wrobel <wrobel@temple.(none)>
Wed, 10 Feb 2010 08:58:49 +0000 (09:58 +0100)
rather than using the main() method.

It is not sufficient to setup the static AllTests class via the main method.
This only allows to directly execute the AllTests.php file by parsing it
with php. Using phpunit is not possible as this will only use the suite()
method to grab the test suite.

It would still be better to use late static binding here but the added
method should be enough to allow running the tests in both ways.

The AllTests.php in Kolab_Session demonstrates how to use the init() method.

framework/Kolab_Session/test/Horde/Kolab/Session/AllTests.php
framework/Test/lib/Horde/Test/AllTests.php

index 2e1aa22..0e58c14 100644 (file)
@@ -43,6 +43,8 @@ class Horde_Kolab_Session_AllTests extends Horde_Test_AllTests
 {
 }
 
+Horde_Kolab_Session_AllTests::init('Horde_Kolab_Session', __FILE__);
+
 if (PHPUnit_MAIN_METHOD == 'Horde_Kolab_Session_AllTests::main') {
-    Horde_Kolab_Session_AllTests::main('Horde_Kolab_Session', __FILE__);
+    Horde_Kolab_Session_AllTests::main();
 }
index 4376458..f85863e 100644 (file)
@@ -41,6 +41,20 @@ class Horde_Test_AllTests
     }
 
    /**
+    * Initialize the test suite class.
+    *
+    * @param string $package The name of the package tested by this suite.
+    * @param string $file    The path of the AllTests class.
+    *
+    * @return NULL
+    */
+    public static function init($package, $file)
+    {
+        self::$_package = $package;
+        self::$_file = $file;
+    }
+
+   /**
     * Collect the unit tests of this directory into a new suite.
     *
     * @return PHPUnit_Framework_TestSuite The test suite.