Improves unit testing.
authorFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 11 Mar 2010 10:04:33 +0000 (11:04 +0100)
committerFlorent Bruneau <florent.bruneau@polytechnique.org>
Thu, 11 Mar 2010 10:04:33 +0000 (11:04 +0100)
Signed-off-by: Florent Bruneau <florent.bruneau@polytechnique.org>
Makefile
classes/pltestcase.php [new file with mode: 0644]
classes/pltestsuite.php [new file with mode: 0644]
include/test.inc.php
ut/Makefile [deleted file]
ut/arrayiteratortest.php
ut/xdbtest.php

index 13da69d..ed1959d 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -13,7 +13,7 @@ all: build
 build: include/version.inc.php
 
 test:
-       make -C ut test
+       phpunit pltestsuite classes/pltestsuite.php
 
 clean:
        -rm include/version.inc.php
diff --git a/classes/pltestcase.php b/classes/pltestcase.php
new file mode 100644 (file)
index 0000000..cd59154
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+/***************************************************************************
+ *  Copyright (C) 2003-2010 Polytechnique.org                              *
+ *  http://opensource.polytechnique.org/                                   *
+ *                                                                         *
+ *  This program is free software; you can redistribute it and/or modify   *
+ *  it under the terms of the GNU General Public License as published by   *
+ *  the Free Software Foundation; either version 2 of the License, or      *
+ *  (at your option) any later version.                                    *
+ *                                                                         *
+ *  This program is distributed in the hope that it will be useful,        *
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
+ *  GNU General Public License for more details.                           *
+ *                                                                         *
+ *  You should have received a copy of the GNU General Public License      *
+ *  along with this program; if not, write to the Free Software            *
+ *  Foundation, Inc.,                                                      *
+ *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
+ ***************************************************************************/
+
+require_once 'PHPUnit/Framework.php';
+
+abstract class PlTestCase extends PHPUnit_Framework_TestCase
+{
+}
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+?>
diff --git a/classes/pltestsuite.php b/classes/pltestsuite.php
new file mode 100644 (file)
index 0000000..889547c
--- /dev/null
@@ -0,0 +1,50 @@
+<?php
+/***************************************************************************
+ *  Copyright (C) 2003-2010 Polytechnique.org                              *
+ *  http://opensource.polytechnique.org/                                   *
+ *                                                                         *
+ *  This program is free software; you can redistribute it and/or modify   *
+ *  it under the terms of the GNU General Public License as published by   *
+ *  the Free Software Foundation; either version 2 of the License, or      *
+ *  (at your option) any later version.                                    *
+ *                                                                         *
+ *  This program is distributed in the hope that it will be useful,        *
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of         *
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          *
+ *  GNU General Public License for more details.                           *
+ *                                                                         *
+ *  You should have received a copy of the GNU General Public License      *
+ *  along with this program; if not, write to the Free Software            *
+ *  Foundation, Inc.,                                                      *
+ *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
+ ***************************************************************************/
+
+require_once dirname(__FILE__) . '/../include/test.inc.php';
+require_once 'PHPUnit/Framework.php';
+
+class PlTestSuite
+{
+    public static function suite()
+    {
+        $suite = new PHPUnit_Framework_TestSuite('Plat/al');
+        $base = dirname(dirname(dirname(__FILE__)));
+        $pathes = glob($base . '/**/ut/', GLOB_ONLYDIR);
+        if (file_exists($base . '/ut')) {
+            array_push($pathes, $base . '/ut');
+        }
+        foreach ($pathes as $path) {
+            $subsuite = new PHPUnit_Framework_TestSuite('Plat/al: ' . $path);
+            foreach (glob($path . '/*.php') as $f) {
+                $class = basename($f);
+                $class = substr($class, 0, strlen($class) - 4);
+                require_once $f;
+                $subsuite->addTestSuite($class);
+            }
+            $suite->addTest($subsuite);
+        }
+        return $suite;
+    }
+}
+
+// vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
+?>
index a5a4fd7..0ff3d69 100644 (file)
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
-require_once dirname(__FILE__) . '/platal.inc.php';
-require_once 'PHPUnit/Framework.php';
+if (!@include_once dirname(__FILE__) . '/../../include/test.inc.php') {
+    require_once dirname(__FILE__) . '/platal.inc.php';
+    require_once 'PHPUnit/Framework.php';
 
-function __autoload($class)
-{
-    pl_autoload($class);
-}
-
-abstract class PlTestCase extends PHPUnit_Framework_TestCase
-{
+    function __autoload($class)
+    {
+        pl_autoload($class);
+    }
 }
 
 // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8:
diff --git a/ut/Makefile b/ut/Makefile
deleted file mode 100644 (file)
index 3456003..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-files=$(addprefix test-,$(wildcard *.php))
-
-test: $(files)
-       echo "$(files)"
-
-test-%:
-       phpunit $*
-
-.PHONY: test test-%
index b990612..96c4932 100644 (file)
@@ -19,7 +19,7 @@
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
-include_once dirname(__FILE__) . '/../include/test.inc.php';
+require_once dirname(__FILE__) . '/../include/test.inc.php';
 
 class ArrayIteratorTest extends PlTestCase
 {
index 3cc96e6..72b1686 100644 (file)
@@ -19,7 +19,7 @@
  *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA                *
  ***************************************************************************/
 
-include_once dirname(__FILE__) . '/../include/test.inc.php';
+require_once dirname(__FILE__) . '/../include/test.inc.php';
 
 class XDBTest extends PlTestCase
 {