Browse files

Initial import.

  • Loading branch information...
0 parents commit 98ffbb2bbed1c1cefba21eae9620fd018000c5ef @sebastianbergmann committed Jun 29, 2006
Showing with 14,427 additions and 0 deletions.
  1. +122 −0 Extensions/ExceptionTestCase.php
  2. +128 −0 Extensions/PerformanceTestCase.php
  3. +138 −0 Extensions/RepeatedTest.php
  4. +174 −0 Extensions/TestDecorator.php
  5. +154 −0 Extensions/TestSetup.php
  6. +626 −0 Framework/Assert.php
  7. +80 −0 Framework/AssertionFailedError.php
  8. +153 −0 Framework/ComparisonFailure.php
  9. +88 −0 Framework/Error.php
  10. +72 −0 Framework/IncompleteTest.php
  11. +75 −0 Framework/IncompleteTestError.php
  12. +87 −0 Framework/Test.php
  13. +292 −0 Framework/TestCase.php
  14. +154 −0 Framework/TestFailure.php
  15. +135 −0 Framework/TestListener.php
  16. +447 −0 Framework/TestResult.php
  17. +554 −0 Framework/TestSuite.php
  18. +94 −0 Framework/Warning.php
  19. +283 −0 Runner/BaseTestRunner.php
  20. +184 −0 Runner/IncludePathTestCollector.php
  21. +129 −0 Runner/StandardTestSuiteLoader.php
  22. +77 −0 Runner/TestCollector.php
  23. +85 −0 Runner/TestSuiteLoader.php
  24. +90 −0 Runner/Version.php
  25. +133 −0 Samples/BankAccount/BankAccount.php
  26. +150 −0 Samples/BankAccount/BankAccountTest.php
  27. +82 −0 Samples/Money/IMoney.php
  28. +146 −0 Samples/Money/Money.php
  29. +240 −0 Samples/Money/MoneyBag.php
  30. +234 −0 Samples/Money/MoneyTest.php
  31. +101 −0 Tests/AllTests.php
  32. +93 −0 Tests/DoubleTestCase.php
  33. +76 −0 Tests/Error.php
  34. +108 −0 Tests/Extensions/AllTests.php
  35. +105 −0 Tests/Extensions/ExceptionTestCaseTest.php
  36. +119 −0 Tests/Extensions/ExtensionTest.php
  37. +92 −0 Tests/Extensions/PerformanceTestCaseTest.php
  38. +122 −0 Tests/Extensions/RepeatedTestTest.php
  39. +76 −0 Tests/Failure.php
  40. +119 −0 Tests/Framework/AllTests.php
  41. +574 −0 Tests/Framework/AssertTest.php
  42. +172 −0 Tests/Framework/ComparisonFailureTest.php
  43. +197 −0 Tests/Framework/SuiteTest.php
  44. +193 −0 Tests/Framework/TestCaseTest.php
  45. +94 −0 Tests/Framework/TestImplementorTest.php
  46. +145 −0 Tests/Framework/TestListenerTest.php
  47. +76 −0 Tests/InheritedTestCase.php
  48. +86 −0 Tests/MockRunner.php
  49. +75 −0 Tests/NoArgTestCaseTest.php
  50. +73 −0 Tests/NoTestCaseClass.php
  51. +75 −0 Tests/NoTestCases.php
  52. +74 −0 Tests/NonStatic.php
  53. +78 −0 Tests/NotPublicTestCase.php
  54. +73 −0 Tests/NotVoidTestCase.php
  55. +78 −0 Tests/OneTestCase.php
  56. +76 −0 Tests/OverrideTestCase.php
  57. +104 −0 Tests/Runner/AllTests.php
  58. +80 −0 Tests/Runner/BaseTestRunnerTest.php
  59. +76 −0 Tests/SetupFailure.php
  60. +76 −0 Tests/Sleep.php
  61. +75 −0 Tests/Success.php
  62. +76 −0 Tests/TearDownFailure.php
  63. +97 −0 Tests/TestIterator.php
  64. +76 −0 Tests/ThrowExceptionTestCase.php
  65. +75 −0 Tests/ThrowNoExceptionTestCase.php
  66. +78 −0 Tests/TornDown.php
  67. +82 −0 Tests/TornDown2.php
  68. +81 −0 Tests/TornDown3.php
  69. +76 −0 Tests/TornDown4.php
  70. +76 −0 Tests/TornDown5.php
  71. +76 −0 Tests/TornDown6.php
  72. +100 −0 Tests/Util/TestDox/AllTests.php
  73. +117 −0 Tests/Util/TestDox/NamePrettifierTest.php
  74. +78 −0 Tests/WasRun.php
  75. +356 −0 TextUI/ResultPrinter.php
  76. +622 −0 TextUI/TestRunner.php
  77. +225 −0 Util/CodeCoverage/Renderer.php
  78. +191 −0 Util/CodeCoverage/Renderer/HTML.php
  79. +125 −0 Util/CodeCoverage/Renderer/Text.php
  80. +77 −0 Util/ErrorHandler.php
  81. +109 −0 Util/Fileloader.php
  82. +263 −0 Util/Filter.php
  83. +220 −0 Util/Log/PEAR.php
  84. +356 −0 Util/Log/XML.php
  85. +116 −0 Util/Printer.php
  86. +340 −0 Util/Skeleton.php
  87. +165 −0 Util/TestDox/NamePrettifier.php
  88. +299 −0 Util/TestDox/ResultPrinter.php
  89. +120 −0 Util/TestDox/ResultPrinter/HTML.php
  90. +102 −0 Util/TestDox/ResultPrinter/Text.php
  91. +606 −0 package.xml
  92. +41 −0 pear-phpunit
  93. +39 −0 pear-phpunit.bat
122 Extensions/ExceptionTestCase.php
@@ -0,0 +1,122 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * PHP Version 5
+ *
+ * Copyright (c) 2002-2006, Sebastian Bergmann <sb@sebastian-bergmann.de>.
+ * 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 <sb@sebastian-bergmann.de>
+ * @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version CVS: $Id: ExceptionTestCase.php,v 1.15.2.6 2006/02/20 07:42:59 sebastian Exp $
+ * @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 <sb@sebastian-bergmann.de>
+ * @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @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 mixed
+ * @access private
+ */
+ private $expectedException = NULL;
+
+ /**
+ * @return string
+ * @access public
+ * @since Method available since Release 2.2.0
+ */
+ public function getExpectedException() {
+ return $this->expectedException;
+ }
+
+ /**
+ * @param mixed $exceptionName
+ * @access public
+ * @since Method available since Release 2.2.0
+ */
+ public function setExpectedException($exceptionName) {
+ if ((is_string($exceptionName) && class_exists($exceptionName)) || $exceptionName === NULL) {
+ $this->expectedException = $exceptionName;
+ }
+ }
+
+ /**
+ * @access protected
+ */
+ protected function runTest() {
+ try {
+ parent::runTest();
+ }
+
+ catch (Exception $e) {
+ if ($this->expectedException !== NULL &&
+ $e instanceof $this->expectedException) {
+ return;
+ } else {
+ throw $e;
+ }
+ }
+
+ if ($this->expectedException !== NULL) {
+ $this->fail('Expected exception ' . $this->expectedException);
+ }
+ }
+}
+
+/*
+ * Local variables:
+ * tab-width: 4
+ * c-basic-offset: 4
+ * c-hanging-comment-ender-p: nil
+ * End:
+ */
+?>
128 Extensions/PerformanceTestCase.php
@@ -0,0 +1,128 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * PHP Version 5
+ *
+ * Copyright (c) 2002-2006, Sebastian Bergmann <sb@sebastian-bergmann.de>.
+ * 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 <sb@sebastian-bergmann.de>
+ * @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version CVS: $Id: PerformanceTestCase.php,v 1.15.2.5 2005/12/17 16:04:56 sebastian Exp $
+ * @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 <sb@sebastian-bergmann.de>
+ * @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @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:
+ */
+?>
138 Extensions/RepeatedTest.php
@@ -0,0 +1,138 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * PHP Version 5
+ *
+ * Copyright (c) 2002-2006, Sebastian Bergmann <sb@sebastian-bergmann.de>.
+ * 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 <sb@sebastian-bergmann.de>
+ * @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version CVS: $Id: RepeatedTest.php,v 1.15.2.4 2005/12/17 16:04:56 sebastian Exp $
+ * @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 <sb@sebastian-bergmann.de>
+ * @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @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:
+ */
+?>
174 Extensions/TestDecorator.php
@@ -0,0 +1,174 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * PHP Version 5
+ *
+ * Copyright (c) 2002-2006, Sebastian Bergmann <sb@sebastian-bergmann.de>.
+ * 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 <sb@sebastian-bergmann.de>
+ * @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version CVS: $Id: TestDecorator.php,v 1.14.2.4 2005/12/17 16:04:56 sebastian Exp $
+ * @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 <sb@sebastian-bergmann.de>
+ * @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @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:
+ */
+?>
154 Extensions/TestSetup.php
@@ -0,0 +1,154 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * PHP Version 5
+ *
+ * Copyright (c) 2002-2006, Sebastian Bergmann <sb@sebastian-bergmann.de>.
+ * 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 <sb@sebastian-bergmann.de>
+ * @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version CVS: $Id: TestSetup.php,v 1.13.2.6 2005/12/17 16:04:56 sebastian Exp $
+ * @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 <sb@sebastian-bergmann.de>
+ * @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @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:
+ */
+?>
626 Framework/Assert.php
@@ -0,0 +1,626 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * PHP Version 5
+ *
+ * Copyright (c) 2002-2006, Sebastian Bergmann <sb@sebastian-bergmann.de>.
+ * 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 <sb@sebastian-bergmann.de>
+ * @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version CVS: $Id: Assert.php,v 1.45.2.4 2005/12/17 16:04:56 sebastian Exp $
+ * @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 <sb@sebastian-bergmann.de>
+ * @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @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 <adam@trachtenberg.com>
+ */
+ 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:
+ */
+?>
80 Framework/AssertionFailedError.php
@@ -0,0 +1,80 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * PHP Version 5
+ *
+ * Copyright (c) 2002-2006, Sebastian Bergmann <sb@sebastian-bergmann.de>.
+ * 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 <sb@sebastian-bergmann.de>
+ * @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version CVS: $Id: AssertionFailedError.php,v 1.9.2.2 2005/12/17 16:04:56 sebastian Exp $
+ * @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 <sb@sebastian-bergmann.de>
+ * @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @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:
+ */
+?>
153 Framework/ComparisonFailure.php
@@ -0,0 +1,153 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * PHP Version 5
+ *
+ * Copyright (c) 2002-2006, Sebastian Bergmann <sb@sebastian-bergmann.de>.
+ * 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 <sb@sebastian-bergmann.de>
+ * @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version CVS: $Id: ComparisonFailure.php,v 1.13.2.3 2005/12/17 16:04:56 sebastian Exp $
+ * @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 <sb@sebastian-bergmann.de>
+ * @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @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:
+ */
+?>
88 Framework/Error.php
@@ -0,0 +1,88 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * PHP Version 5
+ *
+ * Copyright (c) 2002-2006, Sebastian Bergmann <sb@sebastian-bergmann.de>.
+ * 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 <sb@sebastian-bergmann.de>
+ * @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version CVS: $Id: Error.php,v 1.4.2.2 2005/12/17 16:04:56 sebastian Exp $
+ * @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 <sb@sebastian-bergmann.de>
+ * @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @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:
+ */
+?>
72 Framework/IncompleteTest.php
@@ -0,0 +1,72 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * PHP Version 5
+ *
+ * Copyright (c) 2002-2006, Sebastian Bergmann <sb@sebastian-bergmann.de>.
+ * 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 <sb@sebastian-bergmann.de>
+ * @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version CVS: $Id: IncompleteTest.php,v 1.6.2.2 2005/12/17 16:04:56 sebastian Exp $
+ * @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 <sb@sebastian-bergmann.de>
+ * @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @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:
+ */
+?>
75 Framework/IncompleteTestError.php
@@ -0,0 +1,75 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * PHP Version 5
+ *
+ * Copyright (c) 2002-2006, Sebastian Bergmann <sb@sebastian-bergmann.de>.
+ * 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 <sb@sebastian-bergmann.de>
+ * @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version CVS: $Id: IncompleteTestError.php,v 1.5.2.3 2005/12/17 16:04:56 sebastian Exp $
+ * @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 <sb@sebastian-bergmann.de>
+ * @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @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:
+ */
+?>
87 Framework/Test.php
@@ -0,0 +1,87 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * PHP Version 5
+ *
+ * Copyright (c) 2002-2006, Sebastian Bergmann <sb@sebastian-bergmann.de>.
+ * 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 <sb@sebastian-bergmann.de>
+ * @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version CVS: $Id: Test.php,v 1.12.2.3 2005/12/17 16:04:56 sebastian Exp $
+ * @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 <sb@sebastian-bergmann.de>
+ * @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @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:
+ */
+?>
292 Framework/TestCase.php
@@ -0,0 +1,292 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * PHP Version 5
+ *
+ * Copyright (c) 2002-2006, Sebastian Bergmann <sb@sebastian-bergmann.de>.
+ * 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 <sb@sebastian-bergmann.de>
+ * @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @license http://www.opensource.org/licenses/bsd-license.php BSD License
+ * @version CVS: $Id: TestCase.php,v 1.32.2.5 2005/12/17 16:04:56 sebastian Exp $
+ * @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:
+ *
+ * <code>
+ * <?php
+ * require_once 'PHPUnit2/Framework/TestCase.php';
+ *
+ * class MathTest extends PHPUnit2_Framework_TestCase {
+ * public $value1;
+ * public $value2;
+ *
+ * public function __construct($name) {
+ * parent::__construct($name);
+ * }
+ *
+ * public function setUp() {
+ * $this->value1 = 2;
+ * $this->value2 = 3;
+ * }
+ * }
+ * ?>
+ * </code>
+ *
+ * For each test implement a method which interacts with the fixture.
+ * Verify the expected results with assertions specified by calling
+ * assert with a boolean.
+ *
+ * <code>
+ * <?php
+ * public function testPass() {
+ * $this->assertTrue($this->value1 + $this->value2 == 5);
+ * }
+ * ?>
+ * </code>
+ *
+ * @category Testing
+ * @package PHPUnit2
+ * @author Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @copyright 2002-2006 Sebastian Bergmann <sb@sebastian-bergmann.de>
+ * @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.'
+ );