From fbc3ba935fee5b63578a27aec2402f6fc069cf28 Mon Sep 17 00:00:00 2001 From: alban Date: Wed, 12 Mar 2014 18:43:26 +0100 Subject: [PATCH] [enh] adds phpunit tests layout --- phpunit/AutoLoader.php | 37 +++++++++++++ phpunit/bootstrap.php | 9 +++ phpunit/lib/AlterncTest.php | 8 +++ phpunit/phpunit.xml | 4 ++ phpunit/tests/DummyTest.php | 107 ++++++++++++++++++++++++++++++++++++ phpunit/tests/LogTest.php | 33 +++++++++++ 6 files changed, 198 insertions(+) create mode 100644 phpunit/AutoLoader.php create mode 100644 phpunit/bootstrap.php create mode 100644 phpunit/lib/AlterncTest.php create mode 100644 phpunit/phpunit.xml create mode 100644 phpunit/tests/DummyTest.php create mode 100644 phpunit/tests/LogTest.php diff --git a/phpunit/AutoLoader.php b/phpunit/AutoLoader.php new file mode 100644 index 00000000..55dd8085 --- /dev/null +++ b/phpunit/AutoLoader.php @@ -0,0 +1,37 @@ +isDir() && !$file->isLink() && !$file->isDot()) { + // recurse into directories other than a few special ones + self::registerDirectory($file->getPathname()); + } elseif (substr($file->getFilename(), -4) === '.php') { + // save the class name / path of a .php file found + $className = substr($file->getFilename(), 0, -4); + AutoLoader::registerClass($className, $file->getPathname()); + } + } + } + + public static function registerClass($className, $fileName) { + AutoLoader::$classNames[$className] = $fileName; + } + + public static function loadClass($className) { + if (isset(AutoLoader::$classNames[$className])) { + require_once(AutoLoader::$classNames[$className]); + } + } + +} + +spl_autoload_register(array('AutoLoader', 'loadClass')); diff --git a/phpunit/bootstrap.php b/phpunit/bootstrap.php new file mode 100644 index 00000000..4253641d --- /dev/null +++ b/phpunit/bootstrap.php @@ -0,0 +1,9 @@ + + diff --git a/phpunit/tests/DummyTest.php b/phpunit/tests/DummyTest.php new file mode 100644 index 00000000..cd8b66cd --- /dev/null +++ b/phpunit/tests/DummyTest.php @@ -0,0 +1,107 @@ +assertTrue(FALSE); + return TRUE; + } + + /** + * @depends testDependance + * @param bool $dependancyStatus Received from dependance return + */ + public function testHasDependancy( $dependancyStatus) + { + $this->assertTrue($dependancyStatus); + } + + + public function testPushAndPop() + { + $stack = array(); + $this->assertEquals(0, count($stack)); + + array_push($stack, 'foo'); + $this->assertEquals('foo', $stack[count($stack)-1]); + $this->assertEquals(1, count($stack)); + + $this->assertEquals('foo', array_pop($stack)); + $this->assertEquals(0, count($stack)); + } +} + diff --git a/phpunit/tests/LogTest.php b/phpunit/tests/LogTest.php new file mode 100644 index 00000000..85808a25 --- /dev/null +++ b/phpunit/tests/LogTest.php @@ -0,0 +1,33 @@ +logger = new m_log(); + } + + protected function tearDown() + { + } + + public function testPushAndPop() + { + $stack = array(); + $this->assertEquals(0, count($stack)); + + array_push($stack, 'foo'); + $this->assertEquals('foo', $stack[count($stack)-1]); + $this->assertEquals(1, count($stack)); + + $this->assertEquals('foo', array_pop($stack)); + $this->assertEquals(0, count($stack)); + } +} +