From 760d88709fdde725522a114010d021e9391fa184 Mon Sep 17 00:00:00 2001 From: Marius Orcsik Date: Sun, 15 Mar 2009 10:29:41 +0100 Subject: [PATCH] + added the simpletest unit testing framework + some small work of having it working with my code --- _res/_libs/imported/simpletest | 1 + _res/_libs/tests/tsunittest.class.php | 85 ++++++++++++++++++++++++++++++++ _res/_libs/tsexceptionautoload.class.php | 2 + _tests/config.inc.php | 2 + _tests/models/tdoAbstractTest.php | 6 +++ _tests/models/tdoEntityATest.php | 33 +++++++++++++ run-tests.php | 33 +++++++++++++ 7 files changed, 162 insertions(+) create mode 120000 _res/_libs/imported/simpletest create mode 100644 _res/_libs/tests/tsunittest.class.php create mode 100644 _res/_libs/tsexceptionautoload.class.php create mode 100644 _tests/config.inc.php create mode 100644 _tests/models/tdoAbstractTest.php create mode 100644 _tests/models/tdoEntityATest.php create mode 100755 run-tests.php diff --git a/_res/_libs/imported/simpletest b/_res/_libs/imported/simpletest new file mode 120000 index 0000000..b58b39a --- /dev/null +++ b/_res/_libs/imported/simpletest @@ -0,0 +1 @@ +/home/marius/workspace/simpletest \ No newline at end of file diff --git a/_res/_libs/tests/tsunittest.class.php b/_res/_libs/tests/tsunittest.class.php new file mode 100644 index 0000000..3f8eab9 --- /dev/null +++ b/_res/_libs/tests/tsunittest.class.php @@ -0,0 +1,85 @@ + + * @date 09.03.03 + */ +class tsUnitTest extends TestSuite { + /** + * @var tsUnitTest + */ + static private $instance; + + public function __construct () { + // TODO + } + + /** + * @var integer $argc + * @var mixed[] $argv + * @return void + */ + static public function execute ($argc, $argv = null) { + $loader = new SimpleFileLoader(); + $result = false; + + $tests = array(); + for ($i = 0; $i < $argc; $i++) { + if ( stristr ($argv[$i], 'package') !== false ) { + $sPackageName = $argv[$i+1]; + } else { + $sPackageName = null; + } + } + + if ($sPackageName) { + $aPackages = self::getInstance()->getTestsByPackage ($sPackageName); + foreach ($aPackages as $sPath) { + $tests[] = $loader->load ($sPath); + } + }else { + $aPackages = self::getInstance()->getAllTests (); + foreach ($aPackages as $sPath) { + $tests[] = $loader->load ($sPath); + } + } + + foreach ($tests as $suite) { + $result |= $suite->run(new DefaultReporter()); + } + + var_dump($result); + return $result; + } + /** + * @return tsUnitTest + */ + static private function getInstance () { + if (!(self::$instance instanceof tsUnitTest)) { + self::$instance = new tsUnitTest (); + } + return self::$instance; + } + + private function getTestsByPackage ($sPackageName) { + $aFiles = getDirFiles (VSC_TEST_PATH . $sPackageName); + foreach ($aFiles as $key=>$sPath) { + if (!stristr($sPath, 'Test.php')) { + unset($aFiles[$key]); + } + } + return $aFiles; + } + +// private function getAllPackages () {} + + private function getAllTests () { + $aFiles = getDirFiles (VSC_TEST_PATH); + foreach ($aFiles as $key=>$sPath) { + if (!stristr($sPath, 'Test.php')) { + unset($aFiles[$key]); + } + } + return $aFiles; + } +} \ No newline at end of file diff --git a/_res/_libs/tsexceptionautoload.class.php b/_res/_libs/tsexceptionautoload.class.php new file mode 100644 index 0000000..4180e1c --- /dev/null +++ b/_res/_libs/tsexceptionautoload.class.php @@ -0,0 +1,2 @@ +assertFalse(false, 'To be or not to be false'); + } +} \ No newline at end of file diff --git a/_tests/models/tdoEntityATest.php b/_tests/models/tdoEntityATest.php new file mode 100644 index 0000000..54330cf --- /dev/null +++ b/_tests/models/tdoEntityATest.php @@ -0,0 +1,33 @@ + + */ +import ('models'); +class tdoEntityATest extends UnitTestCase { + + private function getTestData () { + return array ( + array ('One', 'Two', 3), + array (null, 0, 1) + ); + } + + public function testToArray (){ +// try { + $o = new tdoEntityA (); +// } catch (AutoloadException $e) { +// echo $e->getTraceAsString(); +// } catch (Exception $e) { +// // TODO proper exception handling +// echo $e->getTraceAsString(); +// } + + $this->assertIsA ($o, 'tdoEntity', 'Failed initialization of our test object'); + } + + public function test123 () { + $this->assertEqual(2, 2, 'it works'); + } +} \ No newline at end of file diff --git a/run-tests.php b/run-tests.php new file mode 100755 index 0000000..9a87755 --- /dev/null +++ b/run-tests.php @@ -0,0 +1,33 @@ +#!/usr/bin/php +getMessage(); + exit (1); +} catch (tsExceptionAutoload $e) { + // could not load the tsUnitTest class + echo $e->getMessage(); + exit (1); +} + +if (SimpleReporter::inCli()) { + exit($result ? 0 : 1); +} \ No newline at end of file -- 2.11.4.GIT