PHP_CompatInfo/tests AllTests and conditional Test Suite ?

From: Date: Mon, 28 Jan 2008 21:15:22 +0000
Subject: PHP_CompatInfo/tests AllTests and conditional Test Suite ?
Groups: php.pear.qa 
Request: Send a blank email to pear-qa+get-4773@lists.php.net to get a copy of this message
Hi QA Team, I've just introduce something to add conditional test suite (with PHPUnit 3) only if package optional resources, are installed on the system that run the global PHP_CompatInfo test suite. I would like your opinion ! Regards Laurent See code below from CVS commit -------- Message original -------- Sujet: cvs: pear /PHP_CompatInfo/tests AllTests.php Date: Mon, 28 Jan 2008 21:06:30 -0000 De: farell@php.net ("Laurent Laville") Pour :: pear-cvs@lists.php.net Forum :: php.pear.cvs farell Mon Jan 28 21:06:30 2008 UTC Modified files:
    /pear/PHP_CompatInfo/tests	AllTests.php
Log: - Add conditional test suite if optional resources are available (packages installed) - Code to check if a package is installed came from PEAR_Info version 1.6.0 or better http://cvs.php.net/viewvc.cgi/pear/PHP_CompatInfo/tests/AllTests.php?r1=1.2&r2=1.3&diff_format=u Index: pear/PHP_CompatInfo/tests/AllTests.php diff -u pear/PHP_CompatInfo/tests/AllTests.php:1.2 pear/PHP_CompatInfo/tests/AllTests.php:1.3 --- pear/PHP_CompatInfo/tests/AllTests.php:1.2 Sun Jan 27 16:41:12 2008 +++ pear/PHP_CompatInfo/tests/AllTests.php Mon Jan 28 21:06:30 2008 @@ -8,7 +8,7 @@ * @package PHP_CompatInfo * @author Laurent Laville <pear@laurent-laville.org> * @license http://www.php.net/license/3_01.txt PHP License 3.01 - * @version CVS: $Id: AllTests.php,v 1.2 2008/01/27 16:41:12 farell Exp $ + * @version CVS: $Id: AllTests.php,v 1.3 2008/01/28 21:06:30 farell Exp $
  * @link     http://pear.php.net/package/PHP_CompatInfo
  * @since    File available since Release 1.6.0
*/ @@ -22,6 +22,7 @@ chdir(dirname(__FILE__)); +require_once 'PEAR/Config.php'; require_once 'PHP_CompatInfo_TestSuite_Standard.php'; require_once 'PHP_CompatInfo_TestSuite_Bugs.php'; @@ -59,8 +60,59 @@
         $suite = new PHPUnit_Framework_TestSuite('PHP_CompatInfo Test Suite');
         $suite->addTestSuite('PHP_CompatInfo_TestSuite_Standard');
         $suite->addTestSuite('PHP_CompatInfo_TestSuite_Bugs');
+
+        if (PHP_CompatInfo_AllTests::packageInstalled('Console_GetArgs', '1.3.3')
+            && PHP_CompatInfo_AllTests::packageInstalled('Console_Table', '1.0.5')) {
+            /* Add CLI test suite, only
+               if packages below are installed on your system :
+               - Console_GetArgs 1.3.3 or better
+               - Console_Table   1.0.5 or better
+             */
+            include_once 'PHP_CompatInfo_TestSuite_Cli.php';
+
+            $suite->addTestSuite('PHP_CompatInfo_TestSuite_Cli');
+        }
         return $suite;
     }
+
+    /**
+     * Check if a package is installed
+     *
+     * Simple function to check if a package is installed under user
+     * or system PEAR installation. Minimal version and channel info are supported.
+     *
+     * @param string $name        Package name
+     * @param string $version     (optional) The minimal version
+     *                            that should be installed
+     * @param string $channel     (optional) The package channel distribution
+     * @param string $user_file   (optional) file to read PEAR user-defined
+     *                            options from
+     * @param string $system_file (optional) file to read PEAR system-wide
+     *                            defaults from
+     *
+     * @static
+     * @return bool
+     * @since  PEAR_Info version 1.6.0 (2005-01-03)
+     * @see    PEAR_Info::packageInstalled()
+     */
+    public static function packageInstalled($name, $version = null, $channel = null,
+        $user_file = '', $system_file = '')
+    {
+        $config =& PEAR_Config::singleton($user_file, $system_file);
+        $reg    =& $config->getRegistry();
+
+        if (is_null($version)) {
+            return $reg->packageExists($name, $channel);
+        } else {
+            $info = &$reg->getPackage($name, $channel);
+            if (is_object($info)) {
+                $installed['version'] = $info->getVersion();
+            } else {
+                $installed = $info;
+            }
+            return version_compare($version, $installed['version'], '<=');
+        }
+    }
} if (PHPUnit_MAIN_METHOD == 'PHP_CompatInfo_AllTests::main') {

« previous php.pear.qa (#4773) next »