diff options
author | knut <> | 2007-06-09 14:16:18 +0000 |
---|---|---|
committer | knut <> | 2007-06-09 14:16:18 +0000 |
commit | 7315ec25dc4ad7ef6cfdff47655d8a3c5f5cac4c (patch) | |
tree | 2b912da1a4bb6e0d46509b31da484a882acc96dd /tests/unit | |
parent | c91ec2590f9c1f7689c468284dc4d523da308897 (diff) |
added custom Prado class for unit tests
Diffstat (limited to 'tests/unit')
-rw-r--r-- | tests/unit/Caching/AllTests.php | 6 | ||||
-rw-r--r-- | tests/unit/Caching/TCacheTest.php | 51 | ||||
-rw-r--r-- | tests/unit/Prado.php | 123 | ||||
-rw-r--r-- | tests/unit/phpunit.php | 2 |
4 files changed, 129 insertions, 53 deletions
diff --git a/tests/unit/Caching/AllTests.php b/tests/unit/Caching/AllTests.php index 072a6182..555a4344 100644 --- a/tests/unit/Caching/AllTests.php +++ b/tests/unit/Caching/AllTests.php @@ -5,7 +5,8 @@ if(!defined('PHPUnit_MAIN_METHOD')) { define('PHPUnit_MAIN_METHOD', 'Caching_AllTests::main'); } -require_once 'TCacheTest.php'; +require_once 'TSqliteCacheTest.php'; +require_once 'TAPCCacheTest.php'; class Caching_AllTests { public static function main() { @@ -15,7 +16,8 @@ class Caching_AllTests { public static function suite() { $suite = new PHPUnit_Framework_TestSuite('System.Caching'); - $suite->addTestSuite('TCacheTest'); + $suite->addTestSuite('TSqliteCacheTest'); + $suite->addTestSuite('TAPCCacheTest'); return $suite; } diff --git a/tests/unit/Caching/TCacheTest.php b/tests/unit/Caching/TCacheTest.php deleted file mode 100644 index 76df7903..00000000 --- a/tests/unit/Caching/TCacheTest.php +++ /dev/null @@ -1,51 +0,0 @@ -<?php -require_once dirname(__FILE__).'/../phpunit.php'; - -Prado::using('System.Caching.TCache'); - -/** - * @package System.Caching - */ -class TCacheTest extends PHPUnit_Framework_TestCase { - - public function setUp() { - } - - public function tearDown() { - } - - public function testInit() { - throw new PHPUnit_Framework_IncompleteTestError(); - } - - public function testPrimaryCache() { - throw new PHPUnit_Framework_IncompleteTestError(); - } - - public function testKeyPrefix() { - throw new PHPUnit_Framework_IncompleteTestError(); - } - - public function testGet() { - throw new PHPUnit_Framework_IncompleteTestError(); - } - - public function testSet() { - throw new PHPUnit_Framework_IncompleteTestError(); - } - - public function testAdd() { - throw new PHPUnit_Framework_IncompleteTestError(); - } - - public function testDelete() { - throw new PHPUnit_Framework_IncompleteTestError(); - } - - public function testFlush() { - throw new PHPUnit_Framework_IncompleteTestError(); - } - -} - -?> diff --git a/tests/unit/Prado.php b/tests/unit/Prado.php new file mode 100644 index 00000000..aebcfcd0 --- /dev/null +++ b/tests/unit/Prado.php @@ -0,0 +1,123 @@ +<?php + +require_once 'PradoBase.php'; + +/** + * Extended Prado class which allows to redefine application instances and aliases. + */ +class Prado extends PradoBase { + + private static $_application = null; + private static $_aliases = array('System'=>PRADO_DIR); + private static $_usings=array(); + + public static function setApplication($application) { + self::$_application = $application; + } + + public static function getApplication() { + return self::$_application; + } + + public static function using($namespace) + { + if(isset(self::$_usings[$namespace]) || class_exists($namespace,false)) + return; + if(($pos=strrpos($namespace,'.'))===false) // a class name + { + try + { + include_once($namespace.self::CLASS_FILE_EXT); + } + catch(Exception $e) + { + if(!class_exists($namespace,false)) + throw new TInvalidOperationException('prado_component_unknown',$namespace); + else + throw $e; + } + } + else if(($path=self::getPathOfNamespace($namespace,self::CLASS_FILE_EXT))!==null) + { + $className=substr($namespace,$pos+1); + if($className==='*') // a directory + { + self::$_usings[$namespace]=$path; + set_include_path(get_include_path().PATH_SEPARATOR.$path); + } + else // a file + { + self::$_usings[$namespace]=$path; + if(!class_exists($className,false)) + { + try + { + include_once($path); + } + catch(Exception $e) + { + if(!class_exists($className,false)) + throw new TInvalidOperationException('prado_component_unknown',$className); + else + throw $e; + } + } + } + } + else + throw new TInvalidDataValueException('prado_using_invalid',$namespace); + } + + public static function getPathOfNamespace($namespace,$ext='') + { + if(isset(self::$_usings[$namespace])) + return self::$_usings[$namespace]; + else if(isset(self::$_aliases[$namespace])) + return self::$_aliases[$namespace]; + else + { + $segs=explode('.',$namespace); + $alias=array_shift($segs); + if(($file=array_pop($segs))!==null && ($root=self::getPathOfAlias($alias))!==null) + return rtrim($root.'/'.implode('/',$segs),'/').(($file==='*')?'':'/'.$file.$ext); + else + return null; + } + } + + public static function getPathOfAlias($alias) + { + return isset(self::$_aliases[$alias])?self::$_aliases[$alias]:null; + } + + protected static function getPathAliases() + { + return self::$_aliases; + } + + public static function setPathOfAlias($alias, $path) { + if(($rp=realpath($path))!==false && is_dir($rp)) { + if(strpos($alias,'.') === false) + self::$_aliases[$alias] = $rp; + else + throw new TInvalidDataValueException('prado_aliasname_invalid',$alias); + } + else + throw new TInvalidDataValueException('prado_alias_invalid',$alias,$path); + } + + + /*public static function setPathOfAlias($alias, $path) { + if(($rp=realpath($path)) !== false && is_dir($rp)) { + if(strpos($alias,'.') === false) { + self::$_aliases[$alias]=$rp; + } else { + throw new TInvalidDataValueException('prado_aliasname_invalid', $alias); + } + } else { + throw new TInvalidDataValueException('prado_alias_invalid', $alias, $path); + } + }*/ +} + +?>
\ No newline at end of file diff --git a/tests/unit/phpunit.php b/tests/unit/phpunit.php index 54e731b6..455f455c 100644 --- a/tests/unit/phpunit.php +++ b/tests/unit/phpunit.php @@ -12,6 +12,8 @@ */ define('PRADO_FRAMEWORK_DIR', dirname(__FILE__).'/../../framework'); set_include_path(PRADO_FRAMEWORK_DIR.':'.get_include_path()); + +require_once dirname(__FILE__).'/Prado.php'; require_once PRADO_FRAMEWORK_DIR.'/prado.php'; require_once 'PHPUnit/Framework/TestCase.php'; require_once 'PHPUnit/Framework/IncompleteTestError.php'; |