cvs: pear /PHPUnit2 package.xml /PHPUnit2/Framework TestSuite.php
| From: | Sebastian Bergmann | Date: | Sun, 29 May 2005 15:53:49 +0000 |
| Subject: | cvs: pear /PHPUnit2 package.xml /PHPUnit2/Framework TestSuite.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-32229@lists.php.net to get a copy of this message | ||
sebastian Sun May 29 11:53:49 2005 EDT
Modified files:
/pear/PHPUnit2/Framework TestSuite.php
/pear/PHPUnit2 package.xml
Log:
Add PHPUnit2_Framework_TestSuite::addTestFile() as a convenience method that wraps
PHPUnit2_Framework_TestSuite::addTest() and PHPUnit2_Framework_TestSuite::addTestSuite().
Contribution by Stefano F. Rausch <stefano@rausch-e.net>.
http://cvs.php.net/diff.php/pear/PHPUnit2/Framework/TestSuite.php?r1=1.25&r2=1.26&ty=u
Index: pear/PHPUnit2/Framework/TestSuite.php
diff -u pear/PHPUnit2/Framework/TestSuite.php:1.25 pear/PHPUnit2/Framework/TestSuite.php:1.26
--- pear/PHPUnit2/Framework/TestSuite.php:1.25 Thu May 26 12:05:36 2005
+++ pear/PHPUnit2/Framework/TestSuite.php Sun May 29 11:53:49 2005
@@ -15,7 +15,7 @@
* @author Sebastian Bergmann <sb@sebastian-bergmann.de>
* @copyright 2002-2005 Sebastian Bergmann <sb@sebastian-bergmann.de>
* @license http://www.php.net/license/3_0.txt
PHP License 3.0
- * @version CVS: $Id: TestSuite.php,v 1.25 2005/05/26 16:05:36 sebastian Exp $
+ * @version CVS: $Id: TestSuite.php,v 1.26 2005/05/29 15:53:49 sebastian Exp $
* @link http://pear.php.net/package/PHPUnit2
* @since File available since Release 2.0.0
*/
@@ -445,6 +445,58 @@
private static function warning($message) {
return new PHPUnit2_Framework_Warning($message);
}
+
+ /**
+ * Wraps both <code>addTest()</code> and <code>addTestSuite</code>
+ * as well as the separate import statements for the user's convenience.
+ *
+ * If the named file cannot be read or there are no new tests that can be
+ * added, a <code>PHPUnit2_Framework_Warning</code> will be created instead,
+ * leaving the current test run untouched.
+ *
+ * @param string $filename
+ * @throws InvalidArgumentException
+ * @access public
+ * @since Method available since Release 2.3.0
+ * @author Stefano F. Rausch <stefano@rausch-e.net>
+ */
+ public function addTestFile($filename) {
+ if (!is_string($filename) || !file_exists($filename)) {
+ throw new InvalidArgumentException;
+ }
+
+ $declaredClasses = get_declared_classes();
+
+ @include_once $filename;
+
+ $newClasses = array_values(
+ array_diff(get_declared_classes(), $declaredClasses)
+ );
+
+ $testsFound = 0;
+
+ foreach ($newClasses as $class) {
+ if (preg_match('"Tests?$"', $class)) {
+ try {
+ $suiteMethod = new ReflectionMethod(
+ $class, PHPUnit2_Runner_BaseTestRunner::SUITE_METHODNAME
+ );
+
+ $this->addTest($suiteMethod->invoke(NULL));
+ } catch (ReflectionException $e) {
+ $this->addTestSuite(new ReflectionClass($class));
+ }
+
+ $testsFound++;
+ }
+ }
+
+ if ($testsFound == 0) {
+ $this->addTest(
+ new PHPUnit2_Framework_Warning('No tests found in file ' . $filename)
+ );
+ }
+ }
}
/*
http://cvs.php.net/diff.php/pear/PHPUnit2/package.xml?r1=1.111&r2=1.112&ty=u
Index: pear/PHPUnit2/package.xml
diff -u pear/PHPUnit2/package.xml:1.111 pear/PHPUnit2/package.xml:1.112
--- pear/PHPUnit2/package.xml:1.111 Thu May 26 12:12:03 2005
+++ pear/PHPUnit2/package.xml Sun May 29 11:53:49 2005
@@ -20,6 +20,8 @@
<![CDATA[
+ Added PHPUnit2_Framework_Assert::assertNotEquals().
++ Added PHPUnit2_Framework_TestSuite::addTestFile() as a convenience method that wraps
PHPUnit2_Framework_TestSuite::addTest() and PHPUnit2_Framework_TestSuite::addTestSuite().
Contribution by Stefano F. Rausch <stefano@rausch-e.net>.
+
+ Added BankAccount and Money samples.
* PHPUnit2_Framework_TestResult::run() now saves the $GLOBALS array before and restores it after
each test execution for better isolation.