diff --git a/Extensions/ExceptionTestCase.php b/Extensions/ExceptionTestCase.php new file mode 100644 index 00000000000..d4437103855 --- /dev/null +++ b/Extensions/ExceptionTestCase.php @@ -0,0 +1,122 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: ExceptionTestCase.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; + +/** + * A TestCase that expects a specified Exception to be thrown. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class PHPUnit2_Extensions_ExceptionTestCase extends PHPUnit2_Framework_TestCase { + /** + * The name of the expected Exception. + * + * @var string + * @access private + */ + private $expectedException = 'Exception'; + + /** + * @return string + * @access public + * @since Method available since Release 2.2.0 + */ + public function getExpectedException() { + return $this->expectedException; + } + + /** + * @param string $exceptionName + * @throws Exception + * @access public + * @since Method available since Release 2.2.0 + */ + public function setExpectedException($exceptionName) { + if (is_string($exceptionName) && class_exists($exceptionName)) { + $this->expectedException = $exceptionName; + } else { + throw new Exception; + } + } + + /** + * @access protected + */ + protected function runTest() { + try { + parent::runTest(); + } + + catch (Exception $e) { + if ($e instanceof $this->expectedException) { + return; + } else { + throw $e; + } + } + + $this->fail('Expected exception ' . $this->expectedException); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/PerformanceTestCase.php b/Extensions/PerformanceTestCase.php new file mode 100644 index 00000000000..d678e9843a4 --- /dev/null +++ b/Extensions/PerformanceTestCase.php @@ -0,0 +1,128 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: PerformanceTestCase.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.1.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; + +require_once 'Benchmark/Timer.php'; + +/** + * A TestCase that expects a TestCase to be executed + * meeting a given time limit. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.1.0 + */ +class PHPUnit2_Extensions_PerformanceTestCase extends PHPUnit2_Framework_TestCase { + /** + * @var integer + * @access private + */ + private $maxRunningTime = 0; + + /** + * @access protected + */ + protected function runTest() { + $timer = new Benchmark_Timer; + + $timer->start(); + parent::runTest(); + $timer->stop(); + + if ($this->maxRunningTime != 0 && + $timer->timeElapsed() > $this->maxRunningTime) { + $this->fail( + sprintf( + 'expected running time: <= %s but was: %s', + + $this->maxRunningTime, + $timer->timeElapsed() + ) + ); + } + } + + /** + * @param integer $maxRunningTime + * @throws Exception + * @access public + * @since Method available since Release 2.3.0 + */ + public function setMaxRunningTime($maxRunningTime) { + if (is_integer($maxRunningTime) && + $maxRunningTime >= 0) { + $this->maxRunningTime = $maxRunningTime; + } else { + throw new Exception; + } + } + + /** + * @return integer + * @access public + * @since Method available since Release 2.3.0 + */ + public function getMaxRunningTime() { + return $this->maxRunningTime; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/RepeatedTest.php b/Extensions/RepeatedTest.php new file mode 100644 index 00000000000..accc192e839 --- /dev/null +++ b/Extensions/RepeatedTest.php @@ -0,0 +1,138 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: RepeatedTest.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Extensions/TestDecorator.php'; + +/** + * A Decorator that runs a test repeatedly. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class PHPUnit2_Extensions_RepeatedTest extends PHPUnit2_Extensions_TestDecorator { + /** + * @var integer + * @access private + */ + private $timesRepeat = 1; + + /** + * Constructor. + * + * @param PHPUnit2_Framework_Test $test + * @param integer $timesRepeat + * @throws Exception + * @access public + */ + public function __construct(PHPUnit2_Framework_Test $test, $timesRepeat = 1) { + parent::__construct($test); + + if (is_integer($timesRepeat) && + $timesRepeat >= 0) { + $this->timesRepeat = $timesRepeat; + } else { + throw new Exception( + 'Argument 2 must be a positive integer.' + ); + } + } + + /** + * Counts the number of test cases that + * will be run by this test. + * + * @return integer + * @access public + */ + public function countTestCases() { + return $this->timesRepeat * $this->test->countTestCases(); + } + + /** + * Runs the decorated test and collects the + * result in a TestResult. + * + * @param PHPUnit2_Framework_TestResult $result + * @return PHPUnit2_Framework_TestResult + * @throws Exception + * @access public + */ + public function run($result = NULL) { + if ($result === NULL) { + $result = $this->createResult(); + } + + // XXX: Workaround for missing ability to declare type-hinted parameters as optional. + else if (!($result instanceof PHPUnit2_Framework_TestResult)) { + throw new Exception( + 'Argument 1 must be an instance of PHPUnit2_Framework_TestResult.' + ); + } + + for ($i = 0; $i < $this->timesRepeat && !$result->shouldStop(); $i++) { + $this->test->run($result); + } + + return $result; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/TestDecorator.php b/Extensions/TestDecorator.php new file mode 100644 index 00000000000..04427d67c3a --- /dev/null +++ b/Extensions/TestDecorator.php @@ -0,0 +1,174 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: TestDecorator.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/Assert.php'; +require_once 'PHPUnit2/Framework/Test.php'; +require_once 'PHPUnit2/Framework/TestResult.php'; + +/** + * A Decorator for Tests. + * + * Use TestDecorator as the base class for defining new + * test decorators. Test decorator subclasses can be introduced + * to add behaviour before or after a test is run. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class PHPUnit2_Extensions_TestDecorator extends PHPUnit2_Framework_Assert implements PHPUnit2_Framework_Test { + /** + * The Test to be decorated. + * + * @var object + * @access protected + */ + protected $test = NULL; + + /** + * Constructor. + * + * @param PHPUnit2_Framework_Test $test + * @access public + */ + public function __construct(PHPUnit2_Framework_Test $test) { + $this->test = $test; + } + + /** + * Returns a string representation of the test. + * + * @return string + * @access public + */ + public function toString() { + return $this->test->toString(); + } + + /** + * Runs the test and collects the + * result in a TestResult. + * + * @param PHPUnit2_Framework_TestResult $result + * @access public + */ + public function basicRun(PHPUnit2_Framework_TestResult $result) { + $this->test->run($result); + } + + /** + * Counts the number of test cases that + * will be run by this test. + * + * @return integer + * @access public + */ + public function countTestCases() { + return $this->test->countTestCases(); + } + + /** + * Creates a default TestResult object. + * + * @return PHPUnit2_Framework_TestResult + * @access protected + */ + protected function createResult() { + return new PHPUnit2_Framework_TestResult; + } + + /** + * Returns the test to be run. + * + * @return PHPUnit2_Framework_Test + * @access public + */ + public function getTest() { + return $this->test; + } + + /** + * Runs the decorated test and collects the + * result in a TestResult. + * + * @param PHPUnit2_Framework_TestResult $result + * @return PHPUnit2_Framework_TestResult + * @throws Exception + * @access public + */ + public function run($result = NULL) { + if ($result === NULL) { + $result = $this->createResult(); + } + + // XXX: Workaround for missing ability to declare type-hinted parameters as optional. + else if (!($result instanceof PHPUnit2_Framework_TestResult)) { + throw new Exception( + 'Argument 1 must be an instance of PHPUnit2_Framework_TestResult.' + ); + } + + $this->basicRun($result); + + return $result; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/TestSetup.php b/Extensions/TestSetup.php new file mode 100644 index 00000000000..d989d7d7650 --- /dev/null +++ b/Extensions/TestSetup.php @@ -0,0 +1,154 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: TestSetup.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/TestSuite.php'; +require_once 'PHPUnit2/Extensions/TestDecorator.php'; + +/** + * A Decorator to set up and tear down additional fixture state. + * Subclass TestSetup and insert it into your tests when you want + * to set up additional state once before the tests are run. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class PHPUnit2_Extensions_TestSetup extends PHPUnit2_Extensions_TestDecorator { + /** + * Runs the decorated test and collects the + * result in a TestResult. + * + * @param PHPUnit2_Framework_TestResult $result + * @return PHPUnit2_Framework_TestResult + * @throws Exception + * @access public + */ + public function run($result = NULL) { + if ($result === NULL) { + $result = $this->createResult(); + } + + // XXX: Workaround for missing ability to declare type-hinted parameters as optional. + else if (!($result instanceof PHPUnit2_Framework_TestResult)) { + throw new Exception( + 'Argument 1 must be an instance of PHPUnit2_Framework_TestResult.' + ); + } + + $this->setUp(); + $this->copyFixtureToTest(); + $this->basicRun($result); + $this->tearDown(); + + return $result; + } + + /** + * Copies the fixture set up by setUp() to the test. + * + * @access private + * @since Method available since Release 2.3.0 + */ + private function copyFixtureToTest() { + $object = new ReflectionClass($this); + + foreach ($object->getProperties() as $property) { + $name = $property->getName(); + + if ($name != 'test') { + $this->doCopyFixtureToTest($this->test, $name, $this->$name); + } + } + } + + /** + * @access private + * @since Method available since Release 2.3.0 + */ + private function doCopyFixtureToTest($object, $name, &$value) { + if ($object instanceof PHPUnit2_Framework_TestSuite) { + foreach ($object->tests() as $test) { + $this->doCopyFixtureToTest($test, $name, $value); + } + } else { + $object->$name =& $value; + } + } + + /** + * Sets up the fixture. Override to set up additional fixture + * state. + * + * @access protected + */ + protected function setUp() { + } + + /** + * Tears down the fixture. Override to tear down the additional + * fixture state. + * + * @access protected + */ + protected function tearDown() { + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/Assert.php b/Framework/Assert.php new file mode 100644 index 00000000000..e5378de24cb --- /dev/null +++ b/Framework/Assert.php @@ -0,0 +1,626 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: Assert.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/AssertionFailedError.php'; +require_once 'PHPUnit2/Framework/ComparisonFailure.php'; + +/** + * A set of assert methods. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + * @static + */ +class PHPUnit2_Framework_Assert { + /** + * @var boolean + * @access private + * @static + */ + private static $looselyTyped = FALSE; + + /** + * Protect constructor since it is a static only class. + * + * @access protected + */ + protected function __construct() { + } + + /** + * Asserts that a haystack contains a needle. + * + * @param mixed $needle + * @param mixed $haystack + * @param string $message + * @access public + * @static + * @since Method available since Release 2.1.0 + */ + public static function assertContains($needle, $haystack, $message = '') { + self::doAssertContains($needle, $haystack, TRUE, $message); + } + + /** + * Asserts that a haystack does not contain a needle. + * + * @param mixed $needle + * @param mixed $haystack + * @param string $message + * @access public + * @static + * @since Method available since Release 2.1.0 + */ + public static function assertNotContains($needle, $haystack, $message = '') { + self::doAssertContains($needle, $haystack, FALSE, $message); + } + + /** + * @param mixed $needle + * @param mixed $haystack + * @param boolean $condition + * @param string $message + * @throws Exception + * @access private + * @static + * @since Method available since Release 2.2.0 + */ + private static function doAssertContains($needle, $haystack, $condition, $message) { + $found = FALSE; + + if (is_array($haystack) || + (is_object($haystack) && $haystack instanceof Iterator)) { + foreach ($haystack as $straw) { + if ($straw === $needle) { + $found = TRUE; + break; + } + } + } + + else if (is_string($needle) && is_string($haystack)) { + if (strpos($haystack, $needle) !== FALSE) { + $found = TRUE; + } + } + + else { + throw new Exception; + } + + if ($condition && !$found) { + self::fail( + sprintf( + '%s%s"%s" does not contain "%s"', + + $message, + ($message != '') ? ' ' : '', + self::objectToString($haystack), + self::objectToString($needle) + ) + ); + } + + else if (!$condition && $found) { + self::fail( + sprintf( + '%s%s"%s" contains "%s"', + + $message, + ($message != '') ? ' ' : '', + self::objectToString($haystack), + self::objectToString($needle) + ) + ); + } + } + + /** + * Asserts that two variables are equal. + * + * @param mixed $expected + * @param mixed $actual + * @param string $message + * @param mixed $delta + * @access public + * @static + */ + public static function assertEquals($expected, $actual, $message = '', $delta = 0) { + self::doAssertEquals($expected, $actual, $delta, TRUE, $message); + } + + /** + * Asserts that two variables are not equal. + * + * @param mixed $expected + * @param mixed $actual + * @param string $message + * @param mixed $delta + * @access public + * @static + * @since Method available since Release 2.3.0 + */ + public static function assertNotEquals($expected, $actual, $message = '', $delta = 0) { + self::doAssertEquals($expected, $actual, $delta, FALSE, $message); + } + + /** + * @param mixed $expected + * @param mixed $actual + * @param mixed $delta + * @param boolean $condition + * @param string $message + * @access private + * @static + * @since Method available since Release 2.3.0 + */ + private static function doAssertEquals($expected, $actual, $delta, $condition, $message) { + $equal = FALSE; + + if (is_array($expected)) { + if (is_array($actual)) { + self::sortArrayRecursively($actual); + self::sortArrayRecursively($expected); + + if (self::$looselyTyped) { + $actual = self::convertToString($actual); + $expected = self::convertToString($expected); + } + + $equal = (serialize($expected) == serialize($actual)); + } + } + + else if (is_float($expected) && is_float($actual) && is_float($delta)) { + $equal = (abs($expected - $actual) <= $delta); + } + + else { + $equal = (serialize($expected) == serialize($actual)); + } + + if ($condition && !$equal) { + self::failNotSame( + $expected, + $actual, + $message + ); + } + + else if (!$condition && $equal) { + self::failSame( + $expected, + $actual, + $message + ); + } + } + + /** + * Asserts that a condition is true. + * + * @param boolean $condition + * @param string $message + * @throws Exception + * @access public + * @static + */ + public static function assertTrue($condition, $message = '') { + if (is_bool($condition)) { + if (!$condition) { + self::fail($message); + } + } else { + throw new Exception; + } + } + + /** + * Asserts that a condition is false. + * + * @param boolean $condition + * @param string $message + * @throws Exception + * @access public + * @static + */ + public static function assertFalse($condition, $message = '') { + if (is_bool($condition)) { + self::assertTrue(!$condition, $message); + } else { + throw new Exception; + } + } + + /** + * Asserts that a variable is not NULL. + * + * @param mixed $actual + * @param string $message + * @access public + * @static + */ + public static function assertNotNull($actual, $message = '') { + if (is_null($actual)) { + self::fail(self::format('NOT NULL', 'NULL', $message)); + } + } + + /** + * Asserts that a variable is NULL. + * + * @param mixed $actual + * @param string $message + * @access public + * @static + */ + public static function assertNull($actual, $message = '') { + if (!is_null($actual)) { + self::fail(self::format('NULL', 'NOT NULL', $message)); + } + } + + /** + * Asserts that two variables have the same type and value. + * Used on objects, it asserts that two variables reference + * the same object. + * + * @param mixed $expected + * @param mixed $actual + * @param string $message + * @access public + * @static + */ + public static function assertSame($expected, $actual, $message = '') { + if ($expected !== $actual) { + self::failNotSame($expected, $actual, $message); + } + } + + /** + * Asserts that two variables do not have the same type and value. + * Used on objects, it asserts that two variables do not reference + * the same object. + * + * @param mixed $expected + * @param mixed $actual + * @param string $message + * @access public + * @static + */ + public static function assertNotSame($expected, $actual, $message = '') { + if ($expected === $actual) { + self::failSame($expected, $actual, $message); + } + } + + /** + * Asserts that a variable is of a given type. + * + * @param string $expected + * @param mixed $actual + * @param string $message + * @access public + * @static + */ + public static function assertType($expected, $actual, $message = '') { + self::doAssertType($expected, $actual, TRUE, $message); + } + + /** + * Asserts that a variable is not of a given type. + * + * @param string $expected + * @param mixed $actual + * @param string $message + * @access public + * @static + * @since Method available since Release 2.2.0 + */ + public static function assertNotType($expected, $actual, $message = '') { + self::doAssertType($expected, $actual, FALSE, $message); + } + + /** + * @param string $expected + * @param mixed $actual + * @param boolean $condition + * @param string $message + * @access private + * @static + * @since Method available since Release 2.2.0 + */ + private static function doAssertType($expected, $actual, $condition, $message) { + if (!is_string($expected)) { + throw new Exception; + } + + if (is_object($actual)) { + $result = $actual instanceof $expected; + } else { + $result = (gettype($actual) == $expected); + } + + if ($condition && !$result) { + self::failNotSame( + $expected, + $actual, + $message + ); + } + + else if (!$condition && $result) { + self::failSame( + $expected, + $actual, + $message + ); + } + } + + /** + * Asserts that a string matches a given regular expression. + * + * @param string $pattern + * @param string $string + * @param string $message + * @access public + * @static + */ + public static function assertRegExp($pattern, $string, $message = '') { + self::doAssertRegExp($pattern, $string, TRUE, $message); + } + + /** + * Asserts that a string does not match a given regular expression. + * + * @param string $pattern + * @param string $string + * @param string $message + * @access public + * @static + * @since Method available since Release 2.1.0 + */ + public static function assertNotRegExp($pattern, $string, $message = '') { + self::doAssertRegExp($pattern, $string, FALSE, $message); + } + + /** + * @param mixed $pattern + * @param mixed $string + * @param boolean $condition + * @param string $message + * @access private + * @static + * @since Method available since Release 2.2.0 + */ + private static function doAssertRegExp($pattern, $string, $condition, $message) { + if (!is_string($pattern) || !is_string($string)) { + throw new Exception; + } + + $result = preg_match($pattern, $string); + + if ($condition && !$result) { + self::fail( + sprintf( + '%s%s"%s" does not match pattern "%s"', + + $message, + ($message != '') ? ' ' : '', + $string, + $pattern + ) + ); + } + + else if (!$condition && $result) { + self::fail( + sprintf( + '%s%s"%s" matches pattern "%s"', + + $message, + ($message != '') ? ' ' : '', + $string, + $pattern + ) + ); + } + } + + /** + * Fails a test with the given message. + * + * @param string $message + * @throws PHPUnit2_Framework_AssertionFailedError + * @access public + * @static + */ + public static function fail($message = '') { + throw new PHPUnit2_Framework_AssertionFailedError($message); + } + + /** + * @param string $message + * @throws PHPUnit2_Framework_AssertionFailedError + * @access private + * @static + */ + private static function failSame($message) { + self::fail( + sprintf( + '%s%sexpected not same', + + $message, + ($message != '') ? ' ' : '' + ) + ); + } + + /** + * @param mixed $expected + * @param mixed $actual + * @param string $message + * @throws PHPUnit2_Framework_AssertionFailedError + * @access private + * @static + */ + private static function failNotSame($expected, $actual, $message) { + if (is_string($expected) && is_string($actual)) { + throw new PHPUnit2_Framework_ComparisonFailure($expected, $actual, $message); + } + + self::fail( + sprintf( + '%s%sexpected same: <%s> was not: <%s>', + + $message, + ($message != '') ? ' ' : '', + self::objectToString($expected), + self::objectToString($actual) + ) + ); + } + + /** + * @param mixed $expected + * @param mixed $actual + * @param string $message + * @access public + * @static + */ + public static function format($expected, $actual, $message) { + return sprintf( + '%s%sexpected: <%s> but was: <%s>', + + $message, + ($message != '') ? ' ' : '', + self::objectToString($expected), + self::objectToString($actual) + ); + } + + /** + * @param boolean $looselyTyped + * @access public + * @static + */ + public static function setLooselyTyped($looselyTyped) { + if (is_bool($looselyTyped)) { + self::$looselyTyped = $looselyTyped; + } + } + + /** + * Converts a value to a string. + * + * @param mixed $value + * @access private + * @static + */ + private static function convertToString($value) { + foreach ($value as $k => $v) { + if (is_array($v)) { + $value[$k] = self::convertToString($value[$k]); + } else if (is_object($v)) { + $value[$k] = self::objectToString($value[$k]); + } else { + settype($value[$k], 'string'); + } + } + + return $value; + } + + /** + * @param mixed $object + * @return string + * @access private + * @static + */ + private static function objectToString($object) { + if (is_array($object) || is_object($object)) { + $object = serialize($object); + } + + return $object; + } + + /** + * Sorts an array recursively by its keys. + * + * @param array $array + * @access private + * @static + * @author Adam Maccabee Trachtenberg + */ + private static function sortArrayRecursively(&$array) { + ksort($array); + + foreach($array as $k => $v) { + if (is_array($v)) { + self::sortArrayRecursively($array[$k]); + } + } + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/AssertionFailedError.php b/Framework/AssertionFailedError.php new file mode 100644 index 00000000000..66b1b9962db --- /dev/null +++ b/Framework/AssertionFailedError.php @@ -0,0 +1,80 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: AssertionFailedError.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +/** + * Thrown when an assertion failed. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class PHPUnit2_Framework_AssertionFailedError extends Exception { + /** + * Wrapper for getMessage() which is declared as final. + * + * @return string + * @access public + */ + public function toString() { + return $this->getMessage(); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/ComparisonFailure.php b/Framework/ComparisonFailure.php new file mode 100644 index 00000000000..a0f6d01e6e9 --- /dev/null +++ b/Framework/ComparisonFailure.php @@ -0,0 +1,153 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: ComparisonFailure.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/Assert.php'; +require_once 'PHPUnit2/Framework/AssertionFailedError.php'; + +/** + * Thrown when an assertion for string equality failed. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class PHPUnit2_Framework_ComparisonFailure extends PHPUnit2_Framework_AssertionFailedError { + /** + * @var string + * @access private + */ + private $expected = ''; + + /** + * @var string + * @access private + */ + private $actual = ''; + + /** + * Constructs a comparison failure. + * + * @param string $expected + * @param string $actual + * @param string $message + * @access public + */ + public function __construct($expected, $actual, $message = '') { + parent::__construct($message); + + $this->expected = ($expected === NULL) ? 'NULL' : $expected; + $this->actual = ($actual === NULL) ? 'NULL' : $actual; + } + + /** + * Returns "..." in place of common prefix and "..." in + * place of common suffix between expected and actual. + * + * @return string + * @access public + */ + public function toString() { + $end = min(strlen($this->expected), strlen($this->actual)); + $i = 0; + $j = strlen($this->expected) - 1; + $k = strlen($this->actual) - 1; + + for (; $i < $end; $i++) { + if ($this->expected[$i] != $this->actual[$i]) { + break; + } + } + + for (; $k >= $i && $j >= $i; $k--,$j--) { + if ($this->expected[$j] != $this->actual[$k]) { + break; + } + } + + if ($j < $i && $k < $i) { + $expected = $this->expected; + $actual = $this->actual; + } else { + $expected = substr($this->expected, $i, ($j + 1 - $i)); + $actual = substr($this->actual, $i, ($k + 1 - $i));; + + if ($i <= $end && $i > 0) { + $expected = '...' . $expected; + $actual = '...' . $actual; + } + + if ($j < strlen($this->expected) - 1) { + $expected .= '...'; + } + + if ($k < strlen($this->actual) - 1) { + $actual .= '...'; + } + } + + return PHPUnit2_Framework_Assert::format( + $expected, + $actual, + parent::getMessage() + ); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/Error.php b/Framework/Error.php new file mode 100644 index 00000000000..e5d0f2e0815 --- /dev/null +++ b/Framework/Error.php @@ -0,0 +1,88 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: Error.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.2.0 + */ + +/** + * Wrapper for PHP errors. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.2.0 + */ +class PHPUnit2_Framework_Error extends Exception { + /** + * Constructor. + * + * @param string $message + * @param integer $code + * @param string $file + * @param integer $line + * @param array $trace + * @access public + */ + public function __construct($message, $code, $file, $line, $trace) { + parent::__construct($message, $code); + + $this->file = $file; + $this->line = $line; + $this->trace = $trace; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/IncompleteTest.php b/Framework/IncompleteTest.php new file mode 100644 index 00000000000..8e020752e8c --- /dev/null +++ b/Framework/IncompleteTest.php @@ -0,0 +1,72 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: IncompleteTest.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +/** + * A marker interface for marking any exception/error as result of an unit + * test as incomplete implementation or currently not implemented. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Interface available since Release 2.0.0 + */ +interface PHPUnit2_Framework_IncompleteTest { +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/IncompleteTestError.php b/Framework/IncompleteTestError.php new file mode 100644 index 00000000000..b9a8662f0af --- /dev/null +++ b/Framework/IncompleteTestError.php @@ -0,0 +1,75 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: IncompleteTestError.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/AssertionFailedError.php'; +require_once 'PHPUnit2/Framework/IncompleteTest.php'; + +/** + * Extension to PHPUnit2_Framework_AssertionFailedError to mark the special + * case of an incomplete test. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class PHPUnit2_Framework_IncompleteTestError extends PHPUnit2_Framework_AssertionFailedError implements PHPUnit2_Framework_IncompleteTest { +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/Test.php b/Framework/Test.php new file mode 100644 index 00000000000..3d87c0fbafc --- /dev/null +++ b/Framework/Test.php @@ -0,0 +1,87 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: Test.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +/** + * A Test can be run and collect its results. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Interface available since Release 2.0.0 + */ +interface PHPUnit2_Framework_Test { + /** + * Counts the number of test cases that will be run by this test. + * + * @return integer + * @access public + */ + public function countTestCases(); + + /** + * Runs a test and collects its result in a TestResult instance. + * + * @param PHPUnit2_Framework_TestResult $result + * @return PHPUnit2_Framework_TestResult + * @access public + */ + public function run($result = NULL); +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/TestCase.php b/Framework/TestCase.php new file mode 100644 index 00000000000..fae89ed60ee --- /dev/null +++ b/Framework/TestCase.php @@ -0,0 +1,292 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: TestCase.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/Assert.php'; +require_once 'PHPUnit2/Framework/Error.php'; +require_once 'PHPUnit2/Framework/Test.php'; +require_once 'PHPUnit2/Framework/TestResult.php'; + +/** + * A TestCase defines the fixture to run multiple tests. + * + * To define a TestCase + * + * 1) Implement a subclass of PHPUnit2_Framework_TestCase. + * 2) Define instance variables that store the state of the fixture. + * 3) Initialize the fixture state by overriding setUp(). + * 4) Clean-up after a test by overriding tearDown(). + * + * Each test runs in its own fixture so there can be no side effects + * among test runs. + * + * Here is an example: + * + * + * value1 = 2; + * $this->value2 = 3; + * } + * } + * ?> + * + * + * For each test implement a method which interacts with the fixture. + * Verify the expected results with assertions specified by calling + * assert with a boolean. + * + * + * assertTrue($this->value1 + $this->value2 == 5); + * } + * ?> + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + * @abstract + */ +abstract class PHPUnit2_Framework_TestCase extends PHPUnit2_Framework_Assert implements PHPUnit2_Framework_Test { + /** + * The name of the test case. + * + * @var string + * @access private + */ + private $name = NULL; + + /** + * Constructs a test case with the given name. + * + * @param string + * @access public + */ + public function __construct($name = NULL) { + if ($name !== NULL) { + $this->setName($name); + } + } + + /** + * Returns a string representation of the test case. + * + * @return string + * @access public + */ + public function toString() { + $class = new ReflectionClass($this); + + return sprintf( + '%s(%s)', + + $this->getName(), + $class->name + ); + } + + /** + * Counts the number of test cases executed by run(TestResult result). + * + * @return integer + * @access public + */ + public function countTestCases() { + return 1; + } + + /** + * Gets the name of a TestCase. + * + * @return string + * @access public + */ + public function getName() { + return $this->name; + } + + /** + * Runs the test case and collects the results in a TestResult object. + * If no TestResult object is passed a new one will be created. + * + * @param PHPUnit2_Framework_TestResult $result + * @return PHPUnit2_Framework_TestResult + * @throws Exception + * @access public + */ + public function run($result = NULL) { + if ($result === NULL) { + $result = $this->createResult(); + } + + // XXX: Workaround for missing ability to declare type-hinted parameters as optional. + else if (!($result instanceof PHPUnit2_Framework_TestResult)) { + throw new Exception( + 'Argument 1 must be an instance of PHPUnit2_Framework_TestResult.' + ); + } + + $result->run($this); + + return $result; + } + + /** + * Runs the bare test sequence. + * + * @access public + */ + public function runBare() { + $catchedException = NULL; + + $this->setUp(); + + try { + $this->runTest(); + } + + catch (Exception $e) { + $catchedException = $e; + } + + $this->tearDown(); + + // Workaround for missing "finally". + if ($catchedException !== NULL) { + throw $catchedException; + } + } + + /** + * Override to run the test and assert its state. + * + * @throws PHPUnit2_Framework_Error + * @access protected + */ + protected function runTest() { + if ($this->name === NULL) { + throw new PHPUnit2_Framework_Error( + 'PHPUnit2_Framework_TestCase::$name must not be NULL.' + ); + } + + try { + $class = new ReflectionClass($this); + $method = $class->getMethod($this->name); + } + + catch (ReflectionException $e) { + $this->fail($e->getMessage()); + } + + $method->invoke($this); + } + + /** + * Sets the name of a TestCase. + * + * @param string + * @access public + */ + public function setName($name) { + $this->name = $name; + } + + /** + * Creates a default TestResult object. + * + * @return PHPUnit2_Framework_TestResult + * @access protected + */ + protected function createResult() { + return new PHPUnit2_Framework_TestResult; + } + + /** + * Sets up the fixture, for example, open a network connection. + * This method is called before a test is executed. + * + * @access protected + */ + protected function setUp() { + } + + /** + * Tears down the fixture, for example, close a network connection. + * This method is called after a test is executed. + * + * @access protected + */ + protected function tearDown() { + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/TestFailure.php b/Framework/TestFailure.php new file mode 100644 index 00000000000..52067782369 --- /dev/null +++ b/Framework/TestFailure.php @@ -0,0 +1,154 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: TestFailure.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/AssertionFailedError.php'; +require_once 'PHPUnit2/Framework/Test.php'; + +/** + * A TestFailure collects a failed test together with the caught exception. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class PHPUnit2_Framework_TestFailure { + /** + * @var PHPUnit2_Framework_Test + * @access protected + */ + protected $failedTest; + + /** + * @var Exception + * @access protected + */ + protected $thrownException; + + /** + * Constructs a TestFailure with the given test and exception. + * + * @param PHPUnit2_Framework_Test $failedTest + * @param Exception $thrownException + * @access public + */ + public function __construct(PHPUnit2_Framework_Test $failedTest, Exception $thrownException) { + $this->failedTest = $failedTest; + $this->thrownException = $thrownException; + } + + /** + * Returns a short description of the failure. + * + * @return string + * @access public + */ + public function toString() { + return sprintf( + '%s: %s', + + $this->failedTest, + $this->thrownException->getMessage() + ); + } + + /** + * Gets the failed test. + * + * @return Test + * @access public + */ + public function failedTest() { + return $this->failedTest; + } + + /** + * Gets the thrown exception. + * + * @return Exception + * @access public + */ + public function thrownException() { + return $this->thrownException; + } + + /** + * Returns the exception's message. + * + * @return string + * @access public + */ + public function exceptionMessage() { + return $this->thrownException()->getMessage(); + } + + /** + * Returns TRUE if the thrown exception + * is of type AssertionFailedError. + * + * @return boolean + * @access public + */ + public function isFailure() { + return ($this->thrownException() instanceof PHPUnit2_Framework_AssertionFailedError); + } +} + + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/TestListener.php b/Framework/TestListener.php new file mode 100644 index 00000000000..85b8e511502 --- /dev/null +++ b/Framework/TestListener.php @@ -0,0 +1,135 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: TestListener.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/AssertionFailedError.php'; +require_once 'PHPUnit2/Framework/TestSuite.php'; + +/** + * A Listener for test progress. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Interface available since Release 2.0.0 + */ +interface PHPUnit2_Framework_TestListener { + /** + * An error occurred. + * + * @param PHPUnit2_Framework_Test $test + * @param Exception $e + * @access public + */ + public function addError(PHPUnit2_Framework_Test $test, Exception $e); + + /** + * A failure occurred. + * + * @param PHPUnit2_Framework_Test $test + * @param PHPUnit2_Framework_AssertionFailedError $e + * @access public + */ + public function addFailure(PHPUnit2_Framework_Test $test, PHPUnit2_Framework_AssertionFailedError $e); + + /** + * Incomplete test. + * + * @param PHPUnit2_Framework_Test $test + * @param Exception $e + * @access public + */ + public function addIncompleteTest(PHPUnit2_Framework_Test $test, Exception $e); + + /** + * A test suite started. + * + * @param PHPUnit2_Framework_TestSuite $suite + * @access public + * @since Method available since Release 2.2.0 + */ + public function startTestSuite(PHPUnit2_Framework_TestSuite $suite); + + /** + * A test suite ended. + * + * @param PHPUnit2_Framework_TestSuite $suite + * @access public + * @since Method available since Release 2.2.0 + */ + public function endTestSuite(PHPUnit2_Framework_TestSuite $suite); + + /** + * A test started. + * + * @param PHPUnit2_Framework_Test $test + * @access public + */ + public function startTest(PHPUnit2_Framework_Test $test); + + /** + * A test ended. + * + * @param PHPUnit2_Framework_Test $test + * @access public + */ + public function endTest(PHPUnit2_Framework_Test $test); +} + + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/TestResult.php b/Framework/TestResult.php new file mode 100644 index 00000000000..249f995501e --- /dev/null +++ b/Framework/TestResult.php @@ -0,0 +1,444 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: TestResult.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/AssertionFailedError.php'; +require_once 'PHPUnit2/Framework/IncompleteTest.php'; +require_once 'PHPUnit2/Framework/TestFailure.php'; +require_once 'PHPUnit2/Framework/TestListener.php'; +require_once 'PHPUnit2/Util/ErrorHandler.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +/** + * A TestResult collects the results of executing a test case. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class PHPUnit2_Framework_TestResult { + /** + * @var array + * @access protected + */ + protected $errors = array(); + + /** + * @var array + * @access protected + */ + protected $failures = array(); + + /** + * @var array + * @access protected + */ + protected $notImplemented = array(); + + /** + * @var array + * @access protected + */ + protected $listeners = array(); + + /** + * @var integer + * @access protected + */ + protected $runTests = 0; + + /** + * Code Coverage information provided by Xdebug. + * + * @var array + * @access protected + */ + protected $codeCoverageInformation = array(); + + /** + * @var boolean + * @access protected + */ + protected $collectCodeCoverageInformation = FALSE; + + /** + * @var boolean + * @access private + */ + private $stop = FALSE; + + /** + * Registers a TestListener. + * + * @param PHPUnit2_Framework_TestListener + * @access public + */ + public function addListener(PHPUnit2_Framework_TestListener $listener) { + $this->listeners[] = $listener; + } + + /** + * Unregisters a TestListener. + * + * @param PHPUnit2_Framework_TestListener $listener + * @access public + */ + public function removeListener(PHPUnit2_Framework_TestListener $listener) { + for ($i = 0; $i < sizeof($this->listeners); $i++) { + if ($this->listeners[$i] === $listener) { + unset($this->listeners[$i]); + } + } + } + + /** + * Adds an error to the list of errors. + * The passed in exception caused the error. + * + * @param PHPUnit2_Framework_Test $test + * @param Exception $e + * @access public + */ + public function addError(PHPUnit2_Framework_Test $test, Exception $e) { + if ($e instanceof PHPUnit2_Framework_IncompleteTest) { + $this->notImplemented[] = new PHPUnit2_Framework_TestFailure($test, $e); + + foreach ($this->listeners as $listener) { + $listener->addIncompleteTest($test, $e); + } + } else { + $this->errors[] = new PHPUnit2_Framework_TestFailure($test, $e); + + foreach ($this->listeners as $listener) { + $listener->addError($test, $e); + } + } + } + + /** + * Adds a failure to the list of failures. + * The passed in exception caused the failure. + * + * @param PHPUnit2_Framework_Test $test + * @param PHPUnit2_Framework_AssertionFailedError $e + * @access public + */ + public function addFailure(PHPUnit2_Framework_Test $test, PHPUnit2_Framework_AssertionFailedError $e) { + if ($e instanceof PHPUnit2_Framework_IncompleteTest) { + $this->notImplemented[] = new PHPUnit2_Framework_TestFailure($test, $e); + + foreach ($this->listeners as $listener) { + $listener->addIncompleteTest($test, $e); + } + } else { + $this->failures[] = new PHPUnit2_Framework_TestFailure($test, $e); + + foreach ($this->listeners as $listener) { + $listener->addFailure($test, $e); + } + } + } + + /** + * Informs the result that a testsuite will be started. + * + * @param PHPUnit2_Framework_TestSuite $suite + * @access public + * @since Method available since Release 2.2.0 + */ + public function startTestSuite(PHPUnit2_Framework_TestSuite $suite) { + foreach ($this->listeners as $listener) { + $listener->startTestSuite($suite); + } + } + + /** + * Informs the result that a testsuite was completed. + * + * @param PHPUnit2_Framework_TestSuite $suite + * @access public + * @since Method available since Release 2.2.0 + */ + public function endTestSuite(PHPUnit2_Framework_TestSuite $suite) { + foreach ($this->listeners as $listener) { + $listener->endTestSuite($suite); + } + } + + /** + * Informs the result that a test will be started. + * + * @param PHPUnit2_Framework_Test $test + * @access public + */ + public function startTest(PHPUnit2_Framework_Test $test) { + $this->runTests += $test->countTestCases(); + + foreach ($this->listeners as $listener) { + $listener->startTest($test); + } + } + + /** + * Informs the result that a test was completed. + * + * @param PHPUnit2_Framework_Test + * @access public + */ + public function endTest(PHPUnit2_Framework_Test $test) { + foreach ($this->listeners as $listener) { + $listener->endTest($test); + } + } + + /** + * Returns TRUE if no incomplete test occured. + * + * @return boolean + * @access public + */ + public function allCompletlyImplemented() { + return $this->notImplementedCount() == 0; + } + + /** + * Gets the number of incomplete tests. + * + * @return integer + * @access public + */ + public function notImplementedCount() { + return sizeof($this->notImplemented); + } + + /** + * Returns an Enumeration for the incomplete tests. + * + * @return array + * @access public + */ + public function notImplemented() { + return $this->notImplemented; + } + + /** + * Gets the number of detected errors. + * + * @return integer + * @access public + */ + public function errorCount() { + return sizeof($this->errors); + } + + /** + * Returns an Enumeration for the errors. + * + * @return array + * @access public + */ + public function errors() { + return $this->errors; + } + + /** + * Gets the number of detected failures. + * + * @return integer + * @access public + */ + public function failureCount() { + return sizeof($this->failures); + } + + /** + * Returns an Enumeration for the failures. + * + * @return array + * @access public + */ + public function failures() { + return $this->failures; + } + + /** + * Enables or disables the collection of Code Coverage information. + * + * @param boolean $flag + * @throws Exception + * @access public + * @since Method available since Release 2.3.0 + */ + public function collectCodeCoverageInformation($flag) { + if (is_bool($flag)) { + $this->collectCodeCoverageInformation = $flag; + } else { + throw new Exception; + } + } + + /** + * Returns Code Coverage data per test case. + * + * Format of the result array: + * + * + * array( + * "testCase" => array( + * "/tested/code.php" => array( + * linenumber => numberOfExecutions + * ) + * ) + * ) + * + * + * @return array + * @access public + */ + public function getCodeCoverageInformation() { + return $this->codeCoverageInformation; + } + + /** + * Runs a TestCase. + * + * @param PHPUnit2_Framework_Test $test + * @access public + */ + public function run(PHPUnit2_Framework_Test $test) { + $this->startTest($test); + + set_error_handler('PHPUnit2_Util_ErrorHandler', E_USER_ERROR); + + $useXdebug = (extension_loaded('xdebug') && $this->collectCodeCoverageInformation); + + if ($useXdebug) { + xdebug_start_code_coverage(XDEBUG_CC_UNUSED); + } + + $globalsBackup = $GLOBALS; + + try { + $test->runBare(); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + $this->addFailure($test, $e); + } + + catch (Exception $e) { + $this->addError($test, $e); + } + + $GLOBALS = $globalsBackup; + + if ($useXdebug) { + $this->codeCoverageInformation[$test->getName()] = PHPUnit2_Util_Filter::getFilteredCodeCoverage( + xdebug_get_code_coverage() + ); + + xdebug_stop_code_coverage(); + } + + restore_error_handler(); + + $this->endTest($test); + } + + /** + * Gets the number of run tests. + * + * @return integer + * @access public + */ + public function runCount() { + return $this->runTests; + } + + /** + * Checks whether the test run should stop. + * + * @return boolean + * @access public + */ + public function shouldStop() { + return $this->stop; + } + + /** + * Marks that the test run should stop. + * + * @access public + */ + public function stop() { + $this->stop = TRUE; + } + + /** + * Returns whether the entire test was successful or not. + * + * @return boolean + * @access public + */ + public function wasSuccessful() { + return empty($this->errors) && empty($this->failures); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/TestSuite.php b/Framework/TestSuite.php new file mode 100644 index 00000000000..bb53846c3f9 --- /dev/null +++ b/Framework/TestSuite.php @@ -0,0 +1,554 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: TestSuite.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/Test.php'; +require_once 'PHPUnit2/Framework/TestCase.php'; +require_once 'PHPUnit2/Framework/TestResult.php'; +require_once 'PHPUnit2/Runner/BaseTestRunner.php'; +require_once 'PHPUnit2/Util/Fileloader.php'; + +/** + * A TestSuite is a composite of Tests. It runs a collection of test cases. + * + * Here is an example using the dynamic test definition. + * + * + * addTest(new MathTest('testPass')); + * ?> + * + * + * Alternatively, a TestSuite can extract the tests to be run automatically. + * To do so you pass a ReflectionClass instance for your + * PHPUnit2_Framework_TestCase class to the PHPUnit2_Framework_TestSuite + * constructor. + * + * + * + * + * + * This constructor creates a suite with all the methods starting with + * "test" that take no arguments. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class PHPUnit2_Framework_TestSuite implements PHPUnit2_Framework_Test { + /** + * The name of the test suite. + * + * @var string + * @access private + */ + private $name = ''; + + /** + * The tests in the test suite. + * + * @var array + * @access private + */ + private $tests = array(); + + /** + * Constructs a new TestSuite: + * + * - PHPUnit2_Framework_TestSuite() constructs an empty TestSuite. + * + * - PHPUnit2_Framework_TestSuite(ReflectionClass) constructs a + * TestSuite from the given class. + * + * - PHPUnit2_Framework_TestSuite(ReflectionClass, String) + * constructs a TestSuite from the given class with the given + * name. + * + * - PHPUnit2_Framework_TestSuite(String) either constructs a + * TestSuite from the given class (if the passed string is the + * name of an existing class) or constructs an empty TestSuite + * with the given name. + * + * @param mixed $theClass + * @param string $name + * @throws Exception + * @access public + */ + public function __construct($theClass = '', $name = '') { + $argumentsValid = FALSE; + + if (is_object($theClass) && + $theClass instanceof ReflectionClass) { + $argumentsValid = TRUE; + } + + else if (is_string($theClass) && $theClass !== '' && class_exists($theClass)) { + $argumentsValid = TRUE; + + if ($name == '') { + $name = $theClass; + } + + $theClass = new ReflectionClass($theClass); + } + + else if (is_string($theClass)) { + $this->setName($theClass); + return; + } + + if (!$argumentsValid) { + throw new Exception; + } + + if ($name != '') { + $this->setName($name); + } else { + $this->setName($theClass->getName()); + } + + $constructor = $theClass->getConstructor(); + + if ($constructor === NULL || + !$constructor->isPublic()) { + $this->addTest( + self::warning( + sprintf( + 'Class %s has no public constructor', + + $theClass->getName() + ) + ) + ); + + return; + } + + $methods = $theClass->getMethods(); + $names = array(); + + foreach ($methods as $method) { + $this->addTestMethod($method, $names, $theClass); + } + + if (empty($this->tests)) { + $this->addTest( + self::warning( + sprintf( + 'No tests found in %s', + + $theClass->getName() + ) + ) + ); + } + } + + /** + * Returns a string representation of the test suite. + * + * @return string + * @access public + */ + public function toString() { + return $this->getName(); + } + + /** + * Adds a test to the suite. + * + * @param PHPUnit2_Framework_Test $test + * @access public + */ + public function addTest(PHPUnit2_Framework_Test $test) { + $this->tests[] = $test; + } + + /** + * Adds the tests from the given class to the suite. + * + * @param mixed $testClass + * @access public + */ + public function addTestSuite($testClass) { + if (is_string($testClass) && + class_exists($testClass)) { + $testClass = new ReflectionClass($testClass); + } + + if (is_object($testClass) && + $testClass instanceof ReflectionClass) { + $this->addTest(new PHPUnit2_Framework_TestSuite($testClass)); + } + } + + /** + * Wraps both addTest() and addTestSuite + * 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 PHPUnit2_Framework_Warning will be created instead, + * leaving the current test run untouched. + * + * @param string $filename + * @throws Exception + * @access public + * @since Method available since Release 2.3.0 + * @author Stefano F. Rausch + */ + public function addTestFile($filename) { + if (!is_string($filename) || !file_exists($filename)) { + throw new Exception; + } + + $declaredClasses = get_declared_classes(); + + PHPUnit2_Util_Fileloader::checkAndLoad($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) + ); + } + } + + /** + * Wrapper for addTestFile() that adds multiple test files. + * + * @param Array $filenames + * @throws Exception + * @access public + * @since Method available since Release 2.3.0 + */ + public function addTestFiles($filenames) { + foreach ($filenames as $filename) { + $this->addTestFile($filename); + } + } + + /** + * Counts the number of test cases that will be run by this test. + * + * @return integer + * @access public + */ + public function countTestCases() { + $count = 0; + + foreach ($this->tests as $test) { + $count += $test->countTestCases(); + } + + return $count; + } + + /** + * @param ReflectionClass $theClass + * @param string $name + * @return PHPUnit2_Framework_Test + * @access public + * @static + */ + public static function createTest(ReflectionClass $theClass, $name) { + if (!$theClass->isInstantiable()) { + return self::warning( + sprintf( + 'Cannot instantiate test case %s.', + $theClass->getName() + ) + ); + } + + $constructor = $theClass->getConstructor(); + + if ($constructor !== NULL) { + $parameters = $constructor->getParameters(); + + if (sizeof($parameters) == 0) { + $test = $theClass->newInstance(); + + if ($test instanceof PHPUnit2_Framework_TestCase) { + $test->setName($name); + } + } + + else if (sizeof($parameters) == 1 && + $parameters[0]->getClass() === NULL) { + $test = $theClass->newInstance($name); + } + + else { + return self::warning( + sprintf( + 'Constructor of class %s is not TestCase($name) or TestCase().', + $theClass->getName() + ) + ); + } + } + + return $test; + } + + /** + * Creates a default TestResult object. + * + * @return PHPUnit2_Framework_TestResult + * @access protected + */ + protected function createResult() { + return new PHPUnit2_Framework_TestResult; + } + + /** + * Returns the name of the suite. + * + * @return string + * @access public + */ + public function getName() { + return $this->name; + } + + /** + * Runs the tests and collects their result in a TestResult. + * + * @param PHPUnit2_Framework_TestResult $result + * @return PHPUnit2_Framework_TestResult + * @throws Exception + * @access public + */ + public function run($result = NULL) { + if ($result === NULL) { + $result = $this->createResult(); + } + + // XXX: Workaround for missing ability to declare type-hinted parameters as optional. + else if (!($result instanceof PHPUnit2_Framework_TestResult)) { + throw new Exception( + 'Argument 1 must be an instance of PHPUnit2_Framework_TestResult.' + ); + } + + $result->startTestSuite($this); + + foreach ($this->tests as $test) { + if ($result->shouldStop()) { + break; + } + + $this->runTest($test, $result); + } + + $result->endTestSuite($this); + + return $result; + } + + /** + * Runs a test. + * + * @param PHPUnit2_Framework_Test $test + * @param PHPUnit2_Framework_TestResult $testResult + * @access public + */ + public function runTest(PHPUnit2_Framework_Test $test, PHPUnit2_Framework_TestResult $result) { + $test->run($result); + } + + /** + * Sets the name of the suite. + * + * @param string + * @access public + */ + public function setName($name) { + $this->name = $name; + } + + /** + * Returns the test at the given index. + * + * @param integer + * @return PHPUnit2_Framework_Test + * @access public + */ + public function testAt($index) { + if (isset($this->tests[$index])) { + return $this->tests[$index]; + } else { + return FALSE; + } + } + + /** + * Returns the number of tests in this suite. + * + * @return integer + * @access public + */ + public function testCount() { + return sizeof($this->tests); + } + + /** + * Returns the tests as an enumeration. + * + * @return array + * @access public + */ + public function tests() { + return $this->tests; + } + + /** + * @param ReflectionMethod $method + * @param array $names + * @param ReflectionClass $theClass + * @access private + */ + private function addTestMethod(ReflectionMethod $method, &$names, ReflectionClass $theClass) { + $name = $method->getName(); + + if (in_array($name, $names)) { + return; + } + + if ($this->isPublicTestMethod($method)) { + $names[] = $name; + + $this->addTest( + self::createTest( + $theClass, + $name + ) + ); + } + + else if ($this->isTestMethod($method)) { + $this->addTest( + self::warning( + sprintf( + 'Test method is not public: %s', + + $name + ) + ) + ); + } + } + + /** + * @param ReflectionMethod $method + * @return boolean + * @access private + */ + private function isPublicTestMethod(ReflectionMethod $method) { + return ($this->isTestMethod($method) && + $method->isPublic()); + } + + /** + * @param ReflectionMethod $method + * @return boolean + * @access private + */ + private function isTestMethod(ReflectionMethod $method) { + return (substr($method->name, 0, 4) == 'test'); + } + + /** + * @param string $message + * @return PHPUnit2_Framework_Warning + * @access private + */ + private static function warning($message) { + require_once 'PHPUnit2/Framework/Warning.php'; + return new PHPUnit2_Framework_Warning($message); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/Warning.php b/Framework/Warning.php new file mode 100644 index 00000000000..ce98ee550a7 --- /dev/null +++ b/Framework/Warning.php @@ -0,0 +1,94 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: Warning.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; + +/** + * A warning. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class PHPUnit2_Framework_Warning extends PHPUnit2_Framework_TestCase { + /** + * @var string + * @access private + */ + private $message = ''; + + /** + * @param string $message + * @access public + */ + public function __construct($message = '') { + $this->message = $message; + parent::__construct('Warning'); + } + + /** + * @access protected + */ + protected function runTest() { + $this->fail($this->message); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Runner/BaseTestRunner.php b/Runner/BaseTestRunner.php new file mode 100644 index 00000000000..c14486426cb --- /dev/null +++ b/Runner/BaseTestRunner.php @@ -0,0 +1,283 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: BaseTestRunner.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/AssertionFailedError.php'; +require_once 'PHPUnit2/Framework/TestListener.php'; +require_once 'PHPUnit2/Runner/StandardTestSuiteLoader.php'; + +/** + * Base class for all test runners. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + * @abstract + */ +abstract class PHPUnit2_Runner_BaseTestRunner implements PHPUnit2_Framework_TestListener { + const STATUS_ERROR = 1; + const STATUS_FAILURE = 2; + const STATUS_INCOMPLETE = 3; + const SUITE_METHODNAME = 'suite'; + + /** + * An error occurred. + * + * @param PHPUnit2_Framework_Test $test + * @param Exception $e + * @access public + */ + public function addError(PHPUnit2_Framework_Test $test, Exception $e) { + $this->testFailed(self::STATUS_ERROR, $test, $e); + } + + /** + * A failure occurred. + * + * @param PHPUnit2_Framework_Test $test + * @param PHPUnit2_Framework_AssertionFailedError $e + * @access public + */ + public function addFailure(PHPUnit2_Framework_Test $test, PHPUnit2_Framework_AssertionFailedError $e) { + $this->testFailed(self::STATUS_FAILURE, $test, $e); + } + + /** + * Incomplete test. + * + * @param PHPUnit2_Framework_Test $test + * @param Exception $e + * @access public + */ + public function addIncompleteTest(PHPUnit2_Framework_Test $test, Exception $e) { + $this->testFailed(self::STATUS_INCOMPLETE, $test, $e); + } + + /** + * A testsuite started. + * + * @param PHPUnit2_Framework_TestSuite $suite + * @access public + * @since Method available since Release 2.2.0 + */ + public function startTestSuite(PHPUnit2_Framework_TestSuite $suite) { + } + + /** + * A testsuite ended. + * + * @param PHPUnit2_Framework_TestSuite $suite + * @access public + * @since Method available since Release 2.2.0 + */ + public function endTestSuite(PHPUnit2_Framework_TestSuite $suite) { + } + + /** + * A test started. + * + * @param PHPUnit2_Framework_Test $test + * @access public + */ + public function startTest(PHPUnit2_Framework_Test $test) { + $this->testStarted($test->getName()); + } + + /** + * A test ended. + * + * @param PHPUnit2_Framework_Test $test + * @access public + */ + public function endTest(PHPUnit2_Framework_Test $test) { + $this->testEnded($test->getName()); + } + + /** + * Returns the loader to be used. + * + * @return PHPUnit2_Runner_TestSuiteLoader + * @access public + */ + public function getLoader() { + return new PHPUnit2_Runner_StandardTestSuiteLoader; + } + + /** + * Returns the Test corresponding to the given suite. + * This is a template method, subclasses override + * the runFailed() and clearStatus() methods. + * + * @param string $suiteClassName + * @param string $suiteClassFile + * @return PHPUnit2_Framework_Test + * @access public + */ + public function getTest($suiteClassName, $suiteClassFile = '') { + if ($suiteClassFile == $suiteClassName . '.php') { + $suiteClassFile = ''; + } + + try { + $testClass = $this->loadSuiteClass($suiteClassName, $suiteClassFile); + } + + catch (Exception $e) { + $this->runFailed($e->getMessage()); + return NULL; + } + + try { + $suiteMethod = $testClass->getMethod(self::SUITE_METHODNAME); + + if (!$suiteMethod->isStatic()) { + $this->runFailed( + 'suite() method must be static.' + ); + + return NULL; + } + + try { + $test = $suiteMethod->invoke(NULL); + } + + catch (ReflectionException $e) { + $this->runFailed( + sprintf( + "Failed to invoke suite() method.\n%s", + + $e->getMessage() + ) + ); + + return NULL; + } + } + + catch (ReflectionException $e) { + $test = new PHPUnit2_Framework_TestSuite($testClass); + } + + $this->clearStatus(); + + return $test; + } + + /** + * Override to define how to handle a failed loading of + * a test suite. + * + * @param string $message + * @access protected + * @abstract + */ + protected abstract function runFailed($message); + + /** + * Returns the loaded ReflectionClass for a suite name. + * + * @param string $suiteClassName + * @param string $suiteClassFile + * @return ReflectionClass + * @access protected + */ + protected function loadSuiteClass($suiteClassName, $suiteClassFile = '') { + return $this->getLoader()->load($suiteClassName, $suiteClassFile); + } + + /** + * Clears the status message. + * + * @access protected + */ + protected function clearStatus() { + } + + /** + * A test started. + * + * @param string $testName + * @access public + * @abstract + */ + public abstract function testStarted($testName); + + /** + * A test ended. + * + * @param string $testName + * @access public + * @abstract + */ + public abstract function testEnded($testName); + + /** + * A test failed. + * + * @param integer $status + * @param PHPUnit2_Framework_Test $test + * @param PHPUnit2_Framework_AssertionFailedError $e + * @access public + * @abstract + */ + public abstract function testFailed($status, PHPUnit2_Framework_Test $test, PHPUnit2_Framework_AssertionFailedError $e); +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Runner/IncludePathTestCollector.php b/Runner/IncludePathTestCollector.php new file mode 100644 index 00000000000..19fc9529cfb --- /dev/null +++ b/Runner/IncludePathTestCollector.php @@ -0,0 +1,184 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: IncludePathTestCollector.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.1.0 + */ + +if (!class_exists('AppendIterator')) { + class AppendIterator implements Iterator { + private $iterators; + + public function __construct() { + $this->iterators = new ArrayIterator(); + } + + public function __call($func, $params) { + return call_user_func_array(array($this->getInnerIterator(), $func), $params); + } + + public function append(Iterator $it) { + $this->iterators->append($it); + } + + public function getInnerIterator() { + return $this->iterators->current(); + } + + public function rewind() { + $this->iterators->rewind(); + + if ($this->iterators->valid()) { + $this->getInnerIterator()->rewind(); + } + } + + public function valid() { + return $this->iterators->valid() && $this->getInnerIterator()->valid(); + } + + public function current() { + return $this->iterators->valid() ? $this->getInnerIterator()->current() : NULL; + } + + public function key() { + return $this->iterators->valid() ? $this->getInnerIterator()->key() : NULL; + } + + public function next() { + if (!$this->iterators->valid()) return; + $this->getInnerIterator()->next(); + + if ($this->getInnerIterator()->valid()) return; + $this->iterators->next(); + + while ($this->iterators->valid()) { + $this->getInnerIterator()->rewind(); + + if ($this->getInnerIterator()->valid()) return; + $this->iterators->next(); + } + } + } +} + +require_once 'PHPUnit2/Runner/TestCollector.php'; + +require_once 'PEAR/Config.php'; + +/** + * An implementation of a TestCollector that consults the + * include path set in the php.ini. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.1.0 + */ + +class PHPUnit2_Runner_IncludePathTestCollector implements PHPUnit2_Runner_TestCollector { + /** + * @return array + * @access public + */ + public function collectTests() { + $config = new PEAR_Config; + $iterator = new AppendIterator; + $result = array(); + + if (substr(PHP_OS, 0, 3) == 'WIN') { + $delimiter = ';'; + } else { + $delimiter = ':'; + } + + $paths = explode($delimiter, ini_get('include_path')); + $paths[] = $config->get('test_dir'); + + foreach ($paths as $path) { + $iterator->append( + new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($path) + ) + ); + } + + foreach ($iterator as $path => $file) { + if ($this->isTestClass($file)) { + if (substr(PHP_OS, 0, 3) == 'WIN') { + $path = str_replace('/', '\\', $path); + } + + $result[] = $path; + } + } + + return $result; + } + + /** + * Considers a file to contain a test class when it contains the + * pattern "Test" in its name and its name ends with ".php". + * + * @param string $classFileName + * @return boolean + * @access protected + */ + protected function isTestClass($classFileName) { + return (strpos($classFileName, 'Test') !== FALSE && substr($classFileName, -4) == '.php') ? TRUE : FALSE; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Runner/StandardTestSuiteLoader.php b/Runner/StandardTestSuiteLoader.php new file mode 100644 index 00000000000..2213e844d9b --- /dev/null +++ b/Runner/StandardTestSuiteLoader.php @@ -0,0 +1,129 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: StandardTestSuiteLoader.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Runner/TestSuiteLoader.php'; +require_once 'PHPUnit2/Util/Fileloader.php'; + +require_once 'PEAR/Config.php'; + +/** + * The standard test suite loader. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class PHPUnit2_Runner_StandardTestSuiteLoader implements PHPUnit2_Runner_TestSuiteLoader { + /** + * @param string $suiteClassName + * @param string $suiteClassFile + * @return ReflectionClass + * @throws Exception + * @access public + */ + public function load($suiteClassName, $suiteClassFile = '') { + $suiteClassName = str_replace('.php', '', $suiteClassName); + $suiteClassFile = !empty($suiteClassFile) ? $suiteClassFile : str_replace('_', '/', $suiteClassName) . '.php'; + + if (!class_exists($suiteClassName)) { + if(!file_exists($suiteClassFile)) { + $config = new PEAR_Config; + + $includePaths = explode(PATH_SEPARATOR, get_include_path()); + $includePaths[] = $config->get('test_dir'); + + foreach ($includePaths as $includePath) { + $file = $includePath . DIRECTORY_SEPARATOR . $suiteClassFile; + + if (file_exists($file)) { + $suiteClassFile = $file; + break; + } + } + } + + PHPUnit2_Util_Fileloader::checkAndLoad($suiteClassFile); + } + + if (class_exists($suiteClassName)) { + return new ReflectionClass($suiteClassName); + } else { + throw new Exception( + sprintf( + 'Class %s could not be found in %s.', + + $suiteClassName, + $suiteClassFile + ) + ); + } + } + + /** + * @param ReflectionClass $aClass + * @return ReflectionClass + * @access public + */ + public function reload(ReflectionClass $aClass) { + return $aClass; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Runner/TestCollector.php b/Runner/TestCollector.php new file mode 100644 index 00000000000..22655aaee3a --- /dev/null +++ b/Runner/TestCollector.php @@ -0,0 +1,77 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: TestCollector.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +/** + * Collects Test class names to be presented + * by the TestSelector. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Interface available since Release 2.0.0 + */ +interface PHPUnit2_Runner_TestCollector { + /** + * @return array + * @access public + */ + public function collectTests(); +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Runner/TestSuiteLoader.php b/Runner/TestSuiteLoader.php new file mode 100644 index 00000000000..f73e9dd563e --- /dev/null +++ b/Runner/TestSuiteLoader.php @@ -0,0 +1,85 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: TestSuiteLoader.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +/** + * An interface to define how a test suite should be loaded. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Interface available since Release 2.0.0 + */ +interface PHPUnit2_Runner_TestSuiteLoader { + /** + * @param string $suiteClassName + * @param string $suiteClassFile + * @return ReflectionClass + * @access public + */ + public function load($suiteClassName, $suiteClassFile = ''); + + /** + * @param ReflectionClass $aClass + * @return ReflectionClass + * @access public + */ + public function reload(ReflectionClass $aClass); +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Runner/Version.php b/Runner/Version.php new file mode 100644 index 00000000000..3a0f117d138 --- /dev/null +++ b/Runner/Version.php @@ -0,0 +1,90 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: Version.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +/** + * This class defines the current version of PHPUnit. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class PHPUnit2_Runner_Version { + /** + * Returns the current version of PHPUnit. + * + * @return string + * @access public + * @static + */ + public static function id() { + return '@package_version@'; + } + + /** + * @return string + * @access public + * @static + */ + public static function getVersionString() { + return 'PHPUnit @package_version@ by Sebastian Bergmann.'; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Samples/BankAccount/BankAccount.php b/Samples/BankAccount/BankAccount.php new file mode 100644 index 00000000000..8e3e244d3cb --- /dev/null +++ b/Samples/BankAccount/BankAccount.php @@ -0,0 +1,133 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: BankAccount.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +/** + * A Bank Account. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.3.0 + */ +class BankAccount { + /** + * The bank account's balance. + * + * @var float + * @access private + */ + private $balance = 0; + + /** + * Returns the bank account's balance. + * + * @return float + * @access public + */ + public function getBalance() { + return $this->balance; + } + + /** + * Sets the bank account's balance. + * + * @param float $balance + * @throws Exception + * @access public + */ + public function setBalance($balance) { + if ($balance >= 0) { + $this->balance = $balance; + } else { + throw new Exception; + } + } + + /** + * Deposits an amount of money to the bank account. + * + * @param float $balance + * @throws Exception + * @access public + */ + public function depositMoney($amount) { + if ($amount >= 0) { + $this->balance += $amount; + } else { + throw new Exception; + } + } + + /** + * Withdraws an amount of money from the bank account. + * + * @param float $balance + * @throws Exception + * @access public + */ + public function withdrawMoney($amount) { + if ($amount >= 0 && $this->balance >= $amount) { + $this->balance -= $amount; + } else { + throw new Exception; + } + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Samples/BankAccount/BankAccountTest.php b/Samples/BankAccount/BankAccountTest.php new file mode 100644 index 00000000000..f1e35cf30c6 --- /dev/null +++ b/Samples/BankAccount/BankAccountTest.php @@ -0,0 +1,150 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: BankAccountTest.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; +require_once 'BankAccount.php'; + +/** + * Tests for the BankAccount class. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.3.0 + */ +class BankAccountTest extends PHPUnit2_Framework_TestCase { + /** + * BankAccount object used as the tests' fixture. + * + * @var BankAccount + * @access private + */ + private $ba; + + /** + * Sets up the test fixture. + * + * @access protected + */ + protected function setUp() { + $this->ba = new BankAccount; + } + + /** + * Asserts that the balance is initially zero. + * + * @access public + */ + public function testBalanceIsInitiallyZero() { + $this->assertEquals(0, $this->ba->getBalance()); + } + + /** + * Asserts that the balance cannot become negative. + * + * @access public + */ + public function testBalanceCannotBecomeNegative() { + try { + $this->ba->withdrawMoney(1); + } + + catch (Exception $e) { + return; + } + + $this->fail(); + } + + /** + * Asserts that the balance cannot become negative. + * + * @access public + */ + public function testBalanceCannotBecomeNegative2() { + try { + $this->ba->depositMoney(-1); + } + + catch (Exception $e) { + return; + } + + $this->fail(); + } + + /** + * Asserts that the balance cannot become negative. + * + * @access public + */ + public function testBalanceCannotBecomeNegative3() { + try { + $this->ba->setBalance(-1); + } + + catch (Exception $e) { + return; + } + + $this->fail(); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Samples/Money/IMoney.php b/Samples/Money/IMoney.php new file mode 100644 index 00000000000..7519e79b440 --- /dev/null +++ b/Samples/Money/IMoney.php @@ -0,0 +1,82 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: IMoney.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +require_once 'Money.php'; +require_once 'MoneyBag.php'; + +/** + * Money Interface. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.3.0 + */ +interface IMoney { + public function add(IMoney $m); + public function addMoney(Money $m); + public function addMoneyBag(MoneyBag $s); + public function isZero(); + public function multiply($factor); + public function negate(); + public function subtract(IMoney $m); + public function appendTo(MoneyBag $m); +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Samples/Money/Money.php b/Samples/Money/Money.php new file mode 100644 index 00000000000..95fff56cd48 --- /dev/null +++ b/Samples/Money/Money.php @@ -0,0 +1,146 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: Money.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +require_once 'IMoney.php'; + +/** + * A Money. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.3.0 + */ +class Money implements IMoney { + private $fAmount; + private $fCurrency; + + public function __construct($amount, $currency) { + $this->fAmount = $amount; + $this->fCurrency = $currency; + } + + public function add(IMoney $m) { + return $m->addMoney($this); + } + + public function addMoney(Money $m) { + if ($this->currency() == $m->currency()) { + return new Money($this->amount() + $m->amount(), $this->currency()); + } + + return MoneyBag::create($this, $m); + } + + public function addMoneyBag(MoneyBag $s) { + return $s->addMoney($this); + } + + public function amount() { + return $this->fAmount; + } + + public function currency() { + return $this->fCurrency; + } + + public function equals($anObject) { + if ($this->isZero() && + $anObject instanceof IMoney) { + return $anObject->isZero(); + } + + if ($anObject instanceof Money) { + return ($this->currency() == $anObject->currency() && + $this->amount() == $anObject->amount()); + } + + return FALSE; + } + + public function hashCode() { + return crc32($this->fCurrency) + $this->fAmount; + } + + public function isZero() { + return $this->amount() == 0; + } + + public function multiply($factor) { + return new Money($this->amount() * $factor, $this->currency()); + } + + public function negate() { + return new Money(-1 * $this->amount(), $this->currency()); + } + + public function subtract(IMoney $m) { + return $this->add($m->negate()); + } + + public function toString() { + return '[' . $this->amount() . ' ' . $this->currency() . ']'; + } + + public function appendTo(MoneyBag $m) { + $m->appendMoney($this); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Samples/Money/MoneyBag.php b/Samples/Money/MoneyBag.php new file mode 100644 index 00000000000..463e383df46 --- /dev/null +++ b/Samples/Money/MoneyBag.php @@ -0,0 +1,240 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: MoneyBag.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +require_once 'IMoney.php'; +require_once 'Money.php'; + +/** + * A MoneyBag. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.3.0 + */ +class MoneyBag implements IMoney { + private $fMonies = array(); + + public static function create(IMoney $m1, IMoney $m2) { + $result = new MoneyBag; + $m1->appendTo($result); + $m2->appendTo($result); + + return $result->simplify(); + } + + public function add(IMoney $m) { + return $m->addMoneyBag($this); + } + + public function addMoney(Money $m) { + return MoneyBag::create($m, $this); + } + + public function addMoneyBag(MoneyBag $s) { + return MoneyBag::create($s, $this); + } + + public function appendBag(MoneyBag $aBag) { + foreach ($aBag->monies() as $aMoney) { + $this->appendMoney($aMoney); + } + } + + public function monies() { + return $this->fMonies; + } + + public function appendMoney(Money $aMoney) { + if ($aMoney->isZero()) { + return; + } + + $old = $this->findMoney($aMoney->currency()); + + if ($old == NULL) { + $this->fMonies[] = $aMoney; + return; + } + + $keys = array_keys($this->fMonies); + + for ($i = 0; $i < sizeof($keys); $i++) { + if ($this->fMonies[$keys[$i]] === $old) { + unset($this->fMonies[$keys[$i]]); + break; + } + } + + $sum = $old->add($aMoney); + + if ($sum->isZero()) { + return; + } + + $this->fMonies[] = $sum; + } + + public function equals($anObject) { + if ($this->isZero() && + $anObject instanceof IMoney) { + return $anObject->isZero(); + } + + if ($anObject instanceof MoneyBag) { + if (sizeof($anObject->monies()) != sizeof($this->fMonies)) { + return FALSE; + } + + foreach ($this->fMonies as $m) { + if (!$anObject->contains($m)) { + return FALSE; + } + } + + return TRUE; + } + + return FALSE; + } + + private function findMoney($currency) { + foreach ($this->fMonies as $m) { + if ($m->currency() == $currency) { + return $m; + } + } + + return NULL; + } + + private function contains(Money $m) { + $found = $this->findMoney($m->currency()); + + if ($found == NULL) { + return FALSE; + } + + return $found->amount() == $m->amount(); + } + + public function hashCode() { + $hash = 0; + + foreach ($this->fMonies as $m) { + $hash ^= $m->hashCode(); + } + + return $hash; + } + + public function isZero() { + return sizeof($this->fMonies) == 0; + } + + public function multiply($factor) { + $result = new MoneyBag; + + if ($factor != 0) { + foreach ($this->fMonies as $m) { + $result->appendMoney($m->multiply($factor)); + } + } + + return $result; + } + + public function negate() { + $result = new MoneyBag; + + foreach ($this->fMonies as $m) { + $result->appendMoney($m->negate()); + } + + return $result; + } + + private function simplify() { + if (sizeof($this->fMonies) == 1) { + return array_pop($this->fMonies); + } + + return $this; + } + + public function subtract(IMoney $m) { + return $this->add($m->negate()); + } + + public function toString() { + $buffer = '{'; + + foreach ($this->fMonies as $m) { + $buffer .= $m->toString(); + } + + return $buffer . '}'; + } + + public function appendTo(MoneyBag $m) { + $m->appendBag($this); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Samples/Money/MoneyTest.php b/Samples/Money/MoneyTest.php new file mode 100644 index 00000000000..f2df0309681 --- /dev/null +++ b/Samples/Money/MoneyTest.php @@ -0,0 +1,234 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: MoneyTest.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; + +require_once 'Money.php'; +require_once 'MoneyBag.php'; + +/** + * Tests for the Money and MoneyBag classes. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.3.0 + */ +class MoneyTest extends PHPUnit2_Framework_TestCase { + private $f12EUR; + private $f14EUR; + private $f7USD; + private $f21USD; + + private $fMB1; + private $fMB2; + + protected function setUp() { + $this->f12EUR = new Money(12, 'EUR'); + $this->f14EUR = new Money(14, 'EUR'); + $this->f7USD = new Money( 7, 'USD'); + $this->f21USD = new Money(21, 'USD'); + + $this->fMB1 = MoneyBag::create($this->f12EUR, $this->f7USD); + $this->fMB2 = MoneyBag::create($this->f14EUR, $this->f21USD); + } + + public function testBagMultiply() { + // {[12 EUR][7 USD]} *2 == {[24 EUR][14 USD]} + $expected = MoneyBag::create(new Money(24, 'EUR'), new Money(14, 'USD')); + + self::assertTrue($expected->equals($this->fMB1->multiply(2))); + self::assertTrue($this->fMB1->equals($this->fMB1->multiply(1))); + self::assertTrue($this->fMB1->multiply(0)->isZero()); + } + + public function testBagNegate() { + // {[12 EUR][7 USD]} negate == {[-12 EUR][-7 USD]} + $expected = MoneyBag::create(new Money(-12, 'EUR'), new Money(-7, 'USD')); + self::assertTrue($expected->equals($this->fMB1->negate())); + } + + public function testBagSimpleAdd() { + // {[12 EUR][7 USD]} + [14 EUR] == {[26 EUR][7 USD]} + $expected = MoneyBag::create(new Money(26, 'EUR'), new Money(7, 'USD')); + self::assertTrue($expected->equals($this->fMB1->add($this->f14EUR))); + } + + public function testBagSubtract() { + // {[12 EUR][7 USD]} - {[14 EUR][21 USD] == {[-2 EUR][-14 USD]} + $expected = MoneyBag::create(new Money(-2, 'EUR'), new Money(-14, 'USD')); + self::assertTrue($expected->equals($this->fMB1->subtract($this->fMB2))); + } + + public function testBagSumAdd() { + // {[12 EUR][7 USD]} + {[14 EUR][21 USD]} == {[26 EUR][28 USD]} + $expected = MoneyBag::create(new Money(26, 'EUR'), new Money(28, 'USD')); + self::assertTrue($expected->equals($this->fMB1->add($this->fMB2))); + } + + public function testIsZero() { + //self::assertTrue($this->fMB1->subtract($this->fMB1)->isZero()); + self::assertTrue(MoneyBag::create(new Money (0, 'EUR'), new Money (0, 'USD'))->isZero()); + } + + public function testMixedSimpleAdd() { + // [12 EUR] + [7 USD] == {[12 EUR][7 USD]} + $expected = MoneyBag::create($this->f12EUR, $this->f7USD); + self::assertTrue($expected->equals($this->f12EUR->add($this->f7USD))); + } + + public function testBagNotEquals() { + $bag1 = MoneyBag::create($this->f12EUR, $this->f7USD); + $bag2 = new Money(12, 'CHF'); + $bag2->add($this->f7USD); + self::assertFalse($bag1->equals($bag2)); + } + + public function testMoneyBagEquals() { + self::assertTrue(!$this->fMB1->equals(NULL)); + + self::assertTrue($this->fMB1->equals($this->fMB1)); + $equal = MoneyBag::create(new Money(12, 'EUR'), new Money(7, 'USD')); + self::assertTrue($this->fMB1->equals($equal)); + self::assertTrue(!$this->fMB1->equals($this->f12EUR)); + self::assertTrue(!$this->f12EUR->equals($this->fMB1)); + self::assertTrue(!$this->fMB1->equals($this->fMB2)); + } + + public function testMoneyBagHash() { + $equal = MoneyBag::create(new Money(12, 'EUR'), new Money(7, 'USD')); + self::assertEquals($this->fMB1->hashCode(), $equal->hashCode()); + } + + public function testMoneyEquals() { + self::assertTrue(!$this->f12EUR->equals(NULL)); + $equalMoney = new Money(12, 'EUR'); + self::assertTrue($this->f12EUR->equals($this->f12EUR)); + self::assertTrue($this->f12EUR->equals($equalMoney)); + self::assertEquals($this->f12EUR->hashCode(), $equalMoney->hashCode()); + self::assertFalse($this->f12EUR->equals($this->f14EUR)); + } + + public function testMoneyHash() { + self::assertNotNull($this->f12EUR); + $equal= new Money(12, 'EUR'); + self::assertEquals($this->f12EUR->hashCode(), $equal->hashCode()); + } + + public function testSimplify() { + $money = MoneyBag::create(new Money(26, 'EUR'), new Money(28, 'EUR')); + self::assertTrue($money->equals(new Money(54, 'EUR'))); + } + + public function testNormalize2() { + // {[12 EUR][7 USD]} - [12 EUR] == [7 USD] + $expected = new Money(7, 'USD'); + self::assertTrue($expected->equals($this->fMB1->subtract($this->f12EUR))); + } + + public function testNormalize3() { + // {[12 EUR][7 USD]} - {[12 EUR][3 USD]} == [4 USD] + $ms1 = MoneyBag::create(new Money(12, 'EUR'), new Money(3, 'USD')); + $expected = new Money(4, 'USD'); + self::assertTrue($expected->equals($this->fMB1->subtract($ms1))); + } + + public function testNormalize4() { + // [12 EUR] - {[12 EUR][3 USD]} == [-3 USD] + $ms1 = MoneyBag::create(new Money(12, 'EUR'), new Money(3, 'USD')); + $expected = new Money(-3, 'USD'); + self::assertTrue($expected->equals($this->f12EUR->subtract($ms1))); + } + + public function testPrint() { + self::assertEquals('[12 EUR]', $this->f12EUR->toString()); + } + + public function testSimpleAdd() { + // [12 EUR] + [14 EUR] == [26 EUR] + $expected = new Money(26, 'EUR'); + self::assertTrue($expected->equals($this->f12EUR->add($this->f14EUR))); + } + + public function testSimpleBagAdd() { + // [14 EUR] + {[12 EUR][7 USD]} == {[26 EUR][7 USD]} + $expected = MoneyBag::create(new Money(26, 'EUR'), new Money(7, 'USD')); + self::assertTrue($expected->equals($this->f14EUR->add($this->fMB1))); + } + + public function testSimpleMultiply() { + // [14 EUR] *2 == [28 EUR] + $expected = new Money(28, 'EUR'); + self::assertTrue($expected->equals($this->f14EUR->multiply(2))); + } + + public function testSimpleNegate() { + // [14 EUR] negate == [-14 EUR] + $expected = new Money(-14, 'EUR'); + self::assertTrue($expected->equals($this->f14EUR->negate())); + } + + public function testSimpleSubtract() { + // [14 EUR] - [12 EUR] == [2 EUR] + $expected = new Money(2, 'EUR'); + self::assertTrue($expected->equals($this->f14EUR->subtract($this->f12EUR))); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/AllTests.php b/Tests/AllTests.php new file mode 100644 index 00000000000..18d50b5ca5a --- /dev/null +++ b/Tests/AllTests.php @@ -0,0 +1,101 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: AllTests.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +if (!defined('PHPUnit2_MAIN_METHOD')) { + define('PHPUnit2_MAIN_METHOD', 'AllTests::main'); +} + +require_once 'PHPUnit2/Framework/TestSuite.php'; +require_once 'PHPUnit2/TextUI/TestRunner.php'; + +require_once 'Framework/AllTests.php'; +require_once 'Extensions/AllTests.php'; +require_once 'Runner/AllTests.php'; +require_once 'Util/AllTests.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class AllTests { + public static function main() { + PHPUnit2_TextUI_TestRunner::run(self::suite()); + } + + public static function suite() { + $suite = new PHPUnit2_Framework_TestSuite('PHPUnit'); + + $suite->addTest(Framework_AllTests::suite()); + $suite->addTest(Extensions_AllTests::suite()); + $suite->addTest(Runner_AllTests::suite()); + $suite->addTest(Util_AllTests::suite()); + + return $suite; + } +} + +if (PHPUnit2_MAIN_METHOD == 'AllTests::main') { + AllTests::main(); +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/DoubleTestCase.php b/Tests/DoubleTestCase.php new file mode 100644 index 00000000000..71a81912652 --- /dev/null +++ b/Tests/DoubleTestCase.php @@ -0,0 +1,93 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: DoubleTestCase.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/Test.php'; +require_once 'PHPUnit2/Framework/TestCase.php'; +require_once 'PHPUnit2/Framework/TestResult.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class DoubleTestCase implements PHPUnit2_Framework_Test { + private $testCase; + + public function __construct(PHPUnit2_Framework_TestCase $testCase) { + $this->testCase = $testCase; + } + + public function countTestCases() { + return 2; + } + + public function run($result = NULL) { + $result->startTest($this); + + $this->testCase->runBare(); + $this->testCase->runBare(); + + $result->endTest($this); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/Error.php b/Tests/Error.php new file mode 100644 index 00000000000..3323d2d566e --- /dev/null +++ b/Tests/Error.php @@ -0,0 +1,76 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: Error.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class Error extends PHPUnit2_Framework_TestCase { + public function runTest() { + throw new Exception; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/Extensions/AllTests.php b/Tests/Extensions/AllTests.php new file mode 100644 index 00000000000..88cc5ea0225 --- /dev/null +++ b/Tests/Extensions/AllTests.php @@ -0,0 +1,108 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: AllTests.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +if (!defined('PHPUnit2_MAIN_METHOD')) { + define('PHPUnit2_MAIN_METHOD', 'Extensions_AllTests::main'); +} + +require_once 'PHPUnit2/Framework/TestSuite.php'; +require_once 'PHPUnit2/TextUI/TestRunner.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +require_once 'Extensions/ExceptionTestCaseTest.php'; +require_once 'Extensions/ExtensionTest.php'; +require_once 'Extensions/PerformanceTestCaseTest.php'; +require_once 'Extensions/RepeatedTestTest.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class Extensions_AllTests { + public static function main() { + PHPUnit2_TextUI_TestRunner::run(self::suite()); + } + + public static function suite() { + $suite = new PHPUnit2_Framework_TestSuite('PHPUnit Extensions'); + + $suite->addTestSuite('Extensions_ExceptionTestCaseTest'); + $suite->addTestSuite('Extensions_ExtensionTest'); + $suite->addTestSuite('Extensions_PerformanceTestCaseTest'); + $suite->addTestSuite('Extensions_RepeatedTestTest'); + + PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Extensions/ExceptionTestCase.php'); + PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Extensions/PerformanceTestCase.php'); + PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Extensions/RepeatedTest.php'); + PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Extensions/TestDecorator.php'); + PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Extensions/TestSetup.php'); + + return $suite; + } +} + +if (PHPUnit2_MAIN_METHOD == 'Extensions_AllTests::main') { + Extensions_AllTests::main(); +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/Extensions/ExceptionTestCaseTest.php b/Tests/Extensions/ExceptionTestCaseTest.php new file mode 100644 index 00000000000..c984ed82087 --- /dev/null +++ b/Tests/Extensions/ExceptionTestCaseTest.php @@ -0,0 +1,105 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: ExceptionTestCaseTest.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; + +require_once 'ThrowExceptionTestCase.php'; +require_once 'ThrowNoExceptionTestCase.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class Extensions_ExceptionTestCaseTest extends PHPUnit2_Framework_TestCase { + public function testException() { + $test = new ThrowExceptionTestCase('test'); + $test->setExpectedException('Exception'); + + $result = $test->run(); + + $this->assertEquals(1, $result->runCount()); + $this->assertTrue($result->wasSuccessful()); + } + + public function testNoException() { + $test = new ThrowNoExceptionTestCase('test'); + $test->setExpectedException('Exception'); + + $result = $test->run(); + + $this->assertEquals(1, $result->failureCount()); + $this->assertEquals(1, $result->runCount()); + } + + public function testWrongException() { + $test = new ThrowExceptionTestCase('test'); + $test->setExpectedException('ReflectionException'); + + $result = $test->run(); + + $this->assertEquals(1, $result->errorCount()); + $this->assertEquals(1, $result->runCount()); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/Extensions/ExtensionTest.php b/Tests/Extensions/ExtensionTest.php new file mode 100644 index 00000000000..769b9036ca3 --- /dev/null +++ b/Tests/Extensions/ExtensionTest.php @@ -0,0 +1,119 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: ExtensionTest.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Extensions/TestSetup.php'; +require_once 'PHPUnit2/Framework/TestCase.php'; +require_once 'PHPUnit2/Framework/TestSuite.php'; + +require_once 'Error.php'; +require_once 'Failure.php'; +require_once 'Success.php'; +require_once 'TornDown6.php'; +require_once 'WasRun.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class Extensions_ExtensionTest extends PHPUnit2_Framework_TestCase { + public function testRunningErrorInTestSetup() { + $wrapper = new PHPUnit2_Extensions_TestSetup(new Failure); + $result = $wrapper->run(); + + $this->assertFalse($result->wasSuccessful()); + } + + public function testRunningErrorsInTestSetup() { + $suite = new PHPUnit2_Framework_TestSuite; + $suite->addTest(new Error); + $suite->addTest(new Failure); + + $wrapper = new PHPUnit2_Extensions_TestSetup($suite); + $result = $wrapper->run(); + + $this->assertEquals(1, $result->errorCount()); + $this->assertEquals(1, $result->failureCount()); + } + + public function testSetupErrorDontTearDown() { +/* + $wrapper = new TornDown6(new WasRun); + $result = $wrapper->run(); + + $this->assertFalse($wrapper->tornDown); +*/ + } + + public function testSetupErrorInTestSetup() { +/* + $test = new WasRun; + $wrapper = new TornDown6($test); + $result = $wrapper->run(); + + $this->assertFalse($test->wasRun); + $this->assertFalse($result->wasSuccessful()); +*/ + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/Extensions/PerformanceTestCaseTest.php b/Tests/Extensions/PerformanceTestCaseTest.php new file mode 100644 index 00000000000..9d5f192346e --- /dev/null +++ b/Tests/Extensions/PerformanceTestCaseTest.php @@ -0,0 +1,92 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: PerformanceTestCaseTest.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/AssertionFailedError.php'; +require_once 'PHPUnit2/Framework/TestCase.php'; +require_once 'PHPUnit2/Framework/TestResult.php'; + +require_once 'Sleep.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class Extensions_PerformanceTestCaseTest extends PHPUnit2_Framework_TestCase { + public function testDoesNotExceedMaxRunningTime() { + $test = new Sleep('testSleepTwoSeconds'); + $test->setMaxRunningTime(3); + + $result = $test->run(); + $this->assertEquals(0, $result->failureCount()); + } + + public function testExceedsMaxRunningTime() { + $test = new Sleep('testSleepTwoSeconds'); + $test->setMaxRunningTime(1); + + $result = $test->run(); + $this->assertEquals(1, $result->failureCount()); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/Extensions/RepeatedTestTest.php b/Tests/Extensions/RepeatedTestTest.php new file mode 100644 index 00000000000..5dabc02f238 --- /dev/null +++ b/Tests/Extensions/RepeatedTestTest.php @@ -0,0 +1,122 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: RepeatedTestTest.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; +require_once 'PHPUnit2/Framework/TestResult.php'; +require_once 'PHPUnit2/Framework/TestSuite.php'; +require_once 'PHPUnit2/Extensions/RepeatedTest.php'; + +require_once 'Success.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class Extensions_RepeatedTestTest extends PHPUnit2_Framework_TestCase { + private $suite; + + public function __construct() { + $this->suite = new PHPUnit2_Framework_TestSuite; + + $this->suite->addTest(new Success); + $this->suite->addTest(new Success); + } + + public function testRepeatedOnce() { + $test = new PHPUnit2_Extensions_RepeatedTest($this->suite, 1); + $this->assertEquals(2, $test->countTestCases()); + + $result = $test->run(); + $this->assertEquals(2, $result->runCount()); + } + + public function testRepeatedMoreThanOnce() { + $test = new PHPUnit2_Extensions_RepeatedTest($this->suite, 3); + $this->assertEquals(6, $test->countTestCases()); + + $result = $test->run(); + $this->assertEquals(6, $result->runCount()); + } + + public function testRepeatedZero() { + $test = new PHPUnit2_Extensions_RepeatedTest($this->suite, 0); + $this->assertEquals(0, $test->countTestCases()); + + $result = $test->run(); + $this->assertEquals(0, $result->runCount()); + } + + public function testRepeatedNegative() { + try { + $test = new PHPUnit2_Extensions_RepeatedTest($this->suite, -1); + } + + catch (Exception $e) { + return; + } + + $this->fail('Should throw an Exception'); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/Failure.php b/Tests/Failure.php new file mode 100644 index 00000000000..22864310286 --- /dev/null +++ b/Tests/Failure.php @@ -0,0 +1,76 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: Failure.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class Failure extends PHPUnit2_Framework_TestCase { + public function runTest() { + $this->fail(); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/Framework/AllTests.php b/Tests/Framework/AllTests.php new file mode 100644 index 00000000000..9938211dd3c --- /dev/null +++ b/Tests/Framework/AllTests.php @@ -0,0 +1,119 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: AllTests.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +if (!defined('PHPUnit2_MAIN_METHOD')) { + define('PHPUnit2_MAIN_METHOD', 'Framework_AllTests::main'); +} + +require_once 'PHPUnit2/Framework/TestSuite.php'; +require_once 'PHPUnit2/TextUI/TestRunner.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +require_once 'Framework/AssertTest.php'; +require_once 'Framework/ComparisonFailureTest.php'; +require_once 'Framework/SuiteTest.php'; +require_once 'Framework/TestCaseTest.php'; +require_once 'Framework/TestImplementorTest.php'; +require_once 'Framework/TestListenerTest.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class Framework_AllTests { + public static function main() { + PHPUnit2_TextUI_TestRunner::run(self::suite()); + } + + public static function suite() { + $suite = new PHPUnit2_Framework_TestSuite('PHPUnit Framework'); + + $suite->addTestSuite('Framework_AssertTest'); + $suite->addTestSuite('Framework_ComparisonFailureTest'); + $suite->addTestSuite('Framework_SuiteTest'); + $suite->addTestSuite('Framework_TestCaseTest'); + $suite->addTestSuite('Framework_TestImplementorTest'); + $suite->addTestSuite('Framework_TestListenerTest'); + + PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Framework/Assert.php'); + PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Framework/AssertionFailedError.php'); + PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Framework/ComparisonFailure.php'); + PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Framework/IncompleteTest.php'); + PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Framework/IncompleteTestError.php'); + PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Framework/Test.php'); + PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Framework/TestCase.php'); + PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Framework/TestFailure.php'); + PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Framework/TestListener.php'); + PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Framework/TestResult.php'); + PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Framework/TestSuite.php'); + PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Framework/Warning.php'); + + return $suite; + } +} + +if (PHPUnit2_MAIN_METHOD == 'Framework_AllTests::main') { + Framework_AllTests::main(); +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/Framework/AssertTest.php b/Tests/Framework/AssertTest.php new file mode 100644 index 00000000000..6364c2e213e --- /dev/null +++ b/Tests/Framework/AssertTest.php @@ -0,0 +1,574 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: AssertTest.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; + +require_once 'TestIterator.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class Framework_AssertTest extends PHPUnit2_Framework_TestCase { + public function testFail() { + try { + $this->fail(); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertArrayContainsObject() { + $a = new StdClass; + $b = new StdClass; + + $this->assertContains($a, array($a)); + + try { + $this->assertContains($a, array($b)); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertArrayContainsString() { + $this->assertContains('foo', array('foo')); + + try { + $this->assertContains('foo', array('bar')); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertIteratorContainsObject() { + $foo = new StdClass; + + $this->assertContains($foo, new TestIterator(array($foo))); + + try { + $this->assertContains($foo, new TestIterator(array(new StdClass))); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertIteratorContainsString() { + $this->assertContains('foo', new TestIterator(array('foo'))); + + try { + $this->assertContains('foo', new TestIterator(array('bar'))); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertStringContainsString() { + $this->assertContains('foo', 'foobar'); + + try { + $this->assertContains('foo', 'bar'); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertArrayNotContainsObject() { + $a = new StdClass; + $b = new StdClass; + + $this->assertNotContains($a, array($b)); + + try { + $this->assertNotContains($a, array($a)); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertArrayNotContainsString() { + $this->assertNotContains('foo', array('bar')); + + try { + $this->assertNotContains('foo', array('foo')); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertStringNotContainsString() { + $this->assertNotContains('foo', 'bar'); + + try { + $this->assertNotContains('foo', 'foo'); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertEqualsArray() { + $this->assertEquals(array('a', 'b'), array('a', 'b')); + + try { + $this->assertEquals(array('a', 'b'), array('b', 'a')); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotEqualsArray() { + $this->assertNotEquals(array('a', 'b'), array('b', 'a')); + + try { + $this->assertNotEquals(array('a', 'b'), array('a', 'b')); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertEqualsFloat() { + $this->assertEquals(2.3, 2.3); + + try { + $this->assertEquals(2.3, 4.2); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotEqualsFloat() { + $this->assertNotEquals(2.3, 4.2); + + try { + $this->assertNotEquals(2.3, 2.3); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertEqualsFloatDelta() { + $this->assertEquals(2.3, 2.5, '', 0.5); + + try { + $this->assertEquals(2.3, 4.2, '', 0.5); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotEqualsFloatDelta() { + $this->assertNotEquals(2.3, 4.2, '', 0.5); + + try { + $this->assertNotEquals(2.3, 2.5, '', 0.5); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertEqualsInteger() { + $this->assertEquals(23, 23); + + try { + $this->assertEquals(23, 42); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotEqualsInteger() { + $this->assertNotEquals(23, 42); + + try { + $this->assertNotEquals(23, 23); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertEqualsObject() { + $this->assertEquals(new StdClass, new StdClass); + + try { + $this->assertEquals(new StdClass, new Exception); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotEqualsObject() { + $this->assertNotEquals(new StdClass, new Exception); + + try { + $this->assertNotEquals(new StdClass, new StdClass); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertEqualsString() { + $this->assertEquals('ab', 'ab'); + + try { + $this->assertEquals('ab', 'ba'); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotEqualsString() { + $this->assertNotEquals('ab', 'ba'); + + try { + $this->assertNotEquals('ab', 'ab'); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNull() { + $this->assertNull(NULL); + + try { + $this->assertNull(new StdClass); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotNull() { + $this->assertNotNull(new StdClass); + + try { + $this->assertNotNull(NULL); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertTrue() { + $this->assertTrue(TRUE); + + try { + $this->assertTrue(FALSE); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertFalse() { + $this->assertFalse(FALSE); + + try { + $this->assertFalse(TRUE); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertSame() { + $o = new StdClass; + + $this->assertSame($o, $o); + + try { + $this->assertSame( + new StdClass, + new StdClass + ); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotSame() { + $this->assertNotSame( + new StdClass, + NULL + ); + + $this->assertNotSame( + NULL, + new StdClass + ); + + $this->assertNotSame( + new StdClass, + new StdClass + ); + + $o = new StdClass; + + try { + $this->assertNotSame($o, $o); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotSameFailsNull() { + try { + $this->assertNotSame(NULL, NULL); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertTypeClass() { + $this->assertType('StdClass', new StdClass); + + try { + $this->assertType('StdClass', new Exception); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); +} + + public function testAssertNotTypeClass() { + $this->assertNotType('StdClass', new Exception); + + try { + $this->assertNotType('StdClass', new StdClass); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertTypeInteger() { + $this->assertType('integer', 2204); + + try { + $this->assertType('integer', 'string'); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotTypeInteger() { + $this->assertNotType('integer', 'string'); + + try { + $this->assertNotType('integer', 2204); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertTypeString() { + $this->assertType('string', 'string'); + + try { + $this->assertType('string', 2204); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotTypeString() { + $this->assertNotType('string', 2204); + + try { + $this->assertNotType('string', 'string'); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/Framework/ComparisonFailureTest.php b/Tests/Framework/ComparisonFailureTest.php new file mode 100644 index 00000000000..8b519c54edf --- /dev/null +++ b/Tests/Framework/ComparisonFailureTest.php @@ -0,0 +1,172 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: ComparisonFailureTest.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/ComparisonFailure.php'; +require_once 'PHPUnit2/Framework/TestCase.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class Framework_ComparisonFailureTest extends PHPUnit2_Framework_TestCase { + public function testComparisonErrorMessage() { + $failure = new PHPUnit2_Framework_ComparisonFailure('a', 'b', 'c'); + + $this->assertEquals( + 'c expected: but was: ', + $failure->toString() + ); + } + + public function testComparisonErrorStartSame() { + $failure = new PHPUnit2_Framework_ComparisonFailure('ba', 'bc'); + + $this->assertEquals( + 'expected: <...a> but was: <...c>', + $failure->toString() + ); + } + + public function testComparisonErrorEndSame() { + $failure = new PHPUnit2_Framework_ComparisonFailure('ab', 'cb'); + + $this->assertEquals( + 'expected: but was: ', + $failure->toString() + ); + } + + public function testComparisonErrorSame() { + $failure = new PHPUnit2_Framework_ComparisonFailure('ab', 'ab'); + + $this->assertEquals( + 'expected: but was: ', + $failure->toString() + ); + } + + public function testComparisonErrorStartAndEndSame() { + $failure = new PHPUnit2_Framework_ComparisonFailure('abc', 'adc'); + + $this->assertEquals( + 'expected: <...b...> but was: <...d...>', + $failure->toString() + ); + } + + public function testComparisonErrorStartSameComplete() { + $failure = new PHPUnit2_Framework_ComparisonFailure('ab', 'abc'); + + $this->assertEquals( + 'expected: <...> but was: <...c>', + $failure->toString() + ); + } + + public function testComparisonErrorEndSameComplete() { + $failure = new PHPUnit2_Framework_ComparisonFailure('bc', 'abc'); + + $this->assertEquals( + 'expected: <...> but was: ', + $failure->toString() + ); + } + + public function testComparisonErrorOverlapingMatches() { + $failure = new PHPUnit2_Framework_ComparisonFailure('abc', 'abbc'); + + $this->assertEquals( + 'expected: <......> but was: <...b...>', + $failure->toString() + ); + } + + public function testComparisonErrorOverlapingMatches2() { + $failure = new PHPUnit2_Framework_ComparisonFailure('abcdde', 'abcde'); + + $this->assertEquals( + 'expected: <...d...> but was: <......>', + $failure->toString() + ); + } + + public function testComparisonErrorWithActualNull() { + $failure = new PHPUnit2_Framework_ComparisonFailure('a', NULL); + + $this->assertEquals( + 'expected: but was: ', + $failure->toString() + ); + } + + public function testComparisonErrorWithExpectedNull() { + $failure = new PHPUnit2_Framework_ComparisonFailure(NULL, 'a'); + + $this->assertEquals( + 'expected: but was: ', + $failure->toString() + ); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/Framework/SuiteTest.php b/Tests/Framework/SuiteTest.php new file mode 100644 index 00000000000..55ea3ce788b --- /dev/null +++ b/Tests/Framework/SuiteTest.php @@ -0,0 +1,197 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: SuiteTest.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; +require_once 'PHPUnit2/Framework/TestResult.php'; +require_once 'PHPUnit2/Framework/TestSuite.php'; + +require_once 'InheritedTestCase.php'; +require_once 'NoTestCaseClass.php'; +require_once 'NoTestCases.php'; +require_once 'NotPublicTestCase.php'; +require_once 'NotVoidTestCase.php'; +require_once 'OneTestCase.php'; +require_once 'OverrideTestCase.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class Framework_SuiteTest extends PHPUnit2_Framework_TestCase { + protected $result; + + protected function setUp() { + $this->result = new PHPUnit2_Framework_TestResult; + } + + public static function suite() { + $suite = new PHPUnit2_Framework_TestSuite; + + $suite->addTest(new Framework_SuiteTest('testAddTestSuite')); + $suite->addTest(new Framework_SuiteTest('testInheritedTests')); + $suite->addTest(new Framework_SuiteTest('testNoTestCases')); + $suite->addTest(new Framework_SuiteTest('testNoTestCaseClass')); + $suite->addTest(new Framework_SuiteTest('testNotExistingTestCase')); + $suite->addTest(new Framework_SuiteTest('testNotPublicTestCase')); + $suite->addTest(new Framework_SuiteTest('testNotVoidTestCase')); + $suite->addTest(new Framework_SuiteTest('testOneTestCase')); + $suite->addTest(new Framework_SuiteTest('testShadowedTests')); + + return $suite; + } + + public function testAddTestSuite() { + $suite = new PHPUnit2_Framework_TestSuite( + 'OneTestCase' + ); + + $suite->run($this->result); + + $this->assertEquals(1, $this->result->runCount()); + } + + public function testInheritedTests() { + $suite = new PHPUnit2_Framework_TestSuite( + 'InheritedTestCase' + ); + + $suite->run($this->result); + + $this->assertTrue($this->result->wasSuccessful()); + $this->assertEquals(2, $this->result->runCount()); + } + + public function testNoTestCases() { + $suite = new PHPUnit2_Framework_TestSuite( + 'NoTestCases' + ); + + $suite->run($this->result); + + $this->assertTrue(!$this->result->wasSuccessful()); + $this->assertEquals(1, $this->result->failureCount()); + $this->assertEquals(1, $this->result->runCount()); + } + + public function testNoTestCaseClass() { + $suite = new PHPUnit2_Framework_TestSuite( + 'NoTestCaseClass' + ); + + $suite->run($this->result); + + $this->assertTrue(!$this->result->wasSuccessful()); + $this->assertEquals(1, $this->result->runCount()); + } + + public function testNotExistingTestCase() { + $suite = new Framework_SuiteTest('notExistingMethod'); + + $suite->run($this->result); + + $this->assertEquals(0, $this->result->errorCount()); + $this->assertEquals(1, $this->result->failureCount()); + $this->assertEquals(1, $this->result->runCount()); + } + + public function testNotPublicTestCase() { + $suite = new PHPUnit2_Framework_TestSuite( + 'NotPublicTestCase' + ); + + $this->assertEquals(2, $suite->countTestCases()); + } + + public function testNotVoidTestCase() { + $suite = new PHPUnit2_Framework_TestSuite( + 'NotVoidTestCase' + ); + + $this->assertEquals(1, $suite->countTestCases()); + } + + public function testOneTestCase() { + $suite = new PHPUnit2_Framework_TestSuite( + 'OneTestCase' + ); + + $suite->run($this->result); + + $this->assertEquals(0, $this->result->errorCount()); + $this->assertEquals(0, $this->result->failureCount()); + $this->assertEquals(1, $this->result->runCount()); + $this->assertTrue($this->result->wasSuccessful()); + } + + public function testShadowedTests() { + $suite = new PHPUnit2_Framework_TestSuite( + 'OverrideTestCase' + ); + + $suite->run($this->result); + + $this->assertEquals(1, $this->result->runCount()); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/Framework/TestCaseTest.php b/Tests/Framework/TestCaseTest.php new file mode 100644 index 00000000000..67366d3a9d5 --- /dev/null +++ b/Tests/Framework/TestCaseTest.php @@ -0,0 +1,193 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: TestCaseTest.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; + +require_once 'Error.php'; +require_once 'Failure.php'; +require_once 'NoArgTestCaseTest.php'; +require_once 'SetupFailure.php'; +require_once 'Success.php'; +require_once 'TearDownFailure.php'; +require_once 'TornDown2.php'; +require_once 'TornDown3.php'; +require_once 'TornDown4.php'; +require_once 'TornDown5.php'; +require_once 'WasRun.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class Framework_TestCaseTest extends PHPUnit2_Framework_TestCase { + public function testCaseToString() { + $this->assertEquals( + 'testCaseToString(Framework_TestCaseTest)', + $this->toString() + ); + } + + public function testError() { + $this->verifyError(new Error); + } + + public function testExceptionRunningAndTearDown() { + $result = new PHPUnit2_Framework_TestResult(); + $t = new TornDown5; + + $t->run($result); + + $errors = $result->errors(); + + $this->assertEquals( + 'tearDown', + $errors[0]->thrownException()->getMessage() + ); + } + + public function testFailure() { + $this->verifyFailure(new Failure); + } + + /* PHP does not support anonymous classes + public function testNamelessTestCase() { + } + */ + + public function testNoArgTestCasePasses() { + $result = new PHPUnit2_Framework_TestResult(); + $t = new PHPUnit2_Framework_TestSuite('NoArgTestCaseTest'); + + $t->run($result); + + $this->assertEquals(1, $result->runCount()); + $this->assertEquals(0, $result->failureCount()); + $this->assertEquals(0, $result->errorCount()); + } + + public function testRunAndTearDownFails() { + $fails = new TornDown3; + + $this->verifyError($fails); + $this->assertTrue($fails->tornDown); + } + + public function testSetupFails() { + $this->verifyError(new SetupFailure); + } + + public function testSuccess() { + $this->verifySuccess(new Success); + } + + public function testTearDownAfterError() { + $fails = new TornDown2; + + $this->verifyError($fails); + $this->assertTrue($fails->tornDown); + } + + public function testTearDownFails() { + $this->verifyError(new TearDownFailure); + } + + public function testTearDownSetupFails() { + $fails = new TornDown4; + + $this->verifyError($fails); + $this->assertFalse($fails->tornDown); + } + + public function testWasRun() { + $test = new WasRun; + $test->run(); + + $this->assertTrue($test->wasRun); + } + + protected function verifyError(PHPUnit2_Framework_TestCase $test) { + $result = $test->run(); + + $this->assertEquals(1, $result->errorCount()); + $this->assertEquals(0, $result->failureCount()); + $this->assertEquals(1, $result->runCount()); + } + + protected function verifyFailure(PHPUnit2_Framework_TestCase $test) { + $result = $test->run(); + + $this->assertEquals(0, $result->errorCount()); + $this->assertEquals(1, $result->failureCount()); + $this->assertEquals(1, $result->runCount()); + } + + protected function verifySuccess(PHPUnit2_Framework_TestCase $test) { + $result = $test->run(); + + $this->assertEquals(0, $result->errorCount()); + $this->assertEquals(0, $result->failureCount()); + $this->assertEquals(1, $result->runCount()); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/Framework/TestImplementorTest.php b/Tests/Framework/TestImplementorTest.php new file mode 100644 index 00000000000..e3e874aeb6b --- /dev/null +++ b/Tests/Framework/TestImplementorTest.php @@ -0,0 +1,94 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: TestImplementorTest.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; +require_once 'PHPUnit2/Framework/TestResult.php'; + +require_once 'DoubleTestCase.php'; +require_once 'Success.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class Framework_TestImplementorTest extends PHPUnit2_Framework_TestCase { + private $test; + + public function __construct() { + $this->test = new DoubleTestCase( + new Success + ); + } + + public function testSuccessfulRun() { + $result = new PHPUnit2_Framework_TestResult; + + $this->test->run($result); + + $this->assertEquals($this->test->countTestCases(), $result->runCount()); + $this->assertEquals(0, $result->errorCount()); + $this->assertEquals(0, $result->failureCount()); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/Framework/TestListenerTest.php b/Tests/Framework/TestListenerTest.php new file mode 100644 index 00000000000..48b92006cc5 --- /dev/null +++ b/Tests/Framework/TestListenerTest.php @@ -0,0 +1,145 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: TestListenerTest.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; +require_once 'PHPUnit2/Framework/TestListener.php'; +require_once 'PHPUnit2/Framework/TestResult.php'; + +require_once 'Error.php'; +require_once 'Failure.php'; +require_once 'Success.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class Framework_TestListenerTest extends PHPUnit2_Framework_TestCase implements PHPUnit2_Framework_TestListener { + private $endCount; + private $errorCount; + private $failureCount; + private $notImplementedCount; + private $result; + private $startCount; + + public function addError(PHPUnit2_Framework_Test $test, Exception $e) { + $this->errorCount++; + } + + public function addFailure(PHPUnit2_Framework_Test $test, PHPUnit2_Framework_AssertionFailedError $e) { + $this->failureCount++; + } + + public function addIncompleteTest(PHPUnit2_Framework_Test $test, Exception $e) { + $this->notImplementedCount++; + } + + public function startTestSuite(PHPUnit2_Framework_TestSuite $suite) { + } + + public function endTestSuite(PHPUnit2_Framework_TestSuite $suite) { + } + + public function startTest(PHPUnit2_Framework_Test $test) { + $this->startCount++; + } + + public function endTest(PHPUnit2_Framework_Test $test) { + $this->endCount++; + } + + protected function setUp() { + $this->result = new PHPUnit2_Framework_TestResult; + $this->result->addListener($this); + + $this->endCount = 0; + $this->failureCount = 0; + $this->notImplementedCount = 0; + $this->startCount = 0; + } + + public function testError() { + $test = new Error; + $test->run($this->result); + + $this->assertEquals(1, $this->errorCount); + $this->assertEquals(1, $this->endCount); + } + + public function testFailure() { + $test = new Failure; + $test->run($this->result); + + $this->assertEquals(1, $this->failureCount); + $this->assertEquals(1, $this->endCount); + } + + public function testStartStop() { + $test = new Success; + $test->run($this->result); + + $this->assertEquals(1, $this->startCount); + $this->assertEquals(1, $this->endCount); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/InheritedTestCase.php b/Tests/InheritedTestCase.php new file mode 100644 index 00000000000..b9fe61f3681 --- /dev/null +++ b/Tests/InheritedTestCase.php @@ -0,0 +1,76 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: InheritedTestCase.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; +require_once 'OneTestCase.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class InheritedTestCase extends OneTestCase { + public function test2() { + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/MockRunner.php b/Tests/MockRunner.php new file mode 100644 index 00000000000..6d9fac46cef --- /dev/null +++ b/Tests/MockRunner.php @@ -0,0 +1,86 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: MockRunner.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/AssertionFailedError.php'; +require_once 'PHPUnit2/Framework/Test.php'; +require_once 'PHPUnit2/Runner/BaseTestRunner.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class MockRunner extends PHPUnit2_Runner_BaseTestRunner { + public function testEnded($testName) { + } + + public function testFailed($status, PHPUnit2_Framework_Test $test, PHPUnit2_Framework_AssertionFailedError $e) { + } + + public function testStarted($testName) { + } + + protected function runFailed($message) { + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/NoArgTestCaseTest.php b/Tests/NoArgTestCaseTest.php new file mode 100644 index 00000000000..13677eb1792 --- /dev/null +++ b/Tests/NoArgTestCaseTest.php @@ -0,0 +1,75 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: NoArgTestCaseTest.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class NoArgTestCaseTest extends PHPUnit2_Framework_TestCase { + public function testNothing() { + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/NoTestCaseClass.php b/Tests/NoTestCaseClass.php new file mode 100644 index 00000000000..fcb7a6495a7 --- /dev/null +++ b/Tests/NoTestCaseClass.php @@ -0,0 +1,73 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: NoTestCaseClass.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class NoTestCaseClass { +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/NoTestCases.php b/Tests/NoTestCases.php new file mode 100644 index 00000000000..c213bd70d05 --- /dev/null +++ b/Tests/NoTestCases.php @@ -0,0 +1,75 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: NoTestCases.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class NoTestCases extends PHPUnit2_Framework_TestCase { + public function noTestCase() { + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/NonStatic.php b/Tests/NonStatic.php new file mode 100644 index 00000000000..c8451b8bc99 --- /dev/null +++ b/Tests/NonStatic.php @@ -0,0 +1,74 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: NonStatic.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class NonStatic { + public function suite() { + return NULL; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/NotPublicTestCase.php b/Tests/NotPublicTestCase.php new file mode 100644 index 00000000000..9caf85c4c27 --- /dev/null +++ b/Tests/NotPublicTestCase.php @@ -0,0 +1,78 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: NotPublicTestCase.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class NotPublicTestCase extends PHPUnit2_Framework_TestCase { + public function testPublic() { + } + + protected function testNotPublic() { + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/NotVoidTestCase.php b/Tests/NotVoidTestCase.php new file mode 100644 index 00000000000..ae089117521 --- /dev/null +++ b/Tests/NotVoidTestCase.php @@ -0,0 +1,73 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: NotVoidTestCase.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class NotVoidTestCase extends PHPUnit2_Framework_TestCase { +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/OneTestCase.php b/Tests/OneTestCase.php new file mode 100644 index 00000000000..e8ab290d2dc --- /dev/null +++ b/Tests/OneTestCase.php @@ -0,0 +1,78 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: OneTestCase.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class OneTestCase extends PHPUnit2_Framework_TestCase { + public function noTestCase() { + } + + public function testCase($arg = '') { + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/OverrideTestCase.php b/Tests/OverrideTestCase.php new file mode 100644 index 00000000000..80995ad4103 --- /dev/null +++ b/Tests/OverrideTestCase.php @@ -0,0 +1,76 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: OverrideTestCase.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; +require_once 'OneTestCase.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class OverrideTestCase extends OneTestCase { + public function testCase() { + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/Runner/AllTests.php b/Tests/Runner/AllTests.php new file mode 100644 index 00000000000..ef46b530d86 --- /dev/null +++ b/Tests/Runner/AllTests.php @@ -0,0 +1,104 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: AllTests.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +if (!defined('PHPUnit2_MAIN_METHOD')) { + define('PHPUnit2_MAIN_METHOD', 'Runner_AllTests::main'); +} + +require_once 'PHPUnit2/Framework/TestSuite.php'; +require_once 'PHPUnit2/TextUI/TestRunner.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +require_once 'Runner/BaseTestRunnerTest.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class Runner_AllTests { + public static function main() { + PHPUnit2_TextUI_TestRunner::run(self::suite()); + } + + public static function suite() { + $suite = new PHPUnit2_Framework_TestSuite('PHPUnit Runner'); + + $suite->addTestSuite('Runner_BaseTestRunnerTest'); + + PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Runner/BaseTestRunner.php'); + PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Runner/IncludePathTestCollector.php'); + PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Runner/StandardTestSuiteLoader.php'); + PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Runner/TestCollector.php'); + PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Runner/TestRunListener.php'); + PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Runner/TestSuiteLoader.php'); + PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Runner/Version.php'); + + return $suite; + } +} + +if (PHPUnit2_MAIN_METHOD == 'Runner_AllTests::main') { + Runner_AllTests::main(); +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/Runner/BaseTestRunnerTest.php b/Tests/Runner/BaseTestRunnerTest.php new file mode 100644 index 00000000000..9cd748d7b0b --- /dev/null +++ b/Tests/Runner/BaseTestRunnerTest.php @@ -0,0 +1,80 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: BaseTestRunnerTest.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; + +require_once 'MockRunner.php'; +require_once 'NonStatic.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class Runner_BaseTestRunnerTest extends PHPUnit2_Framework_TestCase { + public function testInvokeNonStaticSuite() { + $runner = new MockRunner; + $runner->getTest('NonStatic'); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/SetupFailure.php b/Tests/SetupFailure.php new file mode 100644 index 00000000000..e0e9cc59a9b --- /dev/null +++ b/Tests/SetupFailure.php @@ -0,0 +1,76 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: SetupFailure.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'Success.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class SetupFailure extends Success { + protected function setUp() { + throw new Exception; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/Sleep.php b/Tests/Sleep.php new file mode 100644 index 00000000000..83430488610 --- /dev/null +++ b/Tests/Sleep.php @@ -0,0 +1,76 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: Sleep.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Extensions/PerformanceTestCase.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class Sleep extends PHPUnit2_Extensions_PerformanceTestCase { + public function testSleepTwoSeconds() { + sleep(2); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/Success.php b/Tests/Success.php new file mode 100644 index 00000000000..90aaa517a7a --- /dev/null +++ b/Tests/Success.php @@ -0,0 +1,75 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: Success.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class Success extends PHPUnit2_Framework_TestCase { + public function runTest() { + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/TearDownFailure.php b/Tests/TearDownFailure.php new file mode 100644 index 00000000000..5f652f79512 --- /dev/null +++ b/Tests/TearDownFailure.php @@ -0,0 +1,76 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: TearDownFailure.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'Success.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class TearDownFailure extends Success { + protected function tearDown() { + throw new Exception; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/TestIterator.php b/Tests/TestIterator.php new file mode 100644 index 00000000000..a619fdb88e6 --- /dev/null +++ b/Tests/TestIterator.php @@ -0,0 +1,97 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: TestIterator.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class TestIterator implements Iterator { + private $array; + private $position; + + public function __construct($array = array()) { + $this->array = $array; + } + + public function rewind() { + $this->position = 0; + } + + public function valid() { + return $this->position < sizeof($this->array); + } + + public function key() { + return $this->position; + } + + public function current() { + return $this->array[$this->position]; + } + + public function next() { + $this->position++; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/ThrowExceptionTestCase.php b/Tests/ThrowExceptionTestCase.php new file mode 100644 index 00000000000..c991f3554ec --- /dev/null +++ b/Tests/ThrowExceptionTestCase.php @@ -0,0 +1,76 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: ThrowExceptionTestCase.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Extensions/ExceptionTestCase.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class ThrowExceptionTestCase extends PHPUnit2_Extensions_ExceptionTestCase { + public function test() { + throw new Exception; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/ThrowNoExceptionTestCase.php b/Tests/ThrowNoExceptionTestCase.php new file mode 100644 index 00000000000..82db5af68a7 --- /dev/null +++ b/Tests/ThrowNoExceptionTestCase.php @@ -0,0 +1,75 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: ThrowNoExceptionTestCase.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Extensions/ExceptionTestCase.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class ThrowNoExceptionTestCase extends PHPUnit2_Extensions_ExceptionTestCase { + public function test() { + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/TornDown.php b/Tests/TornDown.php new file mode 100644 index 00000000000..3018a5b3c6e --- /dev/null +++ b/Tests/TornDown.php @@ -0,0 +1,78 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: TornDown.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Extensions/TestSetup.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class TornDown extends PHPUnit2_Extensions_TestSetup { + private $tornDown = FALSE; + + protected function tearDown() { + $this->tornDown = TRUE; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/TornDown2.php b/Tests/TornDown2.php new file mode 100644 index 00000000000..d47e90c02b0 --- /dev/null +++ b/Tests/TornDown2.php @@ -0,0 +1,82 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: TornDown2.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class TornDown2 extends PHPUnit2_Framework_TestCase { + public $tornDown = FALSE; + + protected function tearDown() { + $this->tornDown = TRUE; + } + + protected function runTest() { + throw new Exception; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/TornDown3.php b/Tests/TornDown3.php new file mode 100644 index 00000000000..7dbfd77b252 --- /dev/null +++ b/Tests/TornDown3.php @@ -0,0 +1,81 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: TornDown3.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'TornDown2.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class TornDown3 extends TornDown2 { + protected function tearDown() { + parent::tearDown(); + throw new Exception; + } + + protected function runTest() { + throw new Exception; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/TornDown4.php b/Tests/TornDown4.php new file mode 100644 index 00000000000..5921c125eb3 --- /dev/null +++ b/Tests/TornDown4.php @@ -0,0 +1,76 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: TornDown4.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'TornDown2.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class TornDown4 extends TornDown2 { + protected function setUp() { + throw new Exception; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/TornDown5.php b/Tests/TornDown5.php new file mode 100644 index 00000000000..ffa40570b47 --- /dev/null +++ b/Tests/TornDown5.php @@ -0,0 +1,76 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: TornDown5.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'TornDown2.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class TornDown5 extends TornDown2 { + protected function tearDown() { + throw new Exception('tearDown'); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/TornDown6.php b/Tests/TornDown6.php new file mode 100644 index 00000000000..4e9054d9777 --- /dev/null +++ b/Tests/TornDown6.php @@ -0,0 +1,76 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: TornDown6.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'TornDown.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class TornDown6 extends TornDown { + protected function setUp() { + $this->fail(); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/Util/TestDox/AllTests.php b/Tests/Util/TestDox/AllTests.php new file mode 100644 index 00000000000..7e386cc89a7 --- /dev/null +++ b/Tests/Util/TestDox/AllTests.php @@ -0,0 +1,100 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: AllTests.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +if (!defined('PHPUnit2_MAIN_METHOD')) { + define('PHPUnit2_MAIN_METHOD', 'Util_TestDox_AllTests::main'); +} + +require_once 'PHPUnit2/Framework/TestSuite.php'; +require_once 'PHPUnit2/TextUI/TestRunner.php'; + +require_once 'Util/TestDox/NamePrettifierTest.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.1.0 + */ +class Util_TestDox_AllTests { + public static function main() { + PHPUnit2_TextUI_TestRunner::run(self::suite()); + } + + public static function suite() { + $suite = new PHPUnit2_Framework_TestSuite('PHPUnit2 TestDox Functionality'); + + $suite->addTestSuite('Util_TestDox_NamePrettifierTest'); + + PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Util/TestDox/ResultPrinter/HTML.php'); + PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Util/TestDox/ResultPrinter/Text.php'); + PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Util/TestDox/NamePrettifier.php'); + PHPUnit2_Util_Filter::removeFileFromFilter('PHPUnit2/Util/TestDox/ResultPrinter.php'); + + return $suite; + } +} + +if (PHPUnit2_MAIN_METHOD == 'Util_TestDox_AllTests::main') { + Util_TestDox_AllTests::main(); +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/Util/TestDox/NamePrettifierTest.php b/Tests/Util/TestDox/NamePrettifierTest.php new file mode 100644 index 00000000000..b18aa16db27 --- /dev/null +++ b/Tests/Util/TestDox/NamePrettifierTest.php @@ -0,0 +1,117 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: NamePrettifierTest.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; + +require_once 'PHPUnit2/Util/TestDox/NamePrettifier.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.1.0 + */ +class Util_TestDox_NamePrettifierTest extends PHPUnit2_Framework_TestCase { + private $namePrettifier; + + protected function setUp() { + $this->namePrettifier = new PHPUnit2_Util_TestDox_NamePrettifier; + } + + public function testTitleHasSensibleDefaults() { + $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('FooTest')); + $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('TestFoo')); + $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('TestFooTest')); + } + + public function testCaterForUserDefinedSuffix() { + $this->namePrettifier->setSuffix('TestCase'); + $this->namePrettifier->setPrefix(NULL); + + $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('FooTestCase')); + $this->assertEquals('TestFoo', $this->namePrettifier->prettifyTestClass('TestFoo')); + $this->assertEquals('FooTest', $this->namePrettifier->prettifyTestClass('FooTest')); + } + + public function testCaterForUserDefinedPrefix() { + $this->namePrettifier->setSuffix(NULL); + $this->namePrettifier->setPrefix('XXX'); + + $this->assertEquals('Foo', $this->namePrettifier->prettifyTestClass('XXXFoo')); + $this->assertEquals('TestXXX', $this->namePrettifier->prettifyTestClass('TestXXX')); + $this->assertEquals('XXX', $this->namePrettifier->prettifyTestClass('XXXXXX')); + } + + public function testTestNameIsConvertedToASentence() { + $this->assertEquals('This is a test', $this->namePrettifier->prettifyTestMethod('testThisIsATest')); + $this->assertEquals('This is a test', $this->namePrettifier->prettifyTestMethod('testThisIsATest2')); + $this->assertEquals('This2 is a test', $this->namePrettifier->prettifyTestMethod('testThis2IsATest')); + $this->assertEquals('database_column_spec is set correctly', $this->namePrettifier->prettifyTestMethod('testdatabase_column_specIsSetCorrectly')); + } + + public function testIsATestIsFalseForNonTestMethods() { + $this->assertFalse($this->namePrettifier->isATestMethod('setUp')); + $this->assertFalse($this->namePrettifier->isATestMethod('tearDown')); + $this->assertFalse($this->namePrettifier->isATestMethod('foo')); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/WasRun.php b/Tests/WasRun.php new file mode 100644 index 00000000000..c8d4731bb12 --- /dev/null +++ b/Tests/WasRun.php @@ -0,0 +1,78 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: WasRun.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class WasRun extends PHPUnit2_Framework_TestCase { + public $wasRun = FALSE; + + protected function runTest() { + $this->wasRun = TRUE; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/TextUI/ResultPrinter.php b/TextUI/ResultPrinter.php new file mode 100644 index 00000000000..7ed13979520 --- /dev/null +++ b/TextUI/ResultPrinter.php @@ -0,0 +1,356 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: ResultPrinter.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/TestListener.php'; +require_once 'PHPUnit2/Framework/TestFailure.php'; +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Util/Printer.php'; + +/** + * Prints the result of a TextUI TestRunner run. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class PHPUnit2_TextUI_ResultPrinter extends PHPUnit2_Util_Printer implements PHPUnit2_Framework_TestListener { + /** + * @var integer + * @access private + */ + private $column = 0; + + /** + * @var boolean + * @access private + */ + private $lastTestFailed = FALSE; + + /** + * @param PHPUnit2_Framework_TestResult $result + * @param float $runTime + * @access public + */ + public function printResult(PHPUnit2_Framework_TestResult $result, $timeElapsed) { + $this->printHeader($timeElapsed); + $this->printErrors($result); + $this->printFailures($result); + $this->printIncompletes($result); + $this->printFooter($result); + } + + /** + * @param array $defects + * @param integer $count + * @param string $type + * @access protected + */ + protected function printDefects($defects, $count, $type) { + if ($count == 0) { + return; + } + + $this->write( + sprintf( + "There %s %d %s%s:\n", + + ($count == 1) ? 'was' : 'were', + $count, + $type, + ($count == 1) ? '' : 's' + ) + ); + + $i = 1; + + foreach ($defects as $defect) { + $this->printDefect($defect, $i++); + } + } + + /** + * @param PHPUnit2_Framework_TestFailure $defect + * @param integer $count + * @access protected + */ + protected function printDefect(PHPUnit2_Framework_TestFailure $defect, $count) { + $this->printDefectHeader($defect, $count); + $this->printDefectTrace($defect); + } + + /** + * @param PHPUnit2_Framework_TestFailure $defect + * @param integer $count + * @access protected + */ + protected function printDefectHeader(PHPUnit2_Framework_TestFailure $defect, $count) { + $this->write( + sprintf( + "%d) %s\n", + + $count, + $defect->failedTest()->toString() + ) + ); + } + + /** + * @param PHPUnit2_Framework_TestFailure $defect + * @access protected + */ + protected function printDefectTrace(PHPUnit2_Framework_TestFailure $defect) { + $e = $defect->thrownException(); + $message = method_exists($e, 'toString') ? $e->toString() : $e->getMessage(); + + $this->write($message . "\n"); + + $this->write( + PHPUnit2_Util_Filter::getFilteredStacktrace( + $defect->thrownException() + ) + ); + } + + /** + * @param PHPUnit2_Framework_TestResult $result + * @access protected + */ + protected function printErrors(PHPUnit2_Framework_TestResult $result) { + $this->printDefects($result->errors(), $result->errorCount(), 'error'); + } + + /** + * @param PHPUnit2_Framework_TestResult $result + * @access protected + */ + protected function printFailures(PHPUnit2_Framework_TestResult $result) { + $this->printDefects($result->failures(), $result->failureCount(), 'failure'); + } + + /** + * @param PHPUnit2_Framework_TestResult $result + * @access protected + */ + protected function printIncompletes(PHPUnit2_Framework_TestResult $result) { + $this->printDefects($result->notImplemented(), $result->notImplementedCount(), 'incomplete test case'); + } + + /** + * @param float $timeElapsed + * @access protected + */ + protected function printHeader($timeElapsed) { + $this->write( + sprintf( + "\n\nTime: %s\n", + + $timeElapsed + ) + ); + } + + /** + * @param PHPUnit2_Framework_TestResult $result + * @access protected + */ + protected function printFooter(PHPUnit2_Framework_TestResult $result) { + if ($result->allCompletlyImplemented() && + $result->wasSuccessful()) { + $this->write( + sprintf( + "\nOK (%d test%s)\n", + + $result->runCount(), + ($result->runCount() == 1) ? '' : 's' + ) + ); + } + + else if (!$result->allCompletlyImplemented() && + $result->wasSuccessful()) { + $this->write( + sprintf( + "\nOK, but incomplete test cases!!!\nTests run: %d, Incomplete Tests: %d.\n", + + $result->runCount(), + $result->notImplementedCount() + ) + ); + } + + else { + $this->write( + sprintf( + "\nFAILURES!!!\nTests run: %d, Failures: %d, Errors: %d, Incomplete Tests: %d.\n", + + $result->runCount(), + $result->failureCount(), + $result->errorCount(), + $result->notImplementedCount() + ) + ); + } + } + + /** + * @access public + */ + public function printWaitPrompt() { + $this->write("\n to continue\n"); + } + + /** + * An error occurred. + * + * @param PHPUnit2_Framework_Test $test + * @param Exception $e + * @access public + */ + public function addError(PHPUnit2_Framework_Test $test, Exception $e) { + $this->write('E'); + $this->nextColumn(); + + $this->lastTestFailed = TRUE; + } + + /** + * A failure occurred. + * + * @param PHPUnit2_Framework_Test $test + * @param PHPUnit2_Framework_AssertionFailedError $e + * @access public + */ + public function addFailure(PHPUnit2_Framework_Test $test, PHPUnit2_Framework_AssertionFailedError $e) { + $this->write('F'); + $this->nextColumn(); + + $this->lastTestFailed = TRUE; + } + + /** + * Incomplete test. + * + * @param PHPUnit2_Framework_Test $test + * @param Exception $e + * @access public + */ + public function addIncompleteTest(PHPUnit2_Framework_Test $test, Exception $e) { + $this->write('I'); + $this->nextColumn(); + + $this->lastTestFailed = TRUE; + } + + /** + * A testsuite started. + * + * @param PHPUnit2_Framework_TestSuite $suite + * @access public + * @since Method available since Release 2.2.0 + */ + public function startTestSuite(PHPUnit2_Framework_TestSuite $suite) { + } + + /** + * A testsuite ended. + * + * @param PHPUnit2_Framework_TestSuite $suite + * @access public + * @since Method available since Release 2.2.0 + */ + public function endTestSuite(PHPUnit2_Framework_TestSuite $suite) { + } + + /** + * A test started. + * + * @param PHPUnit2_Framework_Test $test + * @access public + */ + public function startTest(PHPUnit2_Framework_Test $test) { + } + + /** + * A test ended. + * + * @param PHPUnit2_Framework_Test $test + * @access public + */ + public function endTest(PHPUnit2_Framework_Test $test) { + if (!$this->lastTestFailed) { + $this->write('.'); + $this->nextColumn(); + } + + $this->lastTestFailed = FALSE; + } + + /** + * @access protected + */ + protected function nextColumn() { + if ($this->column++ >= 40) { + $this->column = 0; + $this->write("\n"); + } + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/TextUI/TestRunner.php b/TextUI/TestRunner.php new file mode 100644 index 00000000000..cc5d35820f8 --- /dev/null +++ b/TextUI/TestRunner.php @@ -0,0 +1,622 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: TestRunner.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +if (!defined('PHPUnit2_MAIN_METHOD')) { + define('PHPUnit2_MAIN_METHOD', 'PHPUnit2_TextUI_TestRunner::main'); +} + +require_once 'PHPUnit2/Framework/TestSuite.php'; +require_once 'PHPUnit2/Runner/Version.php'; +require_once 'PHPUnit2/Runner/BaseTestRunner.php'; +require_once 'PHPUnit2/TextUI/ResultPrinter.php'; +require_once 'PHPUnit2/Util/Fileloader.php'; + +require_once 'Console/Getopt.php'; +require_once 'Benchmark/Timer.php'; + +/** + * A TestRunner for the Command Line Interface (CLI) + * PHP SAPI Module. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class PHPUnit2_TextUI_TestRunner extends PHPUnit2_Runner_BaseTestRunner { + const SUCCESS_EXIT = 0; + const FAILURE_EXIT = 1; + const EXCEPTION_EXIT = 2; + + /** + * @var PHPUnit2_Runner_TestSuiteLoader + * @access private + */ + private $loader = NULL; + + /** + * @var PHPUnit2_TextUI_ResultPrinter + * @access private + */ + private $printer = NULL; + + /** + * @var boolean + * @access private + * @static + */ + private static $versionStringPrinted = FALSE; + + /** + * @access public + * @static + */ + public static function main() { + $aTestRunner = new PHPUnit2_TextUI_TestRunner; + + try { + $result = $aTestRunner->start($_SERVER['argv']); + + if (!$result->wasSuccessful()) { + exit(self::FAILURE_EXIT); + } + + exit(self::SUCCESS_EXIT); + } + + catch (Exception $e) { + self::printVersionString(); + print $e->getMessage(); + exit(self::EXCEPTION_EXIT); + } + } + + /** + * @param array $arguments + * @throws Exception + * @access protected + */ + protected function start($arguments) { + $coverageDataFile = FALSE; + $coverageHTMLFile = FALSE; + $coverageTextFile = FALSE; + $testdoxHTMLFile = FALSE; + $testdoxTextFile = FALSE; + $xmlLogfile = FALSE; + $wait = FALSE; + + $possibleOptions = array( + 'help', + 'loader=', + 'log-xml=', + 'skeleton', + 'testdox-html=', + 'testdox-text=', + 'version', + 'wait' + ); + + if (extension_loaded('xdebug')) { + $possibleOptions[] = 'coverage-data='; + $possibleOptions[] = 'coverage-html='; + $possibleOptions[] = 'coverage-text='; + } + + $options = Console_Getopt::getopt( + $arguments, + '', + $possibleOptions + ); + + if (PEAR::isError($options)) { + $this->showError($options->getMessage()); + } + + $test = isset($options[1][0]) ? $options[1][0] : FALSE; + $testFile = isset($options[1][1]) ? $options[1][1] : $test . '.php'; + + foreach ($options[0] as $option) { + switch ($option[0]) { + case '--coverage-data': { + $coverageDataFile = $option[1]; + } + break; + + case '--coverage-html': { + $coverageHTMLFile = $option[1]; + } + break; + + case '--coverage-text': { + $coverageTextFile = $option[1]; + } + break; + + case '--help': { + $this->showHelp(); + exit(self::SUCCESS_EXIT); + } + break; + + case '--testdox-html': { + $testdoxHTMLFile = $option[1]; + } + break; + + case '--testdox-text': { + $testdoxTextFile = $option[1]; + } + break; + + case '--loader': { + if (!class_exists($option[1])) { + PHPUnit2_Util_Fileloader::checkAndLoad( + str_replace('_', '/', $option[1]) . '.php' + ); + } + + if (class_exists($option[1])) { + $class = new ReflectionClass($option[1]); + + if ($class->implementsInterface('PHPUnit2_Runner_TestSuiteLoader') && + $class->isInstantiable()) { + $this->loader = $class->newInstance(); + } + } + + if ($this->loader === NULL) { + $this->showError( + sprintf( + 'Could not use "%s" as loader.', + + $option[1] + ) + ); + } + } + break; + + case '--log-xml': { + $xmlLogfile = $option[1]; + } + break; + + case '--skeleton': { + if ($test !== FALSE) { + self::printVersionString(); + + try { + require_once 'PHPUnit2/Util/Skeleton.php'; + + $skeleton = new PHPUnit2_Util_Skeleton($test, $testFile); + $skeleton->write(); + } + + catch (Exception $e) { + print $e->getMessage() . "\n"; + + printf( + "Could not write test class skeleton for %s to %s.\n", + $test, + $test . 'Test.php' + ); + + exit(self::FAILURE_EXIT); + } + + printf( + "Wrote test class skeleton for %s to %s.\n", + $test, + $test . 'Test.php' + ); + + exit(self::SUCCESS_EXIT); + } + } + break; + + case '--version': { + self::printVersionString(); + exit(self::SUCCESS_EXIT); + } + break; + + case '--wait': { + $wait = TRUE; + } + break; + } + } + + if ($test === FALSE) { + $this->showHelp(); + + exit(self::SUCCESS_EXIT); + } + + try { + return $this->doRun( + $this->getTest($test, $testFile), + $coverageDataFile, + $coverageHTMLFile, + $coverageTextFile, + $testdoxHTMLFile, + $testdoxTextFile, + $xmlLogfile, + $wait + ); + } + + catch (Exception $e) { + throw new Exception( + 'Could not create and run test suite: ' . $e->getMessage() + ); + } + } + + /** + * @param mixed $test + * @param mixed $coverageDataFile + * @param mixed $testdoxHTMLFile + * @param mixed $testdoxTextFile + * @param mixed $xmlLogfile + * @param boolean $wait + * @access public + * @static + */ + public static function run($test, $coverageDataFile = FALSE, $coverageHTMLFile = FALSE, $coverageTextFile = FALSE, $testdoxHTMLFile = FALSE, $testdoxTextFile = FALSE, $xmlLogfile = FALSE, $wait = FALSE) { + if ($test instanceof ReflectionClass) { + $test = new PHPUnit2_Framework_TestSuite($test); + } + + if ($test instanceof PHPUnit2_Framework_Test) { + $aTestRunner = new PHPUnit2_TextUI_TestRunner; + + return $aTestRunner->doRun( + $test, + $coverageDataFile, + $coverageHTMLFile, + $coverageTextFile, + $testdoxHTMLFile, + $testdoxTextFile, + $xmlLogfile, + $wait + ); + } + } + + /** + * Runs a single test and waits until the user types RETURN. + * + * @param PHPUnit2_Framework_Test $suite + * @access public + * @static + */ + public static function runAndWait(PHPUnit2_Framework_Test $suite) { + $aTestRunner = new PHPUnit2_TextUI_TestRunner; + + $aTestRunner->doRun( + $suite, + FALSE, + FALSE, + FALSE, + FALSE, + FALSE, + FALSE, + TRUE + ); + } + + /** + * @return PHPUnit2_Framework_TestResult + * @access protected + */ + protected function createTestResult() { + return new PHPUnit2_Framework_TestResult; + } + + /** + * @param PHPUnit2_Framework_Test $suite + * @param mixed $coverageDataFile + * @param mixed $coverageHTMLFile + * @param mixed $coverageTextFile + * @param mixed $testdoxHTMLFile + * @param mixed $testdoxTextFile + * @param mixed $xmlLogfile + * @param boolean $wait + * @return PHPUnit2_Framework_TestResult + * @access public + */ + public function doRun(PHPUnit2_Framework_Test $suite, $coverageDataFile = FALSE, $coverageHTMLFile = FALSE, $coverageTextFile = FALSE, $testdoxHTMLFile = FALSE, $testdoxTextFile = FALSE, $xmlLogfile = FALSE, $wait = FALSE) { + $result = $this->createTestResult(); + $timer = new Benchmark_Timer; + + if ($this->printer === NULL) { + $this->printer = new PHPUnit2_TextUI_ResultPrinter; + } + + $this->printer->write( + PHPUnit2_Runner_Version::getVersionString() . "\n\n" + ); + + $result->addListener($this->printer); + + if ($testdoxHTMLFile !== FALSE || $testdoxTextFile !== FALSE) { + require_once 'PHPUnit2/Util/TestDox/ResultPrinter.php'; + + if ($testdoxHTMLFile !== FALSE) { + $result->addListener( + PHPUnit2_Util_TestDox_ResultPrinter::factory( + 'HTML', + $testdoxHTMLFile + ) + ); + } + + if ($testdoxTextFile !== FALSE) { + $result->addListener( + PHPUnit2_Util_TestDox_ResultPrinter::factory( + 'Text', + $testdoxTextFile + ) + ); + } + } + + if ($xmlLogfile !== FALSE) { + require_once 'PHPUnit2/Util/Log/XML.php'; + + $result->addListener( + new PHPUnit2_Util_Log_XML($xmlLogfile) + ); + } + + if ($coverageDataFile !== FALSE || + $coverageHTMLFile !== FALSE || + $coverageTextFile !== FALSE) { + $result->collectCodeCoverageInformation(TRUE); + } + + $timer->start(); + $suite->run($result); + $timer->stop(); + $timeElapsed = $timer->timeElapsed(); + + $this->pause($wait); + + $this->printer->printResult($result, $timeElapsed); + + $this->handleCodeCoverageInformation( + $result, + $coverageDataFile, + $coverageHTMLFile, + $coverageTextFile + ); + + return $result; + } + + /** + * Returns the loader to be used. + * + * @return PHPUnit2_Runner_TestSuiteLoader + * @access public + * @since Method available since Release 2.2.0 + */ + public function getLoader() { + if ($this->loader === NULL) { + $this->loader = new PHPUnit2_Runner_StandardTestSuiteLoader; + } + + return $this->loader; + } + + /** + * @param PHPUnit2_Framework_TestResult $result + * @param mixed $coverageDataFile + * @param mixed $coverageHTMLFile + * @param mixed $coverageTextFile + * @access protected + * @since Method available since Release 2.1.0 + */ + protected function handleCodeCoverageInformation(PHPUnit2_Framework_TestResult $result, $coverageDataFile, $coverageHTMLFile, $coverageTextFile) { + if ($coverageDataFile !== FALSE && + $fp = fopen($coverageDataFile, 'w')) { + fputs($fp, serialize($result->getCodeCoverageInformation())); + fclose($fp); + } + + if ($coverageHTMLFile !== FALSE || $coverageTextFile !== FALSE) { + require_once 'PHPUnit2/Util/CodeCoverage/Renderer.php'; + + if ($coverageHTMLFile !== FALSE) { + $renderer = PHPUnit2_Util_CodeCoverage_Renderer::factory( + 'HTML', + $result->getCodeCoverageInformation() + ); + + $renderer->renderToFile($coverageHTMLFile); + } + + if ($coverageTextFile !== FALSE) { + $renderer = PHPUnit2_Util_CodeCoverage_Renderer::factory( + 'Text', + $result->getCodeCoverageInformation() + ); + + $renderer->renderToFile($coverageTextFile); + } + } + } + + /** + * @access public + */ + public function showError($message) { + self::printVersionString(); + print $message . "\n"; + + exit(self::FAILURE_EXIT); + } + + /** + * @access public + */ + public function showHelp() { + self::printVersionString(); + print "Usage: phpunit [switches] UnitTest [UnitTest.php]\n"; + + if (extension_loaded('xdebug')) { + print " --coverage-data Write Code Coverage data in raw format to file.\n" . + " --coverage-html Write Code Coverage data in HTML format to file.\n" . + " --coverage-text Write Code Coverage data in text format to file.\n\n"; + } + + print " --testdox-html Write agile documentation in HTML format to file.\n" . + " --testdox-text Write agile documentation in Text format to file.\n" . + " --log-xml Log test progress in XML format to file.\n\n"; + + print " --loader TestSuiteLoader implementation to use.\n\n" . + " --skeleton Generate skeleton UnitTest class for Unit in Unit.php.\n\n" . + " --wait Waits for a keystroke after each test.\n\n" . + " --help Prints this usage information.\n" . + " --version Prints the version and exits.\n"; + } + + /** + * @param boolean $wait + * @access protected + */ + protected function pause($wait) { + if (!$wait) { + return; + } + + $this->printer->printWaitPrompt(); + + fgets(STDIN); + } + + /** + * @param PHPUnit2_TextUI_ResultPrinter $resultPrinter + * @access public + */ + public function setPrinter(PHPUnit2_TextUI_ResultPrinter $resultPrinter) { + $this->printer = $resultPrinter; + } + + /** + * A test started. + * + * @param string $testName + * @access public + */ + public function testStarted($testName) { + } + + /** + * A test ended. + * + * @param string $testName + * @access public + */ + public function testEnded($testName) { + } + + /** + * A test failed. + * + * @param integer $status + * @param PHPUnit2_Framework_Test $test + * @param PHPUnit2_Framework_AssertionFailedError $e + * @access public + */ + public function testFailed($status, PHPUnit2_Framework_Test $test, PHPUnit2_Framework_AssertionFailedError $e) { + } + + /** + * Override to define how to handle a failed loading of + * a test suite. + * + * @param string $message + * @access protected + */ + protected function runFailed($message) { + self::printVersionString(); + print $message; + exit(self::FAILURE_EXIT); + } + + /** + * @access private + * @since Method available since Release 2.2.0 + */ + private static function printVersionString() { + if (!self::$versionStringPrinted) { + print PHPUnit2_Runner_Version::getVersionString() . "\n\n"; + self::$versionStringPrinted = TRUE; + } + } +} + +if (PHPUnit2_MAIN_METHOD == 'PHPUnit2_TextUI_TestRunner::main') { + PHPUnit2_TextUI_TestRunner::main(); +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Util/CodeCoverage/Renderer.php b/Util/CodeCoverage/Renderer.php new file mode 100644 index 00000000000..ec27ca0738e --- /dev/null +++ b/Util/CodeCoverage/Renderer.php @@ -0,0 +1,225 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: Renderer.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +/** + * Abstract base class for Code Coverage renderers. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.1.0 + * @abstract + */ +abstract class PHPUnit2_Util_CodeCoverage_Renderer { + /** + * @var array + * @access protected + */ + protected $codeCoverageInformation; + + /** + * Constructor. + * + * @param array $codeCoverageInformation + * @access protected + */ + protected function __construct($codeCoverageInformation) { + $this->codeCoverageInformation = $codeCoverageInformation; + } + + /** + * Abstract Factory. + * + * @param string $rendererName + * @param array $codeCoverageInformation + * @throws Exception + * @access public + */ + public function factory($rendererName, $codeCoverageInformation) { + require_once 'PHPUnit2/Util/CodeCoverage/Renderer/' . $rendererName . '.php'; + + $class = 'PHPUnit2_Util_CodeCoverage_Renderer_' . $rendererName; + return new $class($codeCoverageInformation); + } + + /** + * Visualizes the result array of + * PHPUnit2_Framework_TestResult::getCodeCoverageInformation(). + * + * @return string + * @access public + * @final + */ + public final function render() { + $buffer = $this->header(); + + foreach ($this->getSummary() as $sourceFile => $executedLines) { + if (file_exists($sourceFile)) { + $buffer .= $this->startSourceFile($sourceFile); + $buffer .= $this->renderSourceFile(file($sourceFile), $executedLines); + $buffer .= $this->endSourceFile($sourceFile); + } + } + + return $buffer . $this->footer(); + } + + /** + * Visualizes the result array of + * PHPUnit2_Framework_TestResult::getCodeCoverageInformation() + * and writes it to a file. + * + * @param string $filename + * @access public + * @since Method available since Release 2.2.0 + */ + public function renderToFile($filename) { + if ($fp = fopen($filename, 'w')) { + fputs( + $fp, + $this->render() + ); + + fclose($fp); + } + } + + /** + * Returns summarized Code Coverage data. + * + * Format of the result array: + * + * + * array( + * "/tested/code.php" => array( + * linenumber => flag + * ) + * ) + * + * + * flag > 1: line was executed. + * flag < 1: line is executable but was not executed. + * + * @return array + * @access protected + * @since Method available since Release 2.2.0 + */ + protected function getSummary() { + $summary = array(); + + foreach ($this->codeCoverageInformation as $testCaseName => $sourceFiles) { + foreach ($sourceFiles as $sourceFile => $executedLines) { + foreach ($executedLines as $lineNumber => $flag) { + if (!isset($summary[$sourceFile][$lineNumber])) { + $summary[$sourceFile][$lineNumber] = $flag; + } + + else if ($flag > 0) { + $summary[$sourceFile][$lineNumber] = $flag; + } + } + } + } + + return $summary; + } + + /** + * @return string + * @access protected + * @since Method available since Release 2.1.1 + */ + protected function header() { + } + + /** + * @return string + * @access protected + * @since Method available since Release 2.1.1 + */ + protected function footer() { + } + + /** + * @param string $sourceFile + * @return string + * @access protected + */ + protected function startSourceFile($sourceFile) { + } + + /** + * @param string $sourceFile + * @return string + * @access protected + */ + protected function endSourceFile($sourceFile) { + } + + /** + * @param array $codeLines + * @param array $executedLines + * @return string + * @access protected + * @abstract + */ + abstract protected function renderSourceFile($codeLines, $executedLines); +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Util/CodeCoverage/Renderer/HTML.php b/Util/CodeCoverage/Renderer/HTML.php new file mode 100644 index 00000000000..6db4d8868e1 --- /dev/null +++ b/Util/CodeCoverage/Renderer/HTML.php @@ -0,0 +1,191 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: HTML.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit2/Util/CodeCoverage/Renderer.php'; + +/** + * Renders Code Coverage information in HTML format. + * + * Formatting of the generated HTML can be achieved through + * CSS (codecoverage.css). + * + * Example + * + * + * td.ccLineNumber, td.ccCoveredLine, td.ccUncoveredLine, td.ccNotExecutableLine { + * font-family: monospace; + * white-space: pre; + * } + * + * td.ccLineNumber, td.ccCoveredLine { + * background-color: #aaaaaa; + * } + * + * td.ccNotExecutableLine { + * color: #aaaaaa; + * } + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.1.0 + */ +class PHPUnit2_Util_CodeCoverage_Renderer_HTML extends PHPUnit2_Util_CodeCoverage_Renderer { + const pageHeader = +' + + + + + + +'; + + const pageFooter = +' + +'; + + const sourceFileHeader = +' +'; + + const sourceFileFooter = +'
+'; + + const codeLine = +' %s%s +'; + + /** + * @return string + * @access protected + * @since Method available since Release 2.1.1 + */ + protected function header() { + return self::pageHeader; + } + + /** + * @return string + * @access protected + * @since Method available since Release 2.1.1 + */ + protected function footer() { + return self::pageFooter; + } + + /** + * @param string $sourceFile + * @return string + * @access protected + */ + protected function startSourceFile($sourceFile) { + return self::sourceFileHeader; + } + + /** + * @param string $sourceFile + * @return string + * @access protected + */ + protected function endSourceFile($sourceFile) { + return self::sourceFileFooter; + } + + /** + * @param array $codeLines + * @param array $executedLines + * @return string + * @access protected + */ + protected function renderSourceFile($codeLines, $executedLines) { + $buffer = ''; + $line = 1; + + foreach ($codeLines as $codeLine) { + $lineStyle = 'ccNotExecutableLine'; + + if (isset($executedLines[$line])) { + if ($executedLines[$line] > 0) { + $lineStyle = 'ccCoveredLine'; + } else { + $lineStyle = 'ccUncoveredLine'; + } + } + + $buffer .= sprintf( + self::codeLine, + + $line, + $lineStyle, + htmlspecialchars(rtrim($codeLine)) + ); + + $line++; + } + + return $buffer; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Util/CodeCoverage/Renderer/Text.php b/Util/CodeCoverage/Renderer/Text.php new file mode 100644 index 00000000000..e3053b71c15 --- /dev/null +++ b/Util/CodeCoverage/Renderer/Text.php @@ -0,0 +1,125 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: Text.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit2/Util/CodeCoverage/Renderer.php'; + +/** + * Renders Code Coverage information in text format. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.1.0 + */ +class PHPUnit2_Util_CodeCoverage_Renderer_Text extends PHPUnit2_Util_CodeCoverage_Renderer { + /** + * @param string $sourceFile + * @return string + * @access protected + */ + protected function startSourceFile($sourceFile) { + return ' ' . $sourceFile . "\n\n"; + } + + /** + * @param string $sourceFile + * @return string + * @access protected + */ + protected function endSourceFile($sourceFile) { + return "\n"; + } + + /** + * @param array $codeLines + * @param array $executedLines + * @return string + * @access protected + */ + protected function renderSourceFile($codeLines, $executedLines) { + $buffer = ''; + $line = 1; + + foreach ($codeLines as $codeLine) { + $flag = '-'; + + if (isset($executedLines[$line])) { + if ($executedLines[$line] > 0) { + $flag = '+'; + } else { + $flag = '#'; + } + } + + $buffer .= sprintf( + ' %4u|%s| %s', + + $line, + $flag, + $codeLine + ); + + $line++; + } + + return $buffer; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Util/ErrorHandler.php b/Util/ErrorHandler.php new file mode 100644 index 00000000000..38b25ee0678 --- /dev/null +++ b/Util/ErrorHandler.php @@ -0,0 +1,77 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: ErrorHandler.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +/** + * @param integer $errno + * @param string $errstr + * @param string $errfile + * @param integer $errline + * @throws PHPUnit2_Framework_Error + * @since Function available since Release 2.3.0 + */ +function PHPUnit2_Util_ErrorHandler($errno, $errstr, $errfile, $errline) { + $trace = debug_backtrace(); + array_shift($trace); + + throw new PHPUnit2_Framework_Error( + $errstr, + $errno, + $errfile, + $errline, + $trace + ); +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Util/Fileloader.php b/Util/Fileloader.php new file mode 100644 index 00000000000..008c7014716 --- /dev/null +++ b/Util/Fileloader.php @@ -0,0 +1,109 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: Fileloader.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.3.0 + */ +class PHPUnit2_Util_Fileloader { + /** + * Checks if a PHP sourcefile is readable and contains no syntax errors. + * If that is the case, the sourcefile is loaded through include_once(). + * + * @param string $filename + * @throws Exception + * @access public + * @static + */ + public static function checkAndLoad($filename) { + if (!is_readable($filename)) { + $filename = './' . $filename; + } + + if (!is_readable($filename)) { + throw new Exception( + sprintf( + '%s could not be found or is not readable.', + + str_replace('./', '', $filename) + ) + ); + } + + $output = shell_exec('php -l ' . escapeshellarg($filename)); + + if (strpos($output, 'No syntax errors detected in') === FALSE) { + throw new Exception( + sprintf( + 'Syntax error in %s.', + + str_replace('./', '', $filename) + ) + ); + } + + include_once $filename; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Util/Filter.php b/Util/Filter.php new file mode 100644 index 00000000000..0cdbe38097d --- /dev/null +++ b/Util/Filter.php @@ -0,0 +1,263 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: Filter.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +/** + * Utility class for code filtering. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + */ +class PHPUnit2_Util_Filter { + /** + * Source files that are to be filtered. + * + * @var array + * @access protected + * @static + */ + protected static $filteredFiles = array( + 'PHPUnit2/Extensions/ExceptionTestCase.php', + 'PHPUnit2/Extensions/PerformanceTestCase.php', + 'PHPUnit2/Extensions/RepeatedTest.php', + 'PHPUnit2/Extensions/TestDecorator.php', + 'PHPUnit2/Extensions/TestSetup.php', + 'PHPUnit2/Framework/Assert.php', + 'PHPUnit2/Framework/AssertionFailedError.php', + 'PHPUnit2/Framework/ComparisonFailure.php', + 'PHPUnit2/Framework/Error.php', + 'PHPUnit2/Framework/IncompleteTest.php', + 'PHPUnit2/Framework/IncompleteTestError.php', + 'PHPUnit2/Framework/Test.php', + 'PHPUnit2/Framework/TestCase.php', + 'PHPUnit2/Framework/TestFailure.php', + 'PHPUnit2/Framework/TestListener.php', + 'PHPUnit2/Framework/TestResult.php', + 'PHPUnit2/Framework/TestSuite.php', + 'PHPUnit2/Framework/Warning.php', + 'PHPUnit2/Runner/BaseTestRunner.php', + 'PHPUnit2/Runner/IncludePathTestCollector.php', + 'PHPUnit2/Runner/StandardTestSuiteLoader.php', + 'PHPUnit2/Runner/TestCollector.php', + 'PHPUnit2/Runner/TestSuiteLoader.php', + 'PHPUnit2/Runner/Version.php', + 'PHPUnit2/TextUI/ResultPrinter.php', + 'PHPUnit2/TextUI/TestRunner.php', + 'PHPUnit2/Util/CodeCoverage/Renderer/HTML.php', + 'PHPUnit2/Util/CodeCoverage/Renderer/Text.php', + 'PHPUnit2/Util/CodeCoverage/Renderer.php', + 'PHPUnit2/Util/Log/PEAR.php', + 'PHPUnit2/Util/Log/XML.php', + 'PHPUnit2/Util/TestDox/ResultPrinter/HTML.php', + 'PHPUnit2/Util/TestDox/ResultPrinter/Text.php', + 'PHPUnit2/Util/TestDox/NamePrettifier.php', + 'PHPUnit2/Util/TestDox/ResultPrinter.php', + 'PHPUnit2/Util/ErrorHandler.php', + 'PHPUnit2/Util/Fileloader.php', + 'PHPUnit2/Util/Filter.php', + 'PHPUnit2/Util/Printer.php', + 'PHPUnit2/Util/Skeleton.php', + 'Benchmark/Timer.php', + 'Console/Getopt.php', + 'Log/composite.php', + 'Log/console.php', + 'Log/display.php', + 'Log/error.php', + 'Log/file.php', + 'Log/mail.php', + 'Log/mcal.php', + 'Log/null.php', + 'Log/observer.php', + 'Log/sql.php', + 'Log/sqlite.php', + 'Log/syslog.php', + 'Log/win.php', + 'Log.php', + 'PEAR/Config.php', + 'PEAR.php' + ); + + /** + * Adds a new file to be filtered. + * + * @param string + * @access public + * @static + * @since Method available since Release 2.1.0 + */ + public static function addFileToFilter($filename) { + $filename = self::getCanonicalFilename($filename); + + if (!self::isFiltered($filename)) { + self::$filteredFiles[] = $filename; + } + } + + /** + * Removes a file from the filter. + * + * @param string + * @access public + * @static + * @since Method available since Release 2.1.0 + */ + public static function removeFileFromFilter($filename) { + $filename = self::getCanonicalFilename($filename); + $keys = array_keys(self::$filteredFiles); + + for ($i = 0; $i < sizeof($keys); $i++) { + if (self::$filteredFiles[$keys[$i]] == $filename) { + unset(self::$filteredFiles[$keys[$i]]); + break; + } + } + } + + /** + * Filters source lines from PHPUnit classes. + * + * @param array + * @return array + * @access public + * @static + */ + public static function getFilteredCodeCoverage($codeCoverageInformation) { + $files = array_keys($codeCoverageInformation); + + foreach ($files as $file) { + if (self::isFiltered($file)) { + unset($codeCoverageInformation[$file]); + } + } + + return $codeCoverageInformation; + } + + /** + * Filters stack frames from PHPUnit classes. + * + * @param Exception $e + * @return string + * @access public + * @static + */ + public static function getFilteredStacktrace(Exception $e) { + $filteredStacktrace = ''; + $stacktrace = $e->getTrace(); + + foreach ($stacktrace as $frame) { + $filtered = FALSE; + + if (isset($frame['file']) && !self::isFiltered($frame['file'])) { + $filteredStacktrace .= sprintf( + "%s:%s\n", + + $frame['file'], + isset($frame['line']) ? $frame['line'] : '?' + ); + } + } + + return $filteredStacktrace; + } + + /** + * Canonicalizes a source file name. + * + * @param string $filename + * @return string + * @access protected + * @static + */ + protected static function getCanonicalFilename($filename) { + foreach (array('PHPUnit2', 'Benchmark', 'Console', 'PEAR') as $package) { + $pos = strpos($filename, $package); + + if ($pos !== FALSE) { + $filename = substr($filename, $pos); + break; + } + } + + return str_replace( + '\\', + '/', + $filename + ); + } + + /** + * @param string $filename + * @return boolean + * @access protected + * @static + * @since Method available since Release 2.1.3 + */ + protected static function isFiltered($filename) { + if (substr($filename, -7) == 'phpunit' || + in_array(self::getCanonicalFilename($filename), self::$filteredFiles)) { + return TRUE; + } + + return FALSE; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Util/Log/PEAR.php b/Util/Log/PEAR.php new file mode 100644 index 00000000000..a7e808e4e68 --- /dev/null +++ b/Util/Log/PEAR.php @@ -0,0 +1,220 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: PEAR.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit2/Framework/TestListener.php'; + +@include_once 'Log.php'; + +/** + * A TestListener that logs to a PEAR_Log sink. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.1.0 + */ +class PHPUnit2_Util_Log_PEAR implements PHPUnit2_Framework_TestListener { + /** + * Log. + * + * @var Log + * @access private + */ + private $log; + + /** + * @param string $type The type of concrete Log subclass to use. + * Currently, valid values are 'console', + * 'syslog', 'sql', 'file', and 'mcal'. + * @param string $name The name of the actually log file, table, or + * other specific store to use. Defaults to an + * empty string, with which the subclass will + * attempt to do something intelligent. + * @param string $ident The identity reported to the log system. + * @param array $conf A hash containing any additional configuration + * information that a subclass might need. + * @param int $maxLevel Maximum priority level at which to log. + * @access public + */ + public function __construct($type, $name = '', $ident = '', $conf = array(), $maxLevel = PEAR_LOG_DEBUG) { + $this->log = Log::factory($type, $name, $ident, $conf, $maxLevel); + } + + /** + * An error occurred. + * + * @param PHPUnit2_Framework_Test $test + * @param Exception $e + * @access public + */ + public function addError(PHPUnit2_Framework_Test $test, Exception $e) { + $this->log->crit( + sprintf( + 'Test "%s" failed: %s', + + $test->getName(), + $e->getMessage() + ) + ); + } + + /** + * A failure occurred. + * + * @param PHPUnit2_Framework_Test $test + * @param PHPUnit2_Framework_AssertionFailedError $e + * @access public + */ + public function addFailure(PHPUnit2_Framework_Test $test, PHPUnit2_Framework_AssertionFailedError $e) { + $this->log->err( + sprintf( + 'Test "%s" failed: %s', + + $test->getName(), + $e->getMessage() + ) + ); + } + + /** + * Incomplete test. + * + * @param PHPUnit2_Framework_Test $test + * @param Exception $e + * @access public + */ + public function addIncompleteTest(PHPUnit2_Framework_Test $test, Exception $e) { + $this->log->info( + sprintf( + 'Test "%s" incomplete: %s', + + $test->getName(), + $e->getMessage() + ) + ); + } + + /** + * A test suite started. + * + * @param PHPUnit2_Framework_TestSuite $suite + * @access public + * @since Method available since Release 2.2.0 + */ + public function startTestSuite(PHPUnit2_Framework_TestSuite $suite) { + $this->log->info( + sprintf( + 'TestSuite "%s" started.', + + $suite->getName() + ) + ); + } + + /** + * A test suite ended. + * + * @param PHPUnit2_Framework_TestSuite $suite + * @access public + * @since Method available since Release 2.2.0 + */ + public function endTestSuite(PHPUnit2_Framework_TestSuite $suite) { + $this->log->info( + sprintf( + 'TestSuite "%s" ended.', + + $suite->getName() + ) + ); + } + + /** + * A test started. + * + * @param PHPUnit2_Framework_Test $test + * @access public + */ + public function startTest(PHPUnit2_Framework_Test $test) { + $this->log->info( + sprintf( + 'Test "%s" started.', + + $test->getName() + ) + ); + } + + /** + * A test ended. + * + * @param PHPUnit2_Framework_Test $test + * @access public + */ + public function endTest(PHPUnit2_Framework_Test $test) { + $this->log->info( + sprintf( + 'Test "%s" ended.', + + $test->getName() + ) + ); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Util/Log/XML.php b/Util/Log/XML.php new file mode 100644 index 00000000000..b212cf0c50d --- /dev/null +++ b/Util/Log/XML.php @@ -0,0 +1,356 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: XML.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit2/Framework/TestListener.php'; +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Util/Printer.php'; + +require_once 'Benchmark/Timer.php'; + +/** + * A TestListener that generates an XML-based logfile + * of the test execution. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.1.0 + */ +class PHPUnit2_Util_Log_XML extends PHPUnit2_Util_Printer implements PHPUnit2_Framework_TestListener { + /** + * @var DOMDocument + * @access private + */ + private $document; + + /** + * @var DOMElement + * @access private + */ + private $root; + + /** + * @var boolean + * @access private + */ + private $writeDocument = TRUE; + + /** + * @var DOMElement[] + * @access private + */ + private $testSuites = array(); + + /** + * @var integer[] + * @access private + */ + private $testSuiteTests = array(0); + + /** + * @var integer[] + * @access private + */ + private $testSuiteErrors = array(0); + + /** + * @var integer[] + * @access private + */ + private $testSuiteFailures = array(0); + + /** + * @var integer[] + * @access private + */ + private $testSuiteTimes = array(0); + + /** + * @var integer + * @access private + */ + private $testSuiteLevel = 0; + + /** + * @var DOMElement + * @access private + */ + private $currentTestCase = NULL; + + /** + * @var Benchmark_Timer + * @access private + */ + private $timer; + + /** + * Constructor. + * + * @param mixed $out + * @access public + */ + public function __construct($out = NULL) { + $this->document = new DOMDocument('1.0', 'UTF-8'); + $this->document->formatOutput = TRUE; + + $this->root = $this->document->createElement('testsuites'); + $this->document->appendChild($this->root); + + $this->timer = new Benchmark_Timer; + + parent::__construct($out); + } + + /** + * Destructor. + * + * @access public + */ + public function __destruct() { + if ($this->writeDocument === TRUE) { + $this->write($this->getXML()); + } + + parent::__destruct(); + } + + /** + * An error occurred. + * + * @param PHPUnit2_Framework_Test $test + * @param Exception $e + * @access public + */ + public function addError(PHPUnit2_Framework_Test $test, Exception $e) { + $error = $this->document->createElement('error', PHPUnit2_Util_Filter::getFilteredStacktrace($e)); + $error->setAttribute('message', $e->getMessage()); + $error->setAttribute('type', get_class($e)); + + $this->currentTestCase->appendChild($error); + + $this->testSuiteErrors[$this->testSuiteLevel]++; + } + + /** + * A failure occurred. + * + * @param PHPUnit2_Framework_Test $test + * @param PHPUnit2_Framework_AssertionFailedError $e + * @access public + */ + public function addFailure(PHPUnit2_Framework_Test $test, PHPUnit2_Framework_AssertionFailedError $e) { + $failure = $this->document->createElement('failure', PHPUnit2_Util_Filter::getFilteredStacktrace($e)); + $failure->setAttribute('message', $e->getMessage()); + $failure->setAttribute('type', get_class($e)); + + $this->currentTestCase->appendChild($failure); + + $this->testSuiteFailures[$this->testSuiteLevel]++; + } + + /** + * Incomplete test. + * + * @param PHPUnit2_Framework_Test $test + * @param Exception $e + * @access public + */ + public function addIncompleteTest(PHPUnit2_Framework_Test $test, Exception $e) { + $error = $this->document->createElement('error', PHPUnit2_Util_Filter::getFilteredStacktrace($e)); + $error->setAttribute('message', 'Incomplete Test'); + $error->setAttribute('type', get_class($e)); + + $this->currentTestCase->appendChild($error); + + $this->testSuiteErrors[$this->testSuiteLevel]++; + } + + /** + * A testsuite started. + * + * @param PHPUnit2_Framework_TestSuite $suite + * @access public + * @since Method available since Release 2.2.0 + */ + public function startTestSuite(PHPUnit2_Framework_TestSuite $suite) { + $testSuite = $this->document->createElement('testsuite'); + $testSuite->setAttribute('name', $suite->getName()); + + try { + $class = new ReflectionClass($suite->getName()); + $docComment = $class->getDocComment(); + + if (preg_match('/@category[\s]+([\.\w]+)/', $docComment, $matches)) { + $testSuite->setAttribute('category', $matches[1]); + } + + if (preg_match('/@package[\s]+([\.\w]+)/', $docComment, $matches)) { + $testSuite->setAttribute('package', $matches[1]); + } + + if (preg_match('/@subpackage[\s]+([\.\w]+)/', $docComment, $matches)) { + $testSuite->setAttribute('subpackage', $matches[1]); + } + } + + catch (ReflectionException $e) { + } + + if ($this->testSuiteLevel > 0) { + $this->testSuites[$this->testSuiteLevel]->appendChild($testSuite); + } else { + $this->root->appendChild($testSuite); + } + + $this->testSuiteLevel++; + $this->testSuites[$this->testSuiteLevel] = $testSuite; + $this->testSuiteTests[$this->testSuiteLevel] = 0; + $this->testSuiteErrors[$this->testSuiteLevel] = 0; + $this->testSuiteFailures[$this->testSuiteLevel] = 0; + $this->testSuiteTimes[$this->testSuiteLevel] = 0; + } + + /** + * A testsuite ended. + * + * @param PHPUnit2_Framework_TestSuite $suite + * @access public + * @since Method available since Release 2.2.0 + */ + public function endTestSuite(PHPUnit2_Framework_TestSuite $suite) { + $this->testSuites[$this->testSuiteLevel]->setAttribute('tests', $this->testSuiteTests[$this->testSuiteLevel]); + $this->testSuites[$this->testSuiteLevel]->setAttribute('failures', $this->testSuiteFailures[$this->testSuiteLevel]); + $this->testSuites[$this->testSuiteLevel]->setAttribute('errors', $this->testSuiteErrors[$this->testSuiteLevel]); + $this->testSuites[$this->testSuiteLevel]->setAttribute('time', $this->testSuiteTimes[$this->testSuiteLevel]); + + if ($this->testSuiteLevel > 1) { + $this->testSuiteTests[$this->testSuiteLevel - 1] += $this->testSuiteTests[$this->testSuiteLevel]; + $this->testSuiteErrors[$this->testSuiteLevel - 1] += $this->testSuiteErrors[$this->testSuiteLevel]; + $this->testSuiteFailures[$this->testSuiteLevel - 1] += $this->testSuiteFailures[$this->testSuiteLevel]; + $this->testSuiteTimes[$this->testSuiteLevel - 1] += $this->testSuiteTimes[$this->testSuiteLevel]; + } + + $this->testSuiteLevel--; + } + + /** + * A test started. + * + * @param PHPUnit2_Framework_Test $test + * @access public + */ + public function startTest(PHPUnit2_Framework_Test $test) { + $testCase = $this->document->createElement('testcase'); + $testCase->setAttribute('name', $test->getName()); + $testCase->setAttribute('class', get_class($test)); + + $this->testSuites[$this->testSuiteLevel]->appendChild($testCase); + $this->currentTestCase = $testCase; + + $this->testSuiteTests[$this->testSuiteLevel]++; + + $this->timer->start(); + } + + /** + * A test ended. + * + * @param PHPUnit2_Framework_Test $test + * @access public + */ + public function endTest(PHPUnit2_Framework_Test $test) { + $this->timer->stop(); + $time = $this->timer->timeElapsed(); + + $this->currentTestCase->setAttribute('time', $time); + $this->testSuiteTimes[$this->testSuiteLevel] += $time; + + $this->currentTestCase = NULL; + } + + /** + * Returns the XML as a string. + * + * @return string + * @access public + * @since Method available since Release 2.2.0 + */ + public function getXML() { + return $this->document->saveXML(); + } + + /** + * Enables or disables the writing of the document + * in __destruct(). + * + * This is a "hack" needed for the integration of + * PHPUnit with Phing. + * + * @return string + * @access public + * @since Method available since Release 2.2.0 + */ + public function setWriteDocument($flag) { + if (is_bool($flag)) { + $this->writeDocument = $flag; + } + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Util/Printer.php b/Util/Printer.php new file mode 100644 index 00000000000..bd0a38d7ad3 --- /dev/null +++ b/Util/Printer.php @@ -0,0 +1,116 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: Printer.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +/** + * Utility class that can print to STDOUT or write to a file. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.0.0 + * @abstract + */ +abstract class PHPUnit2_Util_Printer { + /** + * @var resource + * @access private + */ + private $out = NULL; + + /** + * Constructor. + * + * @param mixed $out + * @access public + */ + public function __construct($out = NULL) { + if ($out !== NULL) { + if (is_string($out)) { + $this->out = fopen($out, 'w'); + } else { + $this->out = $out; + } + } + } + + /** + * Destructor. + * + * @access public + */ + public function __destruct() { + if ($this->out !== NULL) { + fclose($this->out); + } + } + + /** + * @param string $buffer + * @access public + */ + public function write($buffer) { + if ($this->out !== NULL) { + fputs($this->out, $buffer); + } else { + print $buffer; + } + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Util/Skeleton.php b/Util/Skeleton.php new file mode 100644 index 00000000000..a3b6fb3ae8e --- /dev/null +++ b/Util/Skeleton.php @@ -0,0 +1,340 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: Skeleton.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.1.0 + */ + +/** + * Class for creating a PHPUnit2_Framework_TestCase skeleton file. + * + * This class will take a classname as a parameter on construction and will + * create a PHP file that contains the skeleton of a PHPUnit2_Framework_TestCase + * subclass. + * + * + * write(); + * ?> + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.1.0 + */ +class PHPUnit2_Util_Skeleton { + protected $templateClassHeader = +' +'; + + protected $templateMethod = +' + /** + * @todo Implement test{methodName}(). + */ + public function test{methodName}() { + // Remove the following line when you implement this test. + throw new PHPUnit2_Framework_IncompleteTestError; + } +'; + + /** + * @var string + * @access protected + */ + protected $className; + + /** + * @var string + * @access protected + */ + protected $classSourceFile; + + /** + * Constructor. + * + * @param string $className + * @param string $classSourceFile + * @throws Exception + * @access public + */ + public function __construct($className, $classSourceFile = '') { + if ($classSourceFile == '') { + $classSourceFile = $className . '.php'; + } + + if (file_exists($classSourceFile)) { + $this->classSourceFile = $classSourceFile; + } else { + throw new Exception( + sprintf( + 'Could not open %s.', + + $classSourceFile + ) + ); + } + + @include_once $this->classSourceFile; + + if (class_exists($className)) { + $this->className = $className; + } else { + throw new Exception( + sprintf( + 'Could not find class "%s" in %s.', + + $className, + $classSourceFile + ) + ); + } + } + + /** + * Generates the test class' source. + * + * @return string + * @access public + */ + public function generate() { + $testClassSource = $this->testClassHeader($this->className, $this->classSourceFile); + + $class = new ReflectionClass($this->className); + + foreach ($class->getMethods() as $method) { + if (!$method->isConstructor() && + !$method->isAbstract() && + $method->isUserDefined() && + $method->isPublic() && + $method->getDeclaringClass()->getName() == $this->className) { + $testClassSource .= $this->testMethod($method->getName()); + } + } + + $testClassSource .= $this->testClassFooter($this->className); + + return $testClassSource; + } + + /** + * Generates the test class and writes it to a source file. + * + * @param string $file + * @access public + */ + public function write($file = '') { + if ($file == '') { + $file = $this->className . 'Test.php'; + } + + if ($fp = @fopen($file, 'w')) { + @fputs($fp, $this->generate()); + @fclose($fp); + } + } + + /** + * Sets the templates for class header, class footer, and method. + * + * @param string $classHeader + * @param string $classFooter + * @param string $method + * @access public + * @since Method available since Release 2.2.0 + */ + public function setTemplates($classHeader, $classFooter, $method) { + if (is_file($classHeader)) { + $this->templateClassHeader = file_get_contents($classHeader); + } else { + $this->templateClassHeader = $classHeader; + } + + if (is_file($classFooter)) { + $this->templateClassFooter = file_get_contents($classFooter); + } else { + $this->templateClassFooter = $classFooter; + } + + if (is_file($method)) { + $this->templateMethod = file_get_contents($method); + } else { + $this->templateMethod = $method; + } + } + + /** + * @param string $className + * @param string $classSourceFile + * @access protected + */ + protected function testClassHeader($className, $classSourceFile) { + return str_replace( + array( + '{className}', + '{classFile}', + '{date}', + '{time}' + ), + array( + $className, + $classSourceFile, + date('Y-m-d'), + date('H:i:s') + ), + $this->templateClassHeader + ); + } + + /** + * @param string $className + * @access protected + */ + protected function testClassFooter($className) { + return str_replace( + array( + '{className}' + ), + array( + $className + ), + $this->templateClassFooter + ); + } + + /** + * @param string $methodName + * @access protected + */ + protected function testMethod($methodName) { + return str_replace( + array( + '{methodName}' + ), + array( + ucfirst($methodName) + ), + $this->templateMethod + ); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Util/TestDox/NamePrettifier.php b/Util/TestDox/NamePrettifier.php new file mode 100644 index 00000000000..99d27fd3521 --- /dev/null +++ b/Util/TestDox/NamePrettifier.php @@ -0,0 +1,165 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: NamePrettifier.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +/** + * Prettifies class and method names for use in TestDox documentation. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.1.0 + */ +class PHPUnit2_Util_TestDox_NamePrettifier { + /** + * @var string + * @access protected + */ + protected $prefix = 'Test'; + + /** + * @var string + * @access protected + */ + protected $suffix = 'Test'; + + /** + * Tests if a method is a test method. + * + * @param string $testMethodName + * @return boolean + * @access public + */ + public function isATestMethod($testMethodName) { + if (substr($testMethodName, 0, 4) == 'test') { + return TRUE; + } + + return FALSE; + } + + /** + * Prettifies the name of a test class. + * + * @param string $testClassName + * @return string + * @access public + */ + public function prettifyTestClass($testClassName) { + $title = $testClassName; + + if ($this->suffix !== NULL && + $this->suffix == substr($testClassName, -1 * strlen($this->suffix))) { + $title = substr($title, 0, strripos($title, $this->suffix)); + } + + if ($this->prefix !== NULL && + $this->prefix == substr($testClassName, 0, strlen($this->prefix))) { + $title = substr($title, strlen($this->prefix)); + } + + return $title; + } + + /** + * Prettifies the name of a test method. + * + * @param string $testMethodName + * @return string + * @access public + */ + public function prettifyTestMethod($testMethodName) { + $buffer = ''; + + $testMethodName = preg_replace('#\d+$#', '', $testMethodName); + + for ($i = 4; $i < strlen($testMethodName); $i++) { + if ($i > 4 && + ord($testMethodName[$i]) >= 65 && + ord($testMethodName[$i]) <= 90) { + $buffer .= ' ' . strtolower($testMethodName[$i]); + } else { + $buffer .= $testMethodName[$i]; + } + } + + return $buffer; + } + + /** + * Sets the prefix of test names. + * + * @param string $prefix + * @access public + */ + public function setPrefix($prefix) { + $this->prefix = $prefix; + } + + /** + * Sets the suffix of test names. + * + * @param string $prefix + * @access public + */ + public function setSuffix($suffix) { + $this->suffix = $suffix; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Util/TestDox/ResultPrinter.php b/Util/TestDox/ResultPrinter.php new file mode 100644 index 00000000000..dacc070dc0c --- /dev/null +++ b/Util/TestDox/ResultPrinter.php @@ -0,0 +1,299 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: ResultPrinter.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit2/Framework/TestListener.php'; +require_once 'PHPUnit2/Util/TestDox/NamePrettifier.php'; +require_once 'PHPUnit2/Util/Printer.php'; + +/** + * Base class for printers of TestDox documentation. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.1.0 + * @abstract + */ +abstract class PHPUnit2_Util_TestDox_ResultPrinter extends PHPUnit2_Util_Printer implements PHPUnit2_Framework_TestListener { + /** + * @var PHPUnit2_Util_TestDox_NamePrettifier + * @access protected + */ + protected $prettifier; + + /** + * @var string + * @access protected + */ + protected $testClass = ''; + + /** + * @var boolean + * @access protected + */ + protected $testFailed = FALSE; + + /** + * @var array + * @access protected + */ + protected $tests = array(); + + /** + * Constructor. + * + * @param resource $out + * @access public + */ + public function __construct($out = NULL) { + parent::__construct($out); + + $this->prettifier = new PHPUnit2_Util_TestDox_NamePrettifier; + $this->startRun(); + } + + /** + * Destructor. + * + * @access public + */ + public function __destruct() { + $this->doEndClass(); + $this->endRun(); + + parent::__destruct(); + } + + /** + * Abstract Factory. + * + * @param string $type + * @param resource $out + * @throws Exception + * @access public + * @static + */ + public static function factory($type, $out = NULL) { + require_once 'PHPUnit2/Util/TestDox/ResultPrinter/' . $type . '.php'; + + $class = 'PHPUnit2_Util_TestDox_ResultPrinter_' . $type; + return new $class($out); + } + + /** + * An error occurred. + * + * @param PHPUnit2_Framework_Test $test + * @param Exception $e + * @access public + */ + public function addError(PHPUnit2_Framework_Test $test, Exception $e) { + $this->testFailed = TRUE; + } + + /** + * A failure occurred. + * + * @param PHPUnit2_Framework_Test $test + * @param PHPUnit2_Framework_AssertionFailedError $e + * @access public + */ + public function addFailure(PHPUnit2_Framework_Test $test, PHPUnit2_Framework_AssertionFailedError $e) { + $this->testFailed = TRUE; + } + + /** + * Incomplete test. + * + * @param PHPUnit2_Framework_Test $test + * @param Exception $e + * @access public + */ + public function addIncompleteTest(PHPUnit2_Framework_Test $test, Exception $e) { + $this->testFailed = TRUE; + } + + /** + * A testsuite started. + * + * @param PHPUnit2_Framework_TestSuite $suite + * @access public + * @since Method available since Release 2.2.0 + */ + public function startTestSuite(PHPUnit2_Framework_TestSuite $suite) { + } + + /** + * A testsuite ended. + * + * @param PHPUnit2_Framework_TestSuite $suite + * @access public + * @since Method available since Release 2.2.0 + */ + public function endTestSuite(PHPUnit2_Framework_TestSuite $suite) { + } + + /** + * A test started. + * + * @param PHPUnit2_Framework_Test $test + * @access public + */ + public function startTest(PHPUnit2_Framework_Test $test) { + $class = get_class($test); + + if ($this->testClass != $class) { + if ($this->testClass != '') { + $this->doEndClass(); + } + + $this->startClass($this->prettifier->prettifyTestClass($class)); + + $this->testClass = $class; + $this->tests = array(); + } + + $this->testFailed = FALSE; + } + + /** + * A test ended. + * + * @param PHPUnit2_Framework_Test $test + * @access public + */ + public function endTest(PHPUnit2_Framework_Test $test) { + $prettifiedName = $this->prettifier->prettifyTestMethod($test->getName()); + + if (!isset($this->tests[$prettifiedName])) { + if (!$this->testFailed) { + $this->tests[$prettifiedName]['success'] = 1; + $this->tests[$prettifiedName]['failure'] = 0; + } else { + $this->tests[$prettifiedName]['success'] = 0; + $this->tests[$prettifiedName]['failure'] = 1; + } + } else { + if (!$this->testFailed) { + $this->tests[$prettifiedName]['success']++; + } else { + $this->tests[$prettifiedName]['failure']++; + } + } + } + + /** + * @access private + * @since Method available since Release 2.3.0 + */ + private function doEndClass() { + foreach ($this->tests as $name => $data) { + if ($data['failure'] == 0) { + $this->onTest($name); + } + } + + $this->endClass($this->prettifier->prettifyTestClass($this->testClass)); + } + + /** + * Handler for 'start run' event. + * + * @access protected + */ + protected function startRun() { + } + + /** + * Handler for 'start class' event. + * + * @param string $name + * @access protected + * @abstract + */ + abstract protected function startClass($name); + + /** + * Handler for 'on test' event. + * + * @param string $name + * @access protected + * @abstract + */ + abstract protected function onTest($name); + + /** + * Handler for 'end class' event. + * + * @param string $name + * @access protected + * @abstract + */ + abstract protected function endClass($name); + + /** + * Handler for 'end run' event. + * + * @access protected + */ + protected function endRun() { + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Util/TestDox/ResultPrinter/HTML.php b/Util/TestDox/ResultPrinter/HTML.php new file mode 100644 index 00000000000..2760753d240 --- /dev/null +++ b/Util/TestDox/ResultPrinter/HTML.php @@ -0,0 +1,120 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: HTML.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit2/Util/TestDox/ResultPrinter.php'; + +/** + * Prints TestDox documentation in HTML format. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.1.0 + */ +class PHPUnit2_Util_TestDox_ResultPrinter_HTML extends PHPUnit2_Util_TestDox_ResultPrinter { + /** + * Handler for 'start run' event. + * + * @access protected + */ + protected function startRun() { + $this->write(''); + } + + /** + * Handler for 'start class' event. + * + * @param string $name + * @access protected + */ + protected function startClass($name) { + $this->write('

' . $name . '

    '); + } + + /** + * Handler for 'on test' event. + * + * @param string $name + * @access protected + */ + protected function onTest($name) { + $this->write('
  • ' . $name . '
  • '); + } + + /** + * Handler for 'end class' event. + * + * @param string $name + * @access protected + */ + protected function endClass($name) { + $this->write('
'); + } + + /** + * Handler for 'end run' event. + * + * @access protected + */ + protected function endRun() { + $this->write(''); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Util/TestDox/ResultPrinter/Text.php b/Util/TestDox/ResultPrinter/Text.php new file mode 100644 index 00000000000..aec19d5fb3a --- /dev/null +++ b/Util/TestDox/ResultPrinter/Text.php @@ -0,0 +1,102 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version CVS: $Id: Text.php 539 2006-02-13 16:08:42Z sb $ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit2/Util/TestDox/ResultPrinter.php'; + +/** + * Prints TestDox documentation in text format. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version Release: @package_version@ + * @link http://pear.php.net/package/PHPUnit2 + * @since Class available since Release 2.1.0 + */ +class PHPUnit2_Util_TestDox_ResultPrinter_Text extends PHPUnit2_Util_TestDox_ResultPrinter { + /** + * Handler for 'start class' event. + * + * @param string $name + * @access protected + */ + protected function startClass($name) { + $this->write($name . "\n"); + } + + /** + * Handler for 'on test' event. + * + * @param string $name + * @access protected + */ + protected function onTest($name) { + $this->write(' - ' . $name . "\n"); + } + + /** + * Handler for 'end class' event. + * + * @param string $name + * @access protected + */ + protected function endClass($name) { + $this->write("\n"); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/package.xml b/package.xml new file mode 100644 index 00000000000..d5583761c9c --- /dev/null +++ b/package.xml @@ -0,0 +1,608 @@ + + + + PHPUnit2 + Regression testing framework for unit tests. + PHPUnit is a regression testing framework used by the developer who implements unit tests in PHP. This is the version to be used with PHP 5. + + + + sebastian + Sebastian Bergmann + sb@sebastian-bergmann.de + lead + + + + 2.3.4 + 2005-12-27 + BSD License + stable + * Fixed bug #6272: Undefined index: failures in ResultPrinter.php + +* Fixed bug #6282: Invalid PHP syntax validation in Fileloader.php + + + + dom + pcre + spl + xdebug + Benchmark + Console_Getopt + Log + PEAR + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pear-phpunit b/pear-phpunit new file mode 100644 index 00000000000..1d0fbe99a81 --- /dev/null +++ b/pear-phpunit @@ -0,0 +1,41 @@ +#!@php_bin@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * $Id: pear-phpunit,v 1.2.8.2 2005/12/17 16:04:56 sebastian Exp $ + */ + +require 'PHPUnit2/TextUI/TestRunner.php'; +?> diff --git a/pear-phpunit.bat b/pear-phpunit.bat new file mode 100644 index 00000000000..707a29a524c --- /dev/null +++ b/pear-phpunit.bat @@ -0,0 +1,39 @@ +@echo off +REM PHP Version 5 +REM +REM Copyright (c) 2002-2006, Sebastian Bergmann . +REM All rights reserved. +REM +REM Redistribution and use in source and binary forms, with or without +REM modification, are permitted provided that the following conditions +REM are met: +REM +REM * Redistributions of source code must retain the above copyright +REM notice, this list of conditions and the following disclaimer. +REM +REM * Redistributions in binary form must reproduce the above copyright +REM notice, this list of conditions and the following disclaimer in +REM the documentation and/or other materials provided with the +REM distribution. +REM +REM * Neither the name of Sebastian Bergmann nor the names of his +REM contributors may be used to endorse or promote products derived +REM from this software without specific prior written permission. +REM +REM THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +REM "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +REM LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +REM FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +REM COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +REM INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, +REM BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +REM LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +REM CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRIC +REM LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +REM ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +REM POSSIBILITY OF SUCH DAMAGE. +REM +REM $Id: pear-phpunit.bat,v 1.3.2.2 2005/12/17 16:04:56 sebastian Exp $ +REM + +"@php_bin@" "@php_dir@/PHPUnit2/TextUI/TestRunner.php" %*