From c3b52417695d11fd525bddf76ca5af4918a2342e Mon Sep 17 00:00:00 2001 From: Gunnar Wrobel Date: Wed, 10 Feb 2010 09:39:29 +0100 Subject: [PATCH] Add the possibility to initialize a test suite with a static init() method 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. --- .../Kolab_Session/test/Horde/Kolab/Session/AllTests.php | 4 +++- framework/Test/lib/Horde/Test/AllTests.php | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/framework/Kolab_Session/test/Horde/Kolab/Session/AllTests.php b/framework/Kolab_Session/test/Horde/Kolab/Session/AllTests.php index 2e1aa223f..0e58c14f4 100644 --- a/framework/Kolab_Session/test/Horde/Kolab/Session/AllTests.php +++ b/framework/Kolab_Session/test/Horde/Kolab/Session/AllTests.php @@ -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(); } diff --git a/framework/Test/lib/Horde/Test/AllTests.php b/framework/Test/lib/Horde/Test/AllTests.php index 437645861..f85863e5c 100644 --- a/framework/Test/lib/Horde/Test/AllTests.php +++ b/framework/Test/lib/Horde/Test/AllTests.php @@ -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. -- 2.11.0