Diff
Added: library/trunk/lib/callicore.class.php (17 => 18)
--- library/trunk/lib/callicore.class.php 2006-08-18 18:12:11 UTC (rev 17)
+++ library/trunk/lib/callicore.class.php 2006-08-18 19:02:54 UTC (rev 18)
@@ -0,0 +1,126 @@
+<?php
+/**
+ * callicore.class.php - just has autoload for the moment
+ *
+ * Base static class for callicore library
+ *
+ * This is released under the GPL, see license.txt for details
+ *
+ * @author Elizabeth Smith <emsmith@callicore.net>
+ * @copyright Elizabeth Smith (c)2006
+ * @link http://callicore.net
+ * @license http://www.opensource.org/licenses/gpl-license.php GPL
+ * @version $Id$
+ * @since Php 5.2.0
+ * @package callicore library
+ * @subpackage library
+ * @category lib
+ * @filesource
+ */
+
+/**
+ * CCL - library base class
+ *
+ * So far just an autoload with autoload registering implementation
+ */
+abstract class CCL
+{
+ /**
+ * absolute path to callicore library base with trailing seperator
+ * @var $path string
+ */
+ static protected $path;
+
+ /**
+ * static public function registerAutoload
+ *
+ * registers the autoload function (intelligently so it doesn't override
+ * anything already set - or if it already exists it doesn't re-register itself)
+ *
+ * @return bool
+ */
+ static public function registerAutoload($callback = NULL)
+ {
+ // if callback is null, register the base autoload
+ if (is_null($callback))
+ {
+ $callback = array('CCL', 'autoload');
+ }
+ // first of all, check the stack
+ $active = spl_autoload_functions();
+ // if active is false, check for __autoload to push on stack
+ if ($active === FALSE && function_exists('__autoload'))
+ {
+ spl_autoload_register('__autoload');
+ }
+ // if active is array, are we on the array?
+ if (is_array($active) && in_array($callback, $active))
+ {
+ return TRUE;
+ }
+ else
+ {
+ return spl_autoload_register($callback);
+ }
+ }
+
+ /**
+ * static public function autoload
+ *
+ * will attempt to load a callicore library class
+ *
+ * @param string $class name of class to load
+ * @return bool
+ */
+ static public function autoload($class)
+ {
+ if(is_null(self::$path))
+ {
+ self::$path = dirname(__FILE__) . DIRECTORY_SEPARATOR;
+ }
+ // our naming format starts with CCL_ as a namespace and then is camelcapped
+ $total = preg_match_all('/CCL_|[A-Z][a-z0-9_]*/', $class, $matches);
+ // this autoload deals only with CCL_Test classes
+ if ($total < 2 || !isset($matches[0]) || !isset($matches[0][0]) || $matches[0][0] !== 'CCL_')
+ {
+ return FALSE;
+ }
+ // to avoid problems all filenames should be lower case
+ $array = array_map('strtolower', $matches[0]);
+ unset($matches, $total);
+ // discover path, if item is a dir, append it to path
+ $path = self::$path;
+ foreach ($array as $name)
+ {
+ if ($name === 'ccl_')
+ {
+ continue;
+ }
+ elseif(is_dir($path . $name))
+ {
+ $path .= $name . DIRECTORY_SEPARATOR;
+ }
+ else
+ {
+ $prev = basename($path);
+ $files = array($name . '.class.php', $name . '.abstract.php',
+ $name . '.interface.php', $prev . '.class.php',
+ $prev . '.abstract.php', $prev . '.interface.php');
+ break;
+ }
+ }
+ unset ($array, $name, $prev);
+ foreach ($files as $file)
+ {
+ if (file_exists($path . $file))
+ {
+ include ($path . $file);
+ unset($files, $file, $path);
+ return TRUE;
+ }
+ }
+ unset($files, $file, $path);
+ return FALSE;
+ }
+}
+?>
\ No newline at end of file
Property changes on: library/trunk/lib/callicore.class.php
___________________________________________________________________
Name: tsvn:logminsize
+ 15
Name: svn:keywords
+ Id
Name: svn:eol-style
+ LF
Modified: library/trunk/lib/test/result.class.php (17 => 18)
--- library/trunk/lib/test/result.class.php 2006-08-18 18:12:11 UTC (rev 17)
+++ library/trunk/lib/test/result.class.php 2006-08-18 19:02:54 UTC (rev 18)
@@ -57,6 +57,12 @@
protected $profile = array();
/**
+ * xdebug profile file
+ * @var $xdebugprofile string
+ */
+ protected $xdebugprofile;
+
+ /**
* count the number of test units shown
* @var $units int
*/
@@ -122,6 +128,20 @@
*/
protected $assertsfail = 0;
+ /**
+ * public function __construct
+ *
+ * just figures out any xdebug profile file
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ if(extension_loaded('xdebug'))
+ {
+ $this->xdebugprofile = xdebug_get_profiler_filename();
+ }
+ }
//----------------------------------------------------------------
// Observer Handling
Modified: library/trunk/lib/test/run.php (17 => 18)
--- library/trunk/lib/test/run.php 2006-08-18 18:12:11 UTC (rev 17)
+++ library/trunk/lib/test/run.php 2006-08-18 19:02:54 UTC (rev 18)
@@ -1,11 +1,9 @@
-#!/usr/bin/php
<?php
/**
- * run.php - defines the test lib directory and runs the testrunner class
+ * run.php - runs the testrunner class
*
* very simply file used to run the testrunner stuff
- * you can edit the shebang line if your php cli is located elsewhere
- * on windows you can associate php files with your php cli
+ * use run.bat or run.sh to do this from the command line
*
* This is released under the GPL, see license.txt for details
*
@@ -22,8 +20,9 @@
*/
/**
- * Include and create instance of the test runner class
+ * Include callicore class, register autoload, and run testrunner
*/
-include(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'runner.class.php');
+include(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'callicore.class.php');
+CCL::registerAutoload();
new CCL_TestRunner();
?>
\ No newline at end of file
Modified: library/trunk/lib/test/runner.class.php (17 => 18)
--- library/trunk/lib/test/runner.class.php 2006-08-18 18:12:11 UTC (rev 17)
+++ library/trunk/lib/test/runner.class.php 2006-08-18 19:02:54 UTC (rev 18)
@@ -2,7 +2,7 @@
/**
* runner.class.php - test runner script
*
- * allows for grouping tests into suits for quick and easy testing
+ * allows for grouping tests into suites for quick and easy testing
*
* This is released under the GPL, see license.txt for details
*
@@ -21,41 +21,66 @@
/**
* CCL_TestRunner - designed to be run on the command line to quickly execute tests
*
- * Can be configured with command line args or via an ini file
+ * Can be configured with command line args or via an ini file, can also be run
+ * via html and configured with get/post args or via an ini file
*/
class CCL_TestRunner
{
/**
+ * test libraries location
+ * @var $dir string
+ */
+ protected $dir;
+
+ /**
+ * extension test files have
+ * @var $ext string
+ */
+ protected $ext = 'test.php';
+
+ /**
* list of testunit classes to run
* @var $queue array
*/
- private $queue = array();
+ protected $queue = array();
/**
+ * list of report listening classes to attach
+ * @var $reports array
+ */
+ protected $reports = array();
+
+ /**
+ * using cli interface or a sapi
+ * @var $cli bool
+ */
+ protected $cli = FALSE;
+
+ /**
* public function __construct
*
* discovers if this is being called via cli or through a web sapi, you
* can override auto configuration by sending config information
*
- * @param type $name about
- * @return type about
+ * @param array $config configuration options (use instead of command line or get/post)
+ * @return void
*/
public function __construct(array $config = NULL)
{
+ // look for get/post or argv
$this->cli = PHP_SAPI === 'cli' ? TRUE : FALSE;
- // cli interface shortcut
- // webpage form shortcut
+ // raw config information
if (!is_null($config))
{
- //$this->setConfig($config);
+ $this->setConfig($config);
}
- elseif ($this->cli)
+ elseif ($this->cli && isset($_SERVER['argc']) && $_SERVER['argc'] > 1)
{
- // command line args or display cli entry interface
+ $this->parseArgs();
}
else
{
- // get/post or display webpage form
+ $this->runWizard();
}
return;
}
@@ -73,7 +98,7 @@
{
if (get_parent_class($class) != 'CCL_TestUnit')
{
- throw new Exception(get_class($class) . ' must be a subclass of CCL_TestUnit');
+ throw new Exception($class . ' must extend CCL_TestUnit');
return;
}
if (is_null($class))
@@ -113,7 +138,7 @@
foreach ($list as $name)
{
if (is_file($filename . DIRECTORY_SEPARATOR . $name) &&
- pathinfo($name, PATHINFO_EXTENSION) == 'test.php' &&
+ preg_match('/' . preg_quote($this->ext) . '$/', $name) &&
!in_array($name{0}, array('.', '~')))
{
$this->includeFile($filename . DIRECTORY_SEPARATOR . $name);
@@ -142,9 +167,9 @@
throw new Exception('There are no TestUnits to run');
}
$result = new CCL_TestResult();
- foreach ($this->reports as $class => $config)
+ foreach ($this->reports as $info)
{
- $report = new $class($config);
+ $report = new $info['class']($info['config']);
$result->attach($report);
}
foreach ($this->queue as $item)
@@ -168,25 +193,71 @@
//----------------------------------------------------------------
/**
- * private function includeLib
+ * protected function parseArgs
*
- * includes the required files for getting testing to work
+ * parses command line args sent, will die with help
+ * message if needed
*
* @return void
*/
- private function includeLib()
+ protected function parseArgs()
{
- $dir = dirname(__FILE__) . DIRECTORY_SEPARATOR;
- include($dir . 'error.class.php');
- include($dir . 'result.class.php');
- include($dir . 'unit.abstract.php');
- // include report specific classes here
+ foreach ($_SERVER['argv'] as $item)
+ {
+ echo $item;
+ }
}
/**
+ * protected function setConfig
+ *
+ * actually sets the configuration for the test run
+ * called by parseRequest, runWizard, parseArgs and the constructor
+ * with raw configuration information
+ *
+ * @return void
+ */
+ protected function setConfig()
+ {
+ echo "set my config baby";
+ }
+
+ /**
+ * protected function runWizard
+ *
+ * used by constructor to run the appropriate wizard
+ *
+ * @return void
+ */
+ protected function runWizard()
+ {
+ // wizards to run - cli, or html
+ if ($this->cli == TRUE)
+ {
+ $class = 'CCL_TestWizardCli';
+ }
+ else
+ {
+ throw new Exception('Please use cli to run tests');
+ }
+ $wizard = new $class();
+ $wizard->start();
+ $config = $wizard->config();
+ $this->setConfig($config);
+ $run = $wizard->run();
+ unset($wizard, $config);
+ if ($run)
+ {
+ $this->run();
+ }
+ return;
+ }
+
+ /**
* private function includeFile
*
* includes the file and adds any testunit class names to the queue
+ * this is used by addFile in several places
*
* @param string $filename
* @return void
@@ -194,7 +265,7 @@
private function includeFile($filename)
{
$prelist = get_declared_classes();
- include_once ($filename);
+ include ($filename);
$postlist = get_declared_classes();
$checklist = array_diff($postlist, $prelist);
foreach ($checklist as $class)
@@ -208,6 +279,4 @@
return;
}
}
-
-
?>
\ No newline at end of file