From 8b8c705ce7dd77b02ba768d39224dddfeb34fb62 Mon Sep 17 00:00:00 2001 From: Sebastian Bergmann Date: Thu, 29 Jun 2006 14:58:01 +0000 Subject: [PATCH] Recreate trunk. --- Extensions/ExceptionTestCase.php | 129 ++ Extensions/MockObject/Builder/Identity.php | 90 ++ .../MockObject/Builder/InvocationMocker.php | 167 +++ Extensions/MockObject/Builder/Match.php | 87 ++ .../MockObject/Builder/MethodNameMatch.php | 89 ++ Extensions/MockObject/Builder/Namespace.php | 98 ++ .../MockObject/Builder/ParametersMatch.php | 110 ++ Extensions/MockObject/Builder/Stub.php | 87 ++ Extensions/MockObject/Invocation.php | 110 ++ Extensions/MockObject/InvocationMocker.php | 159 +++ Extensions/MockObject/Invokable.php | 101 ++ Extensions/MockObject/Matcher.php | 294 ++++ .../MockObject/Matcher/AnyParameters.php | 89 ++ Extensions/MockObject/Matcher/Invocation.php | 109 ++ .../MockObject/Matcher/InvokedAtIndex.php | 126 ++ .../MockObject/Matcher/InvokedAtLeastOnce.php | 97 ++ .../MockObject/Matcher/InvokedCount.php | 125 ++ .../MockObject/Matcher/InvokedRecorder.php | 110 ++ Extensions/MockObject/Matcher/MethodName.php | 105 ++ Extensions/MockObject/Matcher/Parameters.php | 153 ++ .../Matcher/StatelessInvocation.php | 91 ++ Extensions/MockObject/Mock.php | 347 +++++ Extensions/MockObject/MockObject.php | 98 ++ Extensions/MockObject/Stub.php | 96 ++ .../MockObject/Stub/ConsecutiveCalls.php | 107 ++ .../MockObject/Stub/MatcherCollection.php | 86 ++ Extensions/MockObject/Stub/Return.php | 100 ++ Extensions/MockObject/Verifiable.php | 85 ++ Extensions/OutputTestCase.php | 172 +++ Extensions/PerformanceTestCase.php | 132 ++ Extensions/RepeatedTest.php | 139 ++ Extensions/TestDecorator.php | 176 +++ Extensions/TestSetup.php | 156 +++ Framework.php | 79 ++ Framework/Assert.php | 1095 +++++++++++++++ Framework/AssertionFailedError.php | 114 ++ Framework/ComparisonFailure.php | 278 ++++ Framework/ComparisonFailure/Array.php | 122 ++ Framework/ComparisonFailure/Object.php | 147 ++ Framework/ComparisonFailure/Scalar.php | 131 ++ Framework/ComparisonFailure/String.php | 122 ++ Framework/ComparisonFailure/Type.php | 173 +++ Framework/Constraint.php | 128 ++ Framework/Constraint/And.php | 169 +++ Framework/Constraint/ArrayHasKey.php | 139 ++ Framework/Constraint/FileExists.php | 122 ++ Framework/Constraint/GreaterThan.php | 135 ++ Framework/Constraint/IsAnything.php | 111 ++ Framework/Constraint/IsEqual.php | 333 +++++ Framework/Constraint/IsIdentical.php | 140 ++ Framework/Constraint/IsInstanceOf.php | 147 ++ Framework/Constraint/IsType.php | 222 +++ Framework/Constraint/LessThan.php | 135 ++ Framework/Constraint/Not.php | 130 ++ Framework/Constraint/ObjectHasAttribute.php | 137 ++ Framework/Constraint/Or.php | 155 +++ Framework/Constraint/PCREMatch.php | 138 ++ Framework/Constraint/StringContains.php | 158 +++ Framework/Constraint/TraversableContains.php | 141 ++ Framework/Error.php | 98 ++ Framework/ExpectationFailedException.php | 111 ++ Framework/IncompleteTest.php | 81 ++ Framework/IncompleteTestError.php | 82 ++ Framework/SelfDescribing.php | 88 ++ Framework/SkippedTest.php | 80 ++ Framework/SkippedTestError.php | 82 ++ Framework/Test.php | 89 ++ Framework/TestCase.php | 473 +++++++ Framework/TestFailure.php | 166 +++ Framework/TestListener.php | 151 ++ Framework/TestResult.php | 595 ++++++++ Framework/TestSuite.php | 606 ++++++++ Framework/Warning.php | 104 ++ Runner/BaseTestRunner.php | 312 +++++ Runner/IncludePathTestCollector.php | 146 ++ Runner/StandardTestSuiteLoader.php | 130 ++ Runner/TestCollector.php | 82 ++ Runner/TestFilterIterator.php | 89 ++ Runner/TestSuiteLoader.php | 90 ++ Runner/Version.php | 97 ++ Samples/BankAccount/.cvsignore | 1 + Samples/BankAccount/BankAccount.php | 138 ++ Samples/BankAccount/BankAccountTest.php | 156 +++ Samples/Money/.cvsignore | 1 + Samples/Money/IMoney.php | 83 ++ Samples/Money/Money.php | 161 +++ Samples/Money/MoneyBag.php | 260 ++++ Samples/Money/MoneyTest.php | 258 ++++ Tests/AllTests.php | 109 ++ Tests/Extensions/AllTests.php | 114 ++ Tests/Extensions/ExceptionTestCaseTest.php | 109 ++ Tests/Extensions/ExtensionTest.php | 124 ++ Tests/Extensions/MockObjectTest.php | 112 ++ Tests/Extensions/OutputTestCaseTest.php | 111 ++ Tests/Extensions/PerformanceTestCaseTest.php | 95 ++ Tests/Extensions/RepeatedTestTest.php | 128 ++ Tests/Framework/AllTests.php | 114 ++ Tests/Framework/AssertTest.php | 1237 +++++++++++++++++ Tests/Framework/ComparisonFailureTest.php | 154 ++ Tests/Framework/SuiteTest.php | 208 +++ Tests/Framework/TestCaseTest.php | 210 +++ Tests/Framework/TestImplementorTest.php | 97 ++ Tests/Framework/TestListenerTest.php | 164 +++ Tests/Runner/AllTests.php | 104 ++ Tests/Runner/BaseTestRunnerTest.php | 82 ++ Tests/Util/AllTests.php | 103 ++ Tests/Util/TestDox/AllTests.php | 103 ++ Tests/Util/TestDox/NamePrettifierTest.php | 124 ++ Tests/_files/AnInterface.php | 77 + Tests/_files/ClassWithNonPublicAttributes.php | 83 ++ Tests/_files/DoubleTestCase.php | 98 ++ Tests/_files/Error.php | 81 ++ Tests/_files/Failure.php | 81 ++ Tests/_files/InheritedTestCase.php | 81 ++ Tests/_files/MockRunner.php | 93 ++ Tests/_files/NoArgTestCaseTest.php | 80 ++ Tests/_files/NoTestCaseClass.php | 76 + Tests/_files/NoTestCases.php | 80 ++ Tests/_files/NonStatic.php | 80 ++ Tests/_files/NotPublicTestCase.php | 84 ++ Tests/_files/NotVoidTestCase.php | 77 + Tests/_files/OneTestCase.php | 84 ++ Tests/_files/OutputTestCase.php | 101 ++ Tests/_files/OverrideTestCase.php | 81 ++ Tests/_files/SampleClass.php | 86 ++ Tests/_files/SetupFailure.php | 82 ++ Tests/_files/Sleep.php | 82 ++ Tests/_files/Success.php | 81 ++ Tests/_files/TearDownFailure.php | 82 ++ Tests/_files/TestIterator.php | 108 ++ Tests/_files/ThrowExceptionTestCase.php | 82 ++ Tests/_files/ThrowNoExceptionTestCase.php | 81 ++ Tests/_files/TornDown.php | 84 ++ Tests/_files/TornDown2.php | 89 ++ Tests/_files/TornDown3.php | 88 ++ Tests/_files/TornDown4.php | 82 ++ Tests/_files/TornDown5.php | 82 ++ Tests/_files/TornDown6.php | 82 ++ Tests/_files/WasRun.php | 83 ++ TextUI/ResultPrinter.php | 449 ++++++ TextUI/TestRunner.php | 687 +++++++++ Util/Array.php | 95 ++ Util/ErrorHandler.php | 83 ++ Util/Fileloader.php | 177 +++ Util/Filesystem.php | 91 ++ Util/Filter.php | 282 ++++ Util/Getopt.php | 191 +++ Util/Log/Eclipse.php | 300 ++++ Util/Log/GraphViz.php | 348 +++++ Util/Log/PEAR.php | 252 ++++ Util/Log/TAP.php | 253 ++++ Util/Log/XML.php | 379 +++++ Util/Printer.php | 124 ++ Util/Report.php | 137 ++ Util/Report/Coverage/Factory.php | 358 +++++ Util/Report/Coverage/Node.php | 311 +++++ Util/Report/Coverage/Node/Directory.php | 432 ++++++ Util/Report/Coverage/Node/File.php | 376 +++++ Util/Report/Template/butter.png | Bin 0 -> 150 bytes Util/Report/Template/chameleon.png | Bin 0 -> 150 bytes Util/Report/Template/coverage_directory.htm | 83 ++ Util/Report/Template/coverage_file.htm | 75 + Util/Report/Template/coverage_item.htm | 14 + .../Report/Template/coverage_item_details.htm | 5 + .../Template/coverage_item_details_header.htm | 4 + Util/Report/Template/glass.png | Bin 0 -> 167 bytes Util/Report/Template/scarlet_red.png | Bin 0 -> 150 bytes Util/Report/Template/snow.png | Bin 0 -> 141 bytes Util/Report/Template/style.css | 354 +++++ Util/Report/Template/testsuite.htm | 73 + Util/Report/Template/testsuite_item.htm | 10 + Util/Report/Test/Factory.php | 155 +++ Util/Report/Test/Node.php | 193 +++ Util/Report/Test/Node/Test.php | 163 +++ Util/Report/Test/Node/TestSuite.php | 336 +++++ Util/Skeleton.php | 234 ++++ Util/Skeleton/TestClass.php | 53 + Util/Skeleton/TestMethod.php | 10 + Util/Template.php | 166 +++ Util/Test.php | 145 ++ Util/TestDox/NamePrettifier.php | 176 +++ Util/TestDox/ResultPrinter.php | 330 +++++ Util/TestDox/ResultPrinter/HTML.php | 129 ++ Util/TestDox/ResultPrinter/Text.php | 109 ++ Util/Timer.php | 87 ++ package.xml | 744 ++++++++++ pear-phpunit | 41 + pear-phpunit.bat | 40 + 188 files changed, 29198 insertions(+) create mode 100644 Extensions/ExceptionTestCase.php create mode 100644 Extensions/MockObject/Builder/Identity.php create mode 100644 Extensions/MockObject/Builder/InvocationMocker.php create mode 100644 Extensions/MockObject/Builder/Match.php create mode 100644 Extensions/MockObject/Builder/MethodNameMatch.php create mode 100644 Extensions/MockObject/Builder/Namespace.php create mode 100644 Extensions/MockObject/Builder/ParametersMatch.php create mode 100644 Extensions/MockObject/Builder/Stub.php create mode 100644 Extensions/MockObject/Invocation.php create mode 100644 Extensions/MockObject/InvocationMocker.php create mode 100644 Extensions/MockObject/Invokable.php create mode 100644 Extensions/MockObject/Matcher.php create mode 100644 Extensions/MockObject/Matcher/AnyParameters.php create mode 100644 Extensions/MockObject/Matcher/Invocation.php create mode 100644 Extensions/MockObject/Matcher/InvokedAtIndex.php create mode 100644 Extensions/MockObject/Matcher/InvokedAtLeastOnce.php create mode 100644 Extensions/MockObject/Matcher/InvokedCount.php create mode 100644 Extensions/MockObject/Matcher/InvokedRecorder.php create mode 100644 Extensions/MockObject/Matcher/MethodName.php create mode 100644 Extensions/MockObject/Matcher/Parameters.php create mode 100644 Extensions/MockObject/Matcher/StatelessInvocation.php create mode 100644 Extensions/MockObject/Mock.php create mode 100644 Extensions/MockObject/MockObject.php create mode 100644 Extensions/MockObject/Stub.php create mode 100644 Extensions/MockObject/Stub/ConsecutiveCalls.php create mode 100644 Extensions/MockObject/Stub/MatcherCollection.php create mode 100644 Extensions/MockObject/Stub/Return.php create mode 100644 Extensions/MockObject/Verifiable.php create mode 100644 Extensions/OutputTestCase.php create mode 100644 Extensions/PerformanceTestCase.php create mode 100644 Extensions/RepeatedTest.php create mode 100644 Extensions/TestDecorator.php create mode 100644 Extensions/TestSetup.php create mode 100644 Framework.php create mode 100644 Framework/Assert.php create mode 100644 Framework/AssertionFailedError.php create mode 100644 Framework/ComparisonFailure.php create mode 100644 Framework/ComparisonFailure/Array.php create mode 100644 Framework/ComparisonFailure/Object.php create mode 100644 Framework/ComparisonFailure/Scalar.php create mode 100644 Framework/ComparisonFailure/String.php create mode 100644 Framework/ComparisonFailure/Type.php create mode 100644 Framework/Constraint.php create mode 100644 Framework/Constraint/And.php create mode 100644 Framework/Constraint/ArrayHasKey.php create mode 100644 Framework/Constraint/FileExists.php create mode 100644 Framework/Constraint/GreaterThan.php create mode 100644 Framework/Constraint/IsAnything.php create mode 100644 Framework/Constraint/IsEqual.php create mode 100644 Framework/Constraint/IsIdentical.php create mode 100644 Framework/Constraint/IsInstanceOf.php create mode 100644 Framework/Constraint/IsType.php create mode 100644 Framework/Constraint/LessThan.php create mode 100644 Framework/Constraint/Not.php create mode 100644 Framework/Constraint/ObjectHasAttribute.php create mode 100644 Framework/Constraint/Or.php create mode 100644 Framework/Constraint/PCREMatch.php create mode 100644 Framework/Constraint/StringContains.php create mode 100644 Framework/Constraint/TraversableContains.php create mode 100644 Framework/Error.php create mode 100644 Framework/ExpectationFailedException.php create mode 100644 Framework/IncompleteTest.php create mode 100644 Framework/IncompleteTestError.php create mode 100644 Framework/SelfDescribing.php create mode 100644 Framework/SkippedTest.php create mode 100644 Framework/SkippedTestError.php create mode 100644 Framework/Test.php create mode 100644 Framework/TestCase.php create mode 100644 Framework/TestFailure.php create mode 100644 Framework/TestListener.php create mode 100644 Framework/TestResult.php create mode 100644 Framework/TestSuite.php create mode 100644 Framework/Warning.php create mode 100644 Runner/BaseTestRunner.php create mode 100644 Runner/IncludePathTestCollector.php create mode 100644 Runner/StandardTestSuiteLoader.php create mode 100644 Runner/TestCollector.php create mode 100644 Runner/TestFilterIterator.php create mode 100644 Runner/TestSuiteLoader.php create mode 100644 Runner/Version.php create mode 100644 Samples/BankAccount/.cvsignore create mode 100644 Samples/BankAccount/BankAccount.php create mode 100644 Samples/BankAccount/BankAccountTest.php create mode 100644 Samples/Money/.cvsignore create mode 100644 Samples/Money/IMoney.php create mode 100644 Samples/Money/Money.php create mode 100644 Samples/Money/MoneyBag.php create mode 100644 Samples/Money/MoneyTest.php create mode 100644 Tests/AllTests.php create mode 100644 Tests/Extensions/AllTests.php create mode 100644 Tests/Extensions/ExceptionTestCaseTest.php create mode 100644 Tests/Extensions/ExtensionTest.php create mode 100644 Tests/Extensions/MockObjectTest.php create mode 100644 Tests/Extensions/OutputTestCaseTest.php create mode 100644 Tests/Extensions/PerformanceTestCaseTest.php create mode 100644 Tests/Extensions/RepeatedTestTest.php create mode 100644 Tests/Framework/AllTests.php create mode 100644 Tests/Framework/AssertTest.php create mode 100644 Tests/Framework/ComparisonFailureTest.php create mode 100644 Tests/Framework/SuiteTest.php create mode 100644 Tests/Framework/TestCaseTest.php create mode 100644 Tests/Framework/TestImplementorTest.php create mode 100644 Tests/Framework/TestListenerTest.php create mode 100644 Tests/Runner/AllTests.php create mode 100644 Tests/Runner/BaseTestRunnerTest.php create mode 100644 Tests/Util/AllTests.php create mode 100644 Tests/Util/TestDox/AllTests.php create mode 100644 Tests/Util/TestDox/NamePrettifierTest.php create mode 100644 Tests/_files/AnInterface.php create mode 100644 Tests/_files/ClassWithNonPublicAttributes.php create mode 100644 Tests/_files/DoubleTestCase.php create mode 100644 Tests/_files/Error.php create mode 100644 Tests/_files/Failure.php create mode 100644 Tests/_files/InheritedTestCase.php create mode 100644 Tests/_files/MockRunner.php create mode 100644 Tests/_files/NoArgTestCaseTest.php create mode 100644 Tests/_files/NoTestCaseClass.php create mode 100644 Tests/_files/NoTestCases.php create mode 100644 Tests/_files/NonStatic.php create mode 100644 Tests/_files/NotPublicTestCase.php create mode 100644 Tests/_files/NotVoidTestCase.php create mode 100644 Tests/_files/OneTestCase.php create mode 100644 Tests/_files/OutputTestCase.php create mode 100644 Tests/_files/OverrideTestCase.php create mode 100644 Tests/_files/SampleClass.php create mode 100644 Tests/_files/SetupFailure.php create mode 100644 Tests/_files/Sleep.php create mode 100644 Tests/_files/Success.php create mode 100644 Tests/_files/TearDownFailure.php create mode 100644 Tests/_files/TestIterator.php create mode 100644 Tests/_files/ThrowExceptionTestCase.php create mode 100644 Tests/_files/ThrowNoExceptionTestCase.php create mode 100644 Tests/_files/TornDown.php create mode 100644 Tests/_files/TornDown2.php create mode 100644 Tests/_files/TornDown3.php create mode 100644 Tests/_files/TornDown4.php create mode 100644 Tests/_files/TornDown5.php create mode 100644 Tests/_files/TornDown6.php create mode 100644 Tests/_files/WasRun.php create mode 100644 TextUI/ResultPrinter.php create mode 100644 TextUI/TestRunner.php create mode 100644 Util/Array.php create mode 100644 Util/ErrorHandler.php create mode 100644 Util/Fileloader.php create mode 100644 Util/Filesystem.php create mode 100644 Util/Filter.php create mode 100644 Util/Getopt.php create mode 100644 Util/Log/Eclipse.php create mode 100644 Util/Log/GraphViz.php create mode 100644 Util/Log/PEAR.php create mode 100644 Util/Log/TAP.php create mode 100644 Util/Log/XML.php create mode 100644 Util/Printer.php create mode 100644 Util/Report.php create mode 100644 Util/Report/Coverage/Factory.php create mode 100644 Util/Report/Coverage/Node.php create mode 100644 Util/Report/Coverage/Node/Directory.php create mode 100644 Util/Report/Coverage/Node/File.php create mode 100644 Util/Report/Template/butter.png create mode 100644 Util/Report/Template/chameleon.png create mode 100644 Util/Report/Template/coverage_directory.htm create mode 100644 Util/Report/Template/coverage_file.htm create mode 100644 Util/Report/Template/coverage_item.htm create mode 100644 Util/Report/Template/coverage_item_details.htm create mode 100644 Util/Report/Template/coverage_item_details_header.htm create mode 100644 Util/Report/Template/glass.png create mode 100644 Util/Report/Template/scarlet_red.png create mode 100644 Util/Report/Template/snow.png create mode 100644 Util/Report/Template/style.css create mode 100644 Util/Report/Template/testsuite.htm create mode 100644 Util/Report/Template/testsuite_item.htm create mode 100644 Util/Report/Test/Factory.php create mode 100644 Util/Report/Test/Node.php create mode 100644 Util/Report/Test/Node/Test.php create mode 100644 Util/Report/Test/Node/TestSuite.php create mode 100644 Util/Skeleton.php create mode 100644 Util/Skeleton/TestClass.php create mode 100644 Util/Skeleton/TestMethod.php create mode 100644 Util/Template.php create mode 100644 Util/Test.php create mode 100644 Util/TestDox/NamePrettifier.php create mode 100644 Util/TestDox/ResultPrinter.php create mode 100644 Util/TestDox/ResultPrinter/HTML.php create mode 100644 Util/TestDox/ResultPrinter/Text.php create mode 100644 Util/Timer.php create mode 100644 package.xml create mode 100644 pear-phpunit create mode 100755 pear-phpunit.bat diff --git a/Extensions/ExceptionTestCase.php b/Extensions/ExceptionTestCase.php new file mode 100644 index 00000000000..88271406111 --- /dev/null +++ b/Extensions/ExceptionTestCase.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * 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 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: + */ +?> diff --git a/Extensions/MockObject/Builder/Identity.php b/Extensions/MockObject/Builder/Identity.php new file mode 100644 index 00000000000..3e0574f3f70 --- /dev/null +++ b/Extensions/MockObject/Builder/Identity.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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Builder interface for unique identifiers. + * + * Defines the interface for recording unique identifiers. The identifiers + * can be used to define the invocation order of expectations. The expectation + * is recorded using id() and then defined in order using + * PHPUnit2_Extensions_MockObject_Builder_Match::after(). + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +interface PHPUnit2_Extensions_MockObject_Builder_Identity +{ + /** + * Sets the identification of the expectation to $id. + * + * @note The identifier is unique per mock object. + * @param string $id Unique identifiation of expectation. + */ + public function id($id); +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/MockObject/Builder/InvocationMocker.php b/Extensions/MockObject/Builder/InvocationMocker.php new file mode 100644 index 00000000000..2bdfa63acc8 --- /dev/null +++ b/Extensions/MockObject/Builder/InvocationMocker.php @@ -0,0 +1,167 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Extensions/MockObject/Builder/MethodNameMatch.php'; +require_once 'PHPUnit2/Extensions/MockObject/Matcher.php'; +require_once 'PHPUnit2/Extensions/MockObject/Stub.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Builder for mocked or stubbed invocations. + * + * Provides methods for building expectations without having to resort to + * instantiating the various matchers manually. These methods also form a + * more natural way of reading the expectation. This class should be together + * with the test case PHPUnit2_Extensions_MockObject_TestCase. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +class PHPUnit2_Extensions_MockObject_Builder_InvocationMocker implements PHPUnit2_Extensions_MockObject_Builder_MethodNameMatch +{ + private $collection; + + private $matcher; + + public function __construct(PHPUnit2_Extensions_MockObject_Stub_MatcherCollection $collection, PHPUnit2_Extensions_MockObject_Matcher_Invocation $invocationMatcher) + { + $this->collection = $collection; + $this->matcher = new PHPUnit2_Extensions_MockObject_Matcher($invocationMatcher); + + $this->collection->addMatcher($this->matcher); + } + + public function getMatcher() + { + return $this->matcher; + } + + public function id($id) + { + $this->collection->registerId($id, $this); + + return $this; + } + + public function will(PHPUnit2_Extensions_MockObject_Stub $stub) + { + $this->matcher->stub = $stub; + + return $this; + } + + public function after($id) + { + $this->matcher->afterMatchBuilderId = $id; + + return $this; + } + + public function with() + { + $args = func_get_args(); + + if ($this->matcher->methodNameMatcher === NULL) { + throw new RuntimeException('Method name matcher is not defined, cannot define parameter matcher without one'); + } + + if ( $this->matcher->parametersMatcher !== NULL) { + throw new RuntimeException('Parameter matcher is already defined, cannot redefine'); + } + + $this->matcher->parametersMatcher = new PHPUnit2_Extensions_MockObject_Matcher_Parameters($args); + + return $this; + } + + public function withAnyParameters() + { + if ($this->matcher->methodNameMatcher === NULL) { + throw new RuntimeException('Method name matcher is not defined, cannot define parameter matcher without one'); + } + + if ($this->matcher->parametersMatcher !== NULL) { + throw new RuntimeException('Parameter matcher is already defined, cannot redefine'); + } + + $this->matcher->parametersMatcher = new PHPUnit2_Extensions_MockObject_Matcher_AnyParameters(); + + return $this; + } + + public function method($constraint) + { + if ($this->matcher->methodNameMatcher !== NULL) { + throw new RuntimeException('Method name matcher is already defined, cannot redefine'); + } + + $this->matcher->methodNameMatcher = new PHPUnit2_Extensions_MockObject_Matcher_MethodName($constraint); + + return $this; + } + +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/MockObject/Builder/Match.php b/Extensions/MockObject/Builder/Match.php new file mode 100644 index 00000000000..e1fbd25f6c9 --- /dev/null +++ b/Extensions/MockObject/Builder/Match.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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Extensions/MockObject/Builder/Stub.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Builder interface for invocation order matches. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +interface PHPUnit2_Extensions_MockObject_Builder_Match extends PHPUnit2_Extensions_MockObject_Builder_Stub +{ + /** + * Defines the expectation which must occur before the current is valid. + * + * @param string $id The identification of the expectation that should + * occur before this one. + * @return PHPUnit2_Extensions_MockObject_Builder_Stub + */ + public function after($id); +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/MockObject/Builder/MethodNameMatch.php b/Extensions/MockObject/Builder/MethodNameMatch.php new file mode 100644 index 00000000000..3905404a72a --- /dev/null +++ b/Extensions/MockObject/Builder/MethodNameMatch.php @@ -0,0 +1,89 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Extensions/MockObject/Builder/ParametersMatch.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Builder interface for matcher of method names. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +interface PHPUnit2_Extensions_MockObject_Builder_MethodNameMatch extends PHPUnit2_Extensions_MockObject_Builder_ParametersMatch +{ + /** + * Adds a new method name match and returns the parameter match object for + * further matching possibilities. + * + * @param PHPUnit2_Framework_Constraint $name Constraint for matching method, if a + * string is passed it will use the + * PHPUnit2_Framework_Constraint_IsEqual. + * @return PHPUnit2_Extensions_MockObject_Builder_ParametersMatch + */ + public function method($name); +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/MockObject/Builder/Namespace.php b/Extensions/MockObject/Builder/Namespace.php new file mode 100644 index 00000000000..94586801c08 --- /dev/null +++ b/Extensions/MockObject/Builder/Namespace.php @@ -0,0 +1,98 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Extensions/MockObject/Builder/Match.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Interface for builders which can register builders with a given identification. + * + * This interface relates to PHPUnit2_Extensions_MockObject_Builder_Identity. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +interface PHPUnit2_Extensions_MockObject_Builder_Namespace +{ + /** + * Looks up the match builder with identification $id and returns it. + * + * @param string $id The identifiction of the match builder. + * @return PHPUnit2_Extensions_MockObject_Builder_Match + */ + public function lookupId($id); + + /** + * Registers the match builder $builder with the identification $id. The + * builder can later be looked up using lookupId() to figure out if it + * has been invoked. + * + * @param string $id The identification of the match builder. + * @param PHPUnit2_Extensions_MockObject_Builder_Match $builder The builder which is being registered. + */ + public function registerId($id, PHPUnit2_Extensions_MockObject_Builder_Match $builder); +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/MockObject/Builder/ParametersMatch.php b/Extensions/MockObject/Builder/ParametersMatch.php new file mode 100644 index 00000000000..b31d6c437b3 --- /dev/null +++ b/Extensions/MockObject/Builder/ParametersMatch.php @@ -0,0 +1,110 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Extensions/MockObject/Builder/Match.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Builder interface for parameter matchers. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +interface PHPUnit2_Extensions_MockObject_Builder_ParametersMatch extends PHPUnit2_Extensions_MockObject_Builder_Match +{ + /** + * Sets the parameters to match for, each parameter to this funtion will + * be part of match. To perform specific matches or constraints create a + * new PHPUnit2_Framework_Constraint and use it for the parameter. + * If the parameter value is not a constraint it will use the + * PHPUnit2_Framework_Constraint_IsEqual for the value. + * + * Some examples: + * + * // match first parameter with value 2 + * $b->with(2); + * // match first parameter with value 'smock' and second identical to 42 + * $b->with('smock', new PHPUnit2_Framework_Constraint_IsEqual(42)); + * + * + * @return PHPUnit2_Extensions_MockObject_Builder_ParametersMatch + */ + public function with(); + + /** + * Sets a matcher which allows any kind of parameters. + * + * Some examples: + * + * // match any number of parameters + * $b->withAnyParamers(); + * + * + * @return PHPUnit2_Extensions_MockObject_Matcher_AnyParameters + */ + public function withAnyParameters(); +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/MockObject/Builder/Stub.php b/Extensions/MockObject/Builder/Stub.php new file mode 100644 index 00000000000..a5972779ead --- /dev/null +++ b/Extensions/MockObject/Builder/Stub.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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Extensions/MockObject/Builder/Identity.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Builder interface for stubs which are actions replacing an invocation. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +interface PHPUnit2_Extensions_MockObject_Builder_Stub extends PHPUnit2_Extensions_MockObject_Builder_Identity +{ + /** + * Stubs the matching method with the stub object $stub. Any invocations of + * the matched method will now be handled by the stub instead. + * + * @param PHPUnit2_Extensions_MockObject_Stub $stub The stub object. + * @return PHPUnit2_Extensions_MockObject_Builder_Identity + */ + public function will(PHPUnit2_Extensions_MockObject_Stub $stub); +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/MockObject/Invocation.php b/Extensions/MockObject/Invocation.php new file mode 100644 index 00000000000..f129df214af --- /dev/null +++ b/Extensions/MockObject/Invocation.php @@ -0,0 +1,110 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Encapsulates information on a method invocation which can be passed to matchers. + * + * The invocation consists of the object it occured from, the class name, the + * method name and all the parameters. The mock object must instantiate this + * class with the values from the mocked method and pass it to an object of + * PHPUnit2_Extensions_MockObject_Invokable. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +class PHPUnit2_Extensions_MockObject_Invocation implements PHPUnit2_Framework_SelfDescribing +{ + public $object; + + public $className; + + public $methodName; + + public $parameters; + + public function __construct($object, $className, $methodName, $parameters) + { + $this->object = $object; + $this->className = $className; + $this->methodName = $methodName; + $this->parameters = $parameters; + } + + public function toString() + { + return sprintf( + "%s::%s(%s)", + + $this->className, + $this->methodName, + join(', ', array_map(create_function('$a', 'return PHPUnit2_Framework_ComparisonFailure::shortenedExport($a);'), $this->parameters)) + ); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/MockObject/InvocationMocker.php b/Extensions/MockObject/InvocationMocker.php new file mode 100644 index 00000000000..168b3f87088 --- /dev/null +++ b/Extensions/MockObject/InvocationMocker.php @@ -0,0 +1,159 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Extensions/MockObject/Builder/InvocationMocker.php'; +require_once 'PHPUnit2/Extensions/MockObject/Builder/Match.php'; +require_once 'PHPUnit2/Extensions/MockObject/Builder/Namespace.php'; +require_once 'PHPUnit2/Extensions/MockObject/Matcher.php'; +require_once 'PHPUnit2/Extensions/MockObject/Stub.php'; +require_once 'PHPUnit2/Extensions/MockObject/Invocation.php'; +require_once 'PHPUnit2/Extensions/MockObject/Invokable.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Mocker for invocations which are sent from + * PHPUnit2_Extensions_MockObject_MockObject objects. + * + * Keeps track of all expectations and stubs as well as registering + * identifications for builders. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +class PHPUnit2_Extensions_MockObject_InvocationMocker implements PHPUnit2_Extensions_MockObject_Stub_MatcherCollection, PHPUnit2_Extensions_MockObject_Invokable, PHPUnit2_Extensions_MockObject_Builder_Namespace +{ + private $matchers = array(); + + private $builderMap = array(); + + public function addMatcher(PHPUnit2_Extensions_MockObject_Matcher_Invocation $matcher) + { + $this->matchers[] = $matcher; + } + + public function lookupId($id) + { + if (isset($this->builderMap[$id])) { + return $this->builderMap[$id]; + } + + return NULL; + } + + public function registerId($id, PHPUnit2_Extensions_MockObject_Builder_Match $builder) + { + if (isset($this->builderMap[$id])) { + throw new RuntimeException("Match builder with id <{$id}> is already registered."); + } + + $this->builderMap[$id] = $builder; + } + + public function expects(PHPUnit2_Extensions_MockObject_Matcher_Invocation $matcher) + { + $builder = new PHPUnit2_Extensions_MockObject_Builder_InvocationMocker($this, $matcher); + + return $builder; + } + + public function invoke(PHPUnit2_Extensions_MockObject_Invocation $invocation) + { + $hasReturnValue = FALSE; + $returnValue = NULL; + + foreach($this->matchers as $match) { + if ($match->matches($invocation)) { + $value = $match->invoked($invocation); + + if (!$hasReturnValue) { + $returnValue = $value; + $hasReturnValue = TRUE; + } + } + } + + return $returnValue; + } + + public function matches(PHPUnit2_Extensions_MockObject_Invocation $invocation) + { + foreach($this->matchers as $matcher) { + if (!$matcher->matches($invocation)) { + return FALSE; + } + } + + return TRUE; + } + + public function verify() + { + foreach($this->matchers as $matcher) { + $matcher->verify(); + } + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/MockObject/Invokable.php b/Extensions/MockObject/Invokable.php new file mode 100644 index 00000000000..16a286710c1 --- /dev/null +++ b/Extensions/MockObject/Invokable.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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Extensions/MockObject/Invocation.php'; +require_once 'PHPUnit2/Extensions/MockObject/Verifiable.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Interface for classes which can be invoked. + * + * The invocation will be taken from a mock object and passed to an object + * of this class. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +interface PHPUnit2_Extensions_MockObject_Invokable extends PHPUnit2_Extensions_MockObject_Verifiable +{ + /** + * Invokes the invocation object $invocation so that it can be checked for + * expectations or matched against stubs. + * + * @return Object + * @param PHPUnit2_Extensions_MockObject_Invocation $invocation The invocation object passed from + * mock object. + */ + public function invoke(PHPUnit2_Extensions_MockObject_Invocation $invocation); + + /** + * Checks if the invocation matches. + * + * @return bool + * @param PHPUnit2_Extensions_MockObject_Invocation $invocation The invocation object passed from + * mock object. + */ + public function matches(PHPUnit2_Extensions_MockObject_Invocation $invocation); +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/MockObject/Matcher.php b/Extensions/MockObject/Matcher.php new file mode 100644 index 00000000000..10249ac5a88 --- /dev/null +++ b/Extensions/MockObject/Matcher.php @@ -0,0 +1,294 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Extensions/MockObject/Matcher/Invocation.php'; +require_once 'PHPUnit2/Extensions/MockObject/Invocation.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Main matcher which defines a full expectation using method, parameter and invocation matchers. + * + * This matcher encapsulates all the other matchers and allows the builder to set + * the specific matchers when the appropriate methods are called (once(), where() + * etc.). + * + * All properties are public so that they can easily be accessed by the builder. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +class PHPUnit2_Extensions_MockObject_Matcher implements PHPUnit2_Extensions_MockObject_Matcher_Invocation +{ + public $invocationMatcher; + + public $afterMatchBuilderId = NULL; + + public $afterMatchBuilderIsInvoked = FALSE; + + public $methodNameMatcher = NULL; + + public $parametersMatcher = NULL; + + public $stub = NULL; + + public function __construct(PHPUnit2_Extensions_MockObject_Matcher_Invocation $invocationMatcher) + { + $this->invocationMatcher = $invocationMatcher; + } + + public function toString() + { + $list = array(); + + if ($this->invocationMatcher !== NULL) { + $list[] = $this->invocationMatcher->toString(); + } + + if ($this->methodNameMatcher !== NULL) { + $list[] = 'where ' . $this->methodNameMatcher->toString(); + } + + if ($this->parametersMatcher !== NULL) { + $list[] = 'and ' . $this->parametersMatcher->toString(); + } + + if ($this->afterMatchBuilderId !== NULL) { + $list[] = 'after ' . $this->afterMatchBuilderId; + } + + if ($this->stub !== NULL) { + $list[] = 'will ' . $this->stub->toString(); + } + + return join(' ', $list); + } + + public function invoked(PHPUnit2_Extensions_MockObject_Invocation $invocation) + { + if ($this->invocationMatcher === NULL) { + throw new RuntimeException('No invocation matcher is set'); + } + + if ($this->methodNameMatcher === NULL) { + throw new RuntimeException('No method matcher is set'); + } + + if ($this->afterMatchBuilderId !== NULL) { + $builder = $invocation->object->getInvocationMocker()->lookupId($this->afterMatchBuilderId); + + if (!$builder) { + throw new RuntimeException( + sprintf( + 'No builder found for match builder identification <%s>', + + $this->afterMatchBuilderId + ) + ); + } + + $matcher = $builder->getMatcher(); + + if ($matcher && $matcher->invocationMatcher->hasBeenInvoked()) { + $this->afterMatchBuilderIsInvoked = TRUE; + } + } + + $this->invocationMatcher->invoked($invocation); + + try { + if ( $this->parametersMatcher !== NULL && + !$this->parametersMatcher->matches($invocation)) { + $this->parametersMatcher->verify(); + } + } + + catch (PHPUnit2_Framework_ExpectationFailedException $e) { + throw new PHPUnit2_Framework_ExpectationFailedException( + sprintf( + "Expectation failed for %s when %s\n%s", + + $this->methodNameMatcher->toString(), + $this->invocationMatcher->toString(), + $e->getDescription() + ), + $e->getComparisonFailure() + ); + } + + if ($this->stub) { + return $this->stub->invoke($invocation); + } + + return NULL; + } + + public function matches(PHPUnit2_Extensions_MockObject_Invocation $invocation) + { + if ($this->afterMatchBuilderId !== NULL) { + $builder = $invocation->object->getInvocationMocker()->lookupId($this->afterMatchBuilderId); + + if (!$builder) { + throw new RuntimeException( + sprintf( + 'No builder found for match builder identification <%s>', + + $this->afterMatchBuilderId + ) + ); + } + + $matcher = $builder->getMatcher(); + + if (!$matcher) { + return FALSE; + } + + if (!$matcher->invocationMatcher->hasBeenInvoked()) { + return FALSE; + } + } + + if ($this->invocationMatcher === NULL) { + throw new RuntimeException('No invocation matcher is set'); + } + + if ($this->methodNameMatcher === NULL) { + throw new RuntimeException('No method matcher is set'); + } + + if (!$this->invocationMatcher->matches($invocation)) { + return FALSE; + } + + try { + if (!$this->methodNameMatcher->matches($invocation)) { + return FALSE; + } + } + + catch (PHPUnit2_Framework_ExpectationFailedException $e) { + throw new PHPUnit2_Framework_ExpectationFailedException( + sprintf( + "Expectation failed for %s when %s\n%s", + + $this->methodNameMatcher->toString(), + $this->invocationMatcher->toString(), + $e->getDescription() + ), + $e->getComparisonFailure() + ); + } + + return TRUE; + } + + public function verify() + { + if ($this->stub !== NULL) { + return; + } + + if ($this->invocationMatcher === NULL) { + throw new RuntimeException('No invocation matcher is set'); + } + + if ($this->methodNameMatcher === NULL) { + throw new RuntimeException('No method matcher is set'); + } + + $this->invocationMatcher->verify(); + + try { + if ($this->parametersMatcher !== NULL) { + $this->parametersMatcher->verify(); + } + } + + catch (PHPUnit2_Framework_ExpectationFailedException $e) { + throw new PHPUnit2_Framework_ExpectationFailedException( + sprintf( + "Expectation failed for %s when %s\n%s", + + $this->methodNameMatcher->toString(), + $this->invocationMatcher->toString(), + $e->getDescription() + ), + $e->getComparisonFailure() + ); + } + } +} + +require_once 'PHPUnit2/Extensions/MockObject/Matcher/AnyParameters.php'; +require_once 'PHPUnit2/Extensions/MockObject/Matcher/InvokedAtIndex.php'; +require_once 'PHPUnit2/Extensions/MockObject/Matcher/InvokedAtLeastOnce.php'; +require_once 'PHPUnit2/Extensions/MockObject/Matcher/InvokedCount.php'; +require_once 'PHPUnit2/Extensions/MockObject/Matcher/InvokedRecorder.php'; +require_once 'PHPUnit2/Extensions/MockObject/Matcher/MethodName.php'; +require_once 'PHPUnit2/Extensions/MockObject/Matcher/Parameters.php'; +require_once 'PHPUnit2/Extensions/MockObject/Matcher/StatelessInvocation.php'; + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/MockObject/Matcher/AnyParameters.php b/Extensions/MockObject/Matcher/AnyParameters.php new file mode 100644 index 00000000000..a71af25565a --- /dev/null +++ b/Extensions/MockObject/Matcher/AnyParameters.php @@ -0,0 +1,89 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Extensions/MockObject/Matcher/StatelessInvocation.php'; +require_once 'PHPUnit2/Extensions/MockObject/Invocation.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Invocation matcher which allos any parameters to a method. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +class PHPUnit2_Extensions_MockObject_Matcher_AnyParameters extends PHPUnit2_Extensions_MockObject_Matcher_StatelessInvocation +{ + public function toString() + { + return 'with any parameters'; + } + + public function matches(PHPUnit2_Extensions_MockObject_Invocation $invocation) + { + return TRUE; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/MockObject/Matcher/Invocation.php b/Extensions/MockObject/Matcher/Invocation.php new file mode 100644 index 00000000000..55c36fd7356 --- /dev/null +++ b/Extensions/MockObject/Matcher/Invocation.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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Extensions/MockObject/Invocation.php'; +require_once 'PHPUnit2/Extensions/MockObject/Verifiable.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Interface for classes which matches an invocation based on its + * method name, argument, order or call count. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +interface PHPUnit2_Extensions_MockObject_Matcher_Invocation extends PHPUnit2_Framework_SelfDescribing, PHPUnit2_Extensions_MockObject_Verifiable +{ + /** + * Registers the invocation $invocation in the object as being invoked. + * This will only occur after matches() returns true which means the + * current invocation is the correct one. + * + * The matcher can store information from the invocation which can later + * be checked in verify(), or it can check the values directly and throw + * and exception if an expectation is not met. + * + * If the matcher is a stub it will also have a return value. + * + * @param PHPUnit2_Extensions_MockObject_Invocation Object containing information on a mocked or + * stubbed method which was invoked. + * @return mixed + */ + public function invoked(PHPUnit2_Extensions_MockObject_Invocation $invocation); + + /** + * Checks if the invocation $invocation matches the current rules. If it does + * the matcher will get the invoked() method called which should check if an + * expectation is met. + * + * @param PHPUnit2_Extensions_MockObject_Invocation Object containing information on a mocked or + * stubbed method which was invoked. + * @return bool + */ + public function matches(PHPUnit2_Extensions_MockObject_Invocation $invocation); +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/MockObject/Matcher/InvokedAtIndex.php b/Extensions/MockObject/Matcher/InvokedAtIndex.php new file mode 100644 index 00000000000..6d11c166eda --- /dev/null +++ b/Extensions/MockObject/Matcher/InvokedAtIndex.php @@ -0,0 +1,126 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Extensions/MockObject/Matcher/Invocation.php'; +require_once 'PHPUnit2/Extensions/MockObject/Invocation.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Invocation matcher which checks if a method was invoked at a certain index. + * + * If the expected index number does not match the current invocation index it + * will not match which means it skips all method and parameter matching. Only + * once the index is reached will the method and parameter start matching and + * verifying. + * + * If the index is never reached it will throw an exception in index. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +class PHPUnit2_Extensions_MockObject_Matcher_InvokedAtIndex implements PHPUnit2_Extensions_MockObject_Matcher_Invocation +{ + private $sequenceIndex; + + private $currentIndex = -1; + + public function __construct($sequenceIndex) + { + $this->sequenceIndex = $sequenceIndex; + } + + public function toString() + { + return 'invoked at sequence index ' . $this->sequenceIndex; + } + + public function matches(PHPUnit2_Extensions_MockObject_Invocation $invocation) + { + ++$this->currentIndex; + + return $this->currentIndex == $this->sequenceIndex; + } + + public function invoked(PHPUnit2_Extensions_MockObject_Invocation $invocation) + { + } + + public function verify() + { + if ($this->currentIndex < $this->sequenceIndex) { + throw new PHPUnit2_Framework_ExpectationFailedException( + sprintf( + 'The expected invocation at index %s was never reached.', + + $this->sequenceIndex + ), + new PHPUnit2_Framework_ComparisonFailure_Scalar($this->sequenceIndex, $this->currentIndex) + ); + } + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/MockObject/Matcher/InvokedAtLeastOnce.php b/Extensions/MockObject/Matcher/InvokedAtLeastOnce.php new file mode 100644 index 00000000000..6dd7ae0382a --- /dev/null +++ b/Extensions/MockObject/Matcher/InvokedAtLeastOnce.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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Extensions/MockObject/Matcher/InvokedRecorder.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Invocation matcher which checks if a method has been invoked at least one time. + * + * If the number of invocations is 0 it will throw an exception in verify. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +class PHPUnit2_Extensions_MockObject_Matcher_InvokedAtLeastOnce extends PHPUnit2_Extensions_MockObject_Matcher_InvokedRecorder +{ + public function toString() + { + return 'invoke at least once'; + } + + public function verify() + { + $count = $this->getInvocationCount(); + + if ($count < 1) { + throw new PHPUnit2_Framework_ExpectationFailedException( + 'Expected invocation at least once but it never occured.' + ); + } + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/MockObject/Matcher/InvokedCount.php b/Extensions/MockObject/Matcher/InvokedCount.php new file mode 100644 index 00000000000..1ba288e1f56 --- /dev/null +++ b/Extensions/MockObject/Matcher/InvokedCount.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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Extensions/MockObject/Matcher/InvokedRecorder.php'; +require_once 'PHPUnit2/Extensions/MockObject/Invocation.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Invocation matcher which checks if a method has been invoked a certain amount of times. + * + * If the number of invocations exceeds the value it will immediately throw an exception, + * If the number is less it will later be checked in verify() and also throw an exception. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +class PHPUnit2_Extensions_MockObject_Matcher_InvokedCount extends PHPUnit2_Extensions_MockObject_Matcher_InvokedRecorder +{ + private $expectedCount; + + public function __construct($expectedCount) + { + $this->expectedCount = $expectedCount; + } + + public function toString() + { + return 'invoked ' . $this->expectedCount . ' time(s)'; + } + + public function invoked(PHPUnit2_Extensions_MockObject_Invocation $invocation) + { + parent::invoked($invocation); + + $count = $this->getInvocationCount(); + + if ($count > $this->expectedCount) { + throw new PHPUnit2_Framework_ExpectationFailedException( + sprintf( + 'Expected count for invocation <%s> is wrong.', + + $invocation->toString() + ), + new PHPUnit2_Framework_ComparisonFailure_Scalar($this->expectedCount, $count) + ); + } + } + + public function verify() + { + $count = $this->getInvocationCount(); + + if ($count !== $this->expectedCount) { + throw new PHPUnit2_Framework_ExpectationFailedException( + 'Expected invocation count for is wrong.', + new PHPUnit2_Framework_ComparisonFailure_Scalar($this->expectedCount, $count) + ); + } + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/MockObject/Matcher/InvokedRecorder.php b/Extensions/MockObject/Matcher/InvokedRecorder.php new file mode 100644 index 00000000000..a262b7d5dc1 --- /dev/null +++ b/Extensions/MockObject/Matcher/InvokedRecorder.php @@ -0,0 +1,110 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Extensions/MockObject/Matcher/Invocation.php'; +require_once 'PHPUnit2/Extensions/MockObject/Invocation.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Records invocations and provides convenience methods for checking them later on. + * + * This abstract class can be implemented by matchers which needs to check the + * number of times an invocation has occured. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + * @abstract + */ +abstract class PHPUnit2_Extensions_MockObject_Matcher_InvokedRecorder implements PHPUnit2_Extensions_MockObject_Matcher_Invocation +{ + private $invocations = array(); + + public function getInvocationCount() + { + return count($this->invocations); + } + + public function getInvocations() + { + return $this->invocations; + } + + public function hasBeenInvoked() + { + return count($this->invocations) > 0; + } + + public function invoked(PHPUnit2_Extensions_MockObject_Invocation $invocation) + { + $this->invocations[] = $invocation; + } + + public function matches(PHPUnit2_Extensions_MockObject_Invocation $invocation) + { + return TRUE; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/MockObject/Matcher/MethodName.php b/Extensions/MockObject/Matcher/MethodName.php new file mode 100644 index 00000000000..0cd96e69a2c --- /dev/null +++ b/Extensions/MockObject/Matcher/MethodName.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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Extensions/MockObject/Matcher/StatelessInvocation.php'; +require_once 'PHPUnit2/Extensions/MockObject/Invocation.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Invocation matcher which looks for a specific method name in the invocations. + * + * Checks the method name all incoming invocations, the name is checked against + * the defined constraint $constraint. If the constraint is met it will return + * true in matches(). + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +class PHPUnit2_Extensions_MockObject_Matcher_MethodName extends PHPUnit2_Extensions_MockObject_Matcher_StatelessInvocation +{ + private $constraint; + + public function __construct($constraint) + { + if (!($constraint instanceof PHPUnit2_Framework_Constraint)) { + $constraint = new PHPUnit2_Framework_Constraint_IsEqual($constraint); + } + + $this->constraint = $constraint; + } + + public function toString() + { + return 'method name ' . $this->constraint->toString(); + } + + public function matches(PHPUnit2_Extensions_MockObject_Invocation $invocation) + { + return $this->constraint->evaluate($invocation->methodName); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/MockObject/Matcher/Parameters.php b/Extensions/MockObject/Matcher/Parameters.php new file mode 100644 index 00000000000..8b3aa955af2 --- /dev/null +++ b/Extensions/MockObject/Matcher/Parameters.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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Extensions/MockObject/Matcher/StatelessInvocation.php'; +require_once 'PHPUnit2/Extensions/MockObject/Invocation.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Invocation matcher which looks for specific parameters in the invocations. + * + * Checks the parameters of all incoming invocations, the parameter list is + * checked against the defined constraints in $parameters. If the constraint + * is met it will return true in matches(). + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +class PHPUnit2_Extensions_MockObject_Matcher_Parameters extends PHPUnit2_Extensions_MockObject_Matcher_StatelessInvocation +{ + private $parameters = array(); + + private $invocation; + + public function __construct($parameters) + { + foreach($parameters as $parameter) { + if (!($parameter instanceof PHPUnit2_Framework_Constraint)) { + $parameter = new PHPUnit2_Framework_Constraint_IsEqual($parameter); + } + + $this->parameters[] = $parameter; + } + } + + public function toString() + { + $text = 'with parameter'; + + foreach($this->parameters as $index => $parameter) { + if ($index > 0) { + $text .= ' and'; + } + + $text .= ' ' . $index . ' ' . $parameter->toString(); + } + + return $text; + } + + public function matches(PHPUnit2_Extensions_MockObject_Invocation $invocation) + { + $this->invocation = $invocation; + $this->verify(); + + return count($invocation->parameters) < count($this->parameters); + } + + public function verify() + { + if (count($this->invocation->parameters) < count($this->parameters)) { + throw new PHPUnit2_Framework_ExpectationFailedException( + sprintf( + 'Parameter count for invocation %s is too low.', + + $this->invocation->toString() + ), + new PHPUnit2_Framework_ComparisonFailure_Scalar( + count($this->parameters), + count($this->invocation->parameters) + ) + ); + } + + foreach ($this->parameters as $i => $parameter) { + if (!$parameter->evaluate($this->invocation->parameters[$i])) { + $parameter->fail( + $this->invocation->parameters[$i], + sprintf( + 'Parameter %s for invocation %s does not match expected value.', + + $i, + $this->invocation->toString() + ) + ); + } + } + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/MockObject/Matcher/StatelessInvocation.php b/Extensions/MockObject/Matcher/StatelessInvocation.php new file mode 100644 index 00000000000..bca91fe80c4 --- /dev/null +++ b/Extensions/MockObject/Matcher/StatelessInvocation.php @@ -0,0 +1,91 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Extensions/MockObject/Matcher/Invocation.php'; +require_once 'PHPUnit2/Extensions/MockObject/Invocation.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Invocation matcher which does not care about previous state from earlier invocations. + * + * This abstract class can be implemented by matchers which does not care about + * state but only the current run-time value of the invocation itself. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + * @abstract + */ +abstract class PHPUnit2_Extensions_MockObject_Matcher_StatelessInvocation implements PHPUnit2_Extensions_MockObject_Matcher_Invocation +{ + public function invoked(PHPUnit2_Extensions_MockObject_Invocation $invocation) + { + } + + public function verify() + { + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/MockObject/Mock.php b/Extensions/MockObject/Mock.php new file mode 100644 index 00000000000..553d3a257d6 --- /dev/null +++ b/Extensions/MockObject/Mock.php @@ -0,0 +1,347 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Extensions/MockObject/Matcher.php'; +require_once 'PHPUnit2/Extensions/MockObject/Invocation.php'; +require_once 'PHPUnit2/Extensions/MockObject/MockObject.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Provides generation of mock classes and objects from existing classes. + * + * The mocked class will contain all the methods of the original class but with + * a different implementation which will call the current + * PHPUnit2_Extensions_MockObject_InvocationMocker object, this objects takes + * care of checking expectations and stubs. + * It is also possible to define which methods are mocked by passing an array + * of method names. + * + * The simplest way to define a mock object is to do: + * + * + * PHPUnit2_Extensions_MockObject_Mock::generate('MyClass'); + * $o = new Mock_MyClass; + * + * + * The generate() method returns an object which can be queried. + * + * + * $m = PHPUnit2_Extensions_MockObject::generate('MyClass'); + * $o = new $m->mockClassName; + * print "original class was: . $m->className; + * + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +class PHPUnit2_Extensions_MockObject_Mock +{ + public $mockClassName; + public $className; + public $methods; + + public function __construct($className, Array $methods = array(), $mockClassName = '') + { + $this->mockClassName = $mockClassName; + + if ($this->mockClassName === '') { + do { + $random = substr(md5(microtime()), 0, 8); + } + while (class_exists('Mock_' . $className . '_' . $random, FALSE)); + + $this->mockClassName = 'Mock_' . $className . '_' . $random; + } + + if (empty($methods)) { + $methods = get_class_methods($className); + } + + $this->className = $className; + $this->methods = $methods; + } + + public static function generate($className, Array $methods = array(), $mockClassName = '') + { + $mock = new PHPUnit2_Extensions_MockObject_Mock($className, $methods, $mockClassName); + + if (!class_exists($mock->mockClassName, FALSE)) { + $mock->generateClass(); + } + + return $mock; + } + + protected function generateClass() + { + if (class_exists($this->mockClassName, FALSE)) { + throw new RuntimeException("Mock class <{$this->mockClassName}> already exists, cannot generate"); + } + + try { + $class = new ReflectionClass($this->className); + + if ($class->isFinal()) { + throw new RuntimeException("Class <{$this->className}> is a finalized class, cannot make mock version of it"); + } + + $code = $this->generateClassDefinition($class); + + eval($code); + } + + catch (Exception $e) { + throw new RuntimeException("Failed to generate mock class <{$this->mockClassName}> for class <{$this->className}>, caught an exception:\n" . $e->getMessage()); + } + } + + protected function generateClassDefinition(ReflectionClass $class) + { + $code = 'class '; + + if ($class->isInterface()) { + $code .= "{$this->mockClassName} implements {$this->className}, PHPUnit2_Extensions_MockObject_MockObject {\n"; + } else { + $code .= "{$this->mockClassName} extends {$this->className} implements PHPUnit2_Extensions_MockObject_MockObject {\n"; + } + $code .= $this->generateMockApi($class); + + foreach($class->getMethods() as $method) { + if (!$this->canMockMethod($method)) { + continue; + } + + if (!$this->shouldMockMethod($method)) { + continue; + } + + $code .= $this->generateMethodDefinition($method); + } + + $code .= "}\n"; + + return $code; + } + + protected function canMockMethod(ReflectionMethod $method) + { + if ($method->isConstructor() || $method->isDestructor()) { + return FALSE; + } + + if (substr($method->getName(), 0, 2) == '__') { + return FALSE; + } + + return TRUE; + } + + protected function shouldMockMethod(ReflectionMethod $method) + { + return in_array($method->getName(), $this->methods); + } + + protected function generateMethodDefinition(ReflectionMethod $method) + { + $code = "\n "; + + if ($method->isPrivate()) { + $code .= 'private '; + } + + else if ($method->isProtected()) { + $code .= 'protected '; + } + + else { + $code .= 'public '; + } + + if ($method->isStatic()) { + $code .= 'static '; + } + + $code .= 'function '; + + if ($method->returnsReference()) { + $code .= '&'; + } + + $code .= sprintf( + "%s(%s) {\n" . + " \$args = func_get_args();\n" . + " return \$this->invocationMocker->invoke(new PHPUnit2_Extensions_MockObject_Invocation(\$this, %s, %s, \$args));\n" . + " }\n", + + $method->getName(), + $this->generateMethodParameters($method), + var_export($method->getDeclaringClass()->getName(), TRUE), + var_export($method->getName(), TRUE) + ); + + return $code; + } + + protected function generateMockApi(ReflectionClass $class) + { + return sprintf( + " private \$invocationMocker;\n\n" . + "%s" . + "%s" . + " public function getInvocationMocker() {\n" . + " return \$this->invocationMocker;\n" . + " }\n\n" . + " public function expects(PHPUnit2_Extensions_MockObject_Matcher_Invocation \$matcher) {\n" . + " return \$this->invocationMocker->expects(\$matcher);\n" . + " }\n\n" . + " public function verify() {\n" . + " \$this->invocationMocker->verify();\n" . + " }\n", + + $this->generateConstructorCode($class), + $this->generateCloneCode($class) + ); + } + + protected function generateConstructorCode(ReflectionClass $class) + { + $constructor = $class->getConstructor(); + + if ($constructor) { + return sprintf( + " public function __construct(%s) {\n" . + " \$this->invocationMocker = new PHPUnit2_Extensions_MockObject_InvocationMocker(\$this);\n" . + " parent::%s(%s);\n" . + " }\n\n", + + $this->generateMethodParameters($constructor), + $constructor->getName(), + $this->generateMethodParameters($constructor, TRUE) + ); + } else { + return " public function __construct() {\n" . + " \$this->invocationMocker = new PHPUnit2_Extensions_MockObject_InvocationMocker(\$this);\n" . + " }\n\n"; + } + } + + protected function generateCloneCode(ReflectionClass $class) + { + if ($class->hasMethod('__clone')) { + return " public function __clone() {\n" . + " \$this->invocationMocker = clone \$this->invocationMocker;\n" . + " parent::__clone();\n" . + " }\n\n"; + } else { + return " public function __clone() {\n" . + " \$this->invocationMocker = clone \$this->invocationMocker;\n" . + " }\n\n"; + } + } + + protected function generateMethodParameters(ReflectionMethod $method, $asCall = FALSE) + { + $list = array(); + + foreach($method->getParameters() as $parameter) { + $name = '$' . $parameter->getName(); + + if ($asCall) { + $list[] = $name; + } else { + $typeHint = ''; + + if ($parameter->isArray()) { + $typeHint = 'Array '; + } else { + $class = $parameter->getClass(); + + if ($class) { + $typeHint = $class->getName() . ' '; + } + } + + $default = ''; + + if ($parameter->isDefaultValueAvailable()) { + $value = $parameter->getDefaultValue(); + $default = ' = ' . var_export($value, TRUE); + } + + $ref = ''; + + if ($parameter->isPassedByReference()) { + $ref = '&'; + } + + $list[] = $typeHint . $ref . $name . $default; + } + } + + return join(', ', $list); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/MockObject/MockObject.php b/Extensions/MockObject/MockObject.php new file mode 100644 index 00000000000..f70bd4c926e --- /dev/null +++ b/Extensions/MockObject/MockObject.php @@ -0,0 +1,98 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Extensions/MockObject/Builder/MethodNameMatch.php'; +require_once 'PHPUnit2/Extensions/MockObject/Matcher.php'; +require_once 'PHPUnit2/Extensions/MockObject/InvocationMocker.php'; +require_once 'PHPUnit2/Extensions/MockObject/Verifiable.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Interface for all mock objects which are generated by + * PHPUnit2_Extensions_MockObject_Mock. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +interface PHPUnit2_Extensions_MockObject_MockObject extends PHPUnit2_Extensions_MockObject_Verifiable +{ + /** + * Returns the current invocation mocker which keeps track of expecations + * and stubs. + * @return PHPUnit2_Extensions_MockObject_InvocationMocker + */ + public function getInvocationMocker(); + + /** + * Registers a new expectation in the mock object and returns the match + * object which can be infused with further details. + * + * @param PHPUnit2_Extensions_MockObject_Matcher_Invocation $invocation The invocation handler for the method calls. + * @return PHPUnit2_Extensions_MockObject_Builder_MethodNameMatch + */ + public function expects(PHPUnit2_Extensions_MockObject_Matcher_Invocation $invocation); +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/MockObject/Stub.php b/Extensions/MockObject/Stub.php new file mode 100644 index 00000000000..c39754ebc3e --- /dev/null +++ b/Extensions/MockObject/Stub.php @@ -0,0 +1,96 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Extensions/MockObject/Invocation.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * An object that stubs the process of a normal method for a mock object. + * + * The stub object will replace the code for the stubbed method and return a + * specific value instead of the original value. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +interface PHPUnit2_Extensions_MockObject_Stub extends PHPUnit2_Framework_SelfDescribing +{ + /** + * Fakes the processesing of the invocation $invocation by returning a + * specific value. + * + * @return mixed + * @param PHPUnit2_Extensions_MockObject_Invocation $invocation The invocation which was mocked + * and matched by the current method + * and argument matchers. + */ + public function invoke(PHPUnit2_Extensions_MockObject_Invocation $invocation); +} + +require_once 'PHPUnit2/Extensions/MockObject/Stub/MatcherCollection.php'; +require_once 'PHPUnit2/Extensions/MockObject/Stub/Return.php'; + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/MockObject/Stub/ConsecutiveCalls.php b/Extensions/MockObject/Stub/ConsecutiveCalls.php new file mode 100644 index 00000000000..118989b1220 --- /dev/null +++ b/Extensions/MockObject/Stub/ConsecutiveCalls.php @@ -0,0 +1,107 @@ +. + * 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 Patrick Müller + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Extensions/MockObject/Invocation.php'; +require_once 'PHPUnit2/Extensions/MockObject/Stub.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Stubs a method by returning a user-defined stack of values. + * + * @category Testing + * @package PHPUnit2 + * @author Patrick Müller + * @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 3.0.0 + */ +class PHPUnit2_Extensions_MockObject_Stub_ConsecutiveCalls implements PHPUnit2_Extensions_MockObject_Stub +{ + private $stack; + private $value; + + public function __construct($stack) + { + $this->stack = $stack; + } + + public function invoke(PHPUnit2_Extensions_MockObject_Invocation $invocation) + { + $this->value = array_shift($this->stack); + + if ($this->value instanceof PHPUnit2_Extensions_MockObject_Stub) { + $this->value = $this->value->invoke($invocation); + } + + return $this->value; + } + + public function toString() + { + return sprintf( + 'return the user-specified value <%s>', + + var_export($this->value) + ); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/MockObject/Stub/MatcherCollection.php b/Extensions/MockObject/Stub/MatcherCollection.php new file mode 100644 index 00000000000..c76fd1b731e --- /dev/null +++ b/Extensions/MockObject/Stub/MatcherCollection.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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Extensions/MockObject/Matcher.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Stubs a method by returning a user-defined value. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +interface PHPUnit2_Extensions_MockObject_Stub_MatcherCollection +{ + /** + * Adds a new matcher to the collection which can be used as an expectation + * or a stub. + * + * @param PHPUnit2_Extensions_MockObject_Matcher_Invocation $matcher Matcher for invocations to mock objects. + */ + public function addMatcher(PHPUnit2_Extensions_MockObject_Matcher_Invocation $matcher); +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/MockObject/Stub/Return.php b/Extensions/MockObject/Stub/Return.php new file mode 100644 index 00000000000..cdb2c471f0d --- /dev/null +++ b/Extensions/MockObject/Stub/Return.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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Extensions/MockObject/Invocation.php'; +require_once 'PHPUnit2/Extensions/MockObject/Stub.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Stubs a method by returning a user-defined value. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +class PHPUnit2_Extensions_MockObject_Stub_Return implements PHPUnit2_Extensions_MockObject_Stub +{ + private $value; + + public function __construct($value) + { + $this->value = $value; + } + + public function invoke(PHPUnit2_Extensions_MockObject_Invocation $invocation) + { + return $this->value; + } + + public function toString() + { + return sprintf( + 'return the user-specified value <%s>', + + var_export($this->value) + ); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/MockObject/Verifiable.php b/Extensions/MockObject/Verifiable.php new file mode 100644 index 00000000000..6e54df124e2 --- /dev/null +++ b/Extensions/MockObject/Verifiable.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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Interface for classes which must verify a given expectation. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +interface PHPUnit2_Extensions_MockObject_Verifiable +{ + /** + * Verifies that the current expectation is valid. If everything is OK the + * code should just return, if not it must throw an exception. + * + * @throw PHPUnit2_Framework_ExpectationFailedException + */ + public function verify(); +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Extensions/OutputTestCase.php b/Extensions/OutputTestCase.php new file mode 100644 index 00000000000..97c978d4d94 --- /dev/null +++ b/Extensions/OutputTestCase.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * A TestCase that expects a specified output. + * + * @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 3.0.0 + */ +class PHPUnit2_Extensions_OutputTestCase extends PHPUnit2_Framework_TestCase +{ + /** + * @var string + * @access private + */ + private $expectedRegex = NULL; + + /** + * @var string + * @access private + */ + private $expectedString = NULL; + + /** + * @var string + * @access private + */ + private $output = ''; + + /** + * @return string + * @access public + */ + public function getActualOutput() + { + return $this->output; + } + + /** + * @return string + * @access public + */ + public function expectedRegex() + { + return $this->expectedRegex; + } + + /** + * @param string $expectedRegex + * @access public + */ + public function expectOutputRegex($expectedRegex) + { + if ($this->expectedString !== NULL) { + throw new RuntimeException; + } + + if (is_string($expectedRegex) || is_null($expectedRegex)) { + $this->expectedRegex = $expectedRegex; + } + } + + /** + * @return string + * @access public + */ + public function expectedString() + { + return $this->expectedOutput; + } + + /** + * @param string $expectedString + * @access public + */ + public function expectOutputString($expectedString) + { + if ($this->expectedRegex !== NULL) { + throw new RuntimeException; + } + + if (is_string($expectedString) || is_null($expectedString)) { + $this->expectedString = $expectedString; + } + } + + /** + * @access protected + */ + protected function runTest() + { + ob_start(); + parent::runTest(); + $this->output = ob_get_contents(); + ob_end_clean(); + + if ($this->expectedRegex !== NULL) { + $this->assertRegExp($this->expectedRegex, $this->output); + $this->expectedRegex = NULL; + } + + else if ($this->expectedString !== NULL) { + $this->assertEquals($this->expectedString, $this->output); + $this->expectedString = NULL; + } + } +} + +/* + * 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..9bd813c9bd3 --- /dev/null +++ b/Extensions/PerformanceTestCase.php @@ -0,0 +1,132 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.1.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Util/Timer.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * 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() + { + PHPUnit2_Util_Timer::start(); + parent::runTest(); + $time = PHPUnit2_Util_Timer::stop(); + + if ($this->maxRunningTime != 0 && + $time > $this->maxRunningTime) { + $this->fail( + sprintf( + 'expected running time: <= %s but was: %s', + + $this->maxRunningTime, + $time + ) + ); + } + } + + /** + * @param integer $maxRunningTime + * @throws InvalidArgumentException + * @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 InvalidArgumentException; + } + } + + /** + * @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..8012a85ae14 --- /dev/null +++ b/Extensions/RepeatedTest.php @@ -0,0 +1,139 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Extensions/TestDecorator.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * 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 InvalidArgumentException + * @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 InvalidArgumentException( + '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 count() + { + return $this->timesRepeat * count($this->test); + } + + /** + * Runs the decorated test and collects the + * result in a TestResult. + * + * @param PHPUnit2_Framework_TestResult $result + * @return PHPUnit2_Framework_TestResult + * @throws InvalidArgumentException + * @access public + */ + public function run(PHPUnit2_Framework_TestResult $result = NULL) + { + if ($result === NULL) { + $result = $this->createResult(); + } + + 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..8a72438f59a --- /dev/null +++ b/Extensions/TestDecorator.php @@ -0,0 +1,176 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * 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, PHPUnit2_Framework_SelfDescribing +{ + /** + * 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 count() + { + return count($this->test); + } + + /** + * 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 InvalidArgumentException + * @access public + */ + public function run(PHPUnit2_Framework_TestResult $result = NULL) + { + if ($result === NULL) { + $result = $this->createResult(); + } + + $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..6ec55da8427 --- /dev/null +++ b/Extensions/TestSetup.php @@ -0,0 +1,156 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Extensions/TestDecorator.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * 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 InvalidArgumentException + * @access public + */ + public function run(PHPUnit2_Framework_TestResult $result = NULL) + { + if ($result === NULL) { + $result = $this->createResult(); + } + + $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 $attribute) { + $name = $attribute->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.php b/Framework.php new file mode 100644 index 00000000000..d57d45864ac --- /dev/null +++ b/Framework.php @@ -0,0 +1,79 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +require 'PHPUnit2/Framework/SelfDescribing.php'; +require 'PHPUnit2/Framework/AssertionFailedError.php'; +require 'PHPUnit2/Framework/Assert.php'; +require 'PHPUnit2/Framework/Error.php'; +require 'PHPUnit2/Framework/IncompleteTest.php'; +require 'PHPUnit2/Framework/SkippedTest.php'; +require 'PHPUnit2/Framework/Test.php'; +require 'PHPUnit2/Framework/TestFailure.php'; +require 'PHPUnit2/Framework/TestListener.php'; +require 'PHPUnit2/Framework/TestResult.php'; +require 'PHPUnit2/Framework/ExpectationFailedException.php'; +require 'PHPUnit2/Framework/IncompleteTestError.php'; +require 'PHPUnit2/Framework/SkippedTestError.php'; +require 'PHPUnit2/Framework/TestCase.php'; +require 'PHPUnit2/Framework/TestSuite.php'; +require 'PHPUnit2/Framework/Warning.php'; +require 'PHPUnit2/Framework/Constraint.php'; +require 'PHPUnit2/Framework/ComparisonFailure.php'; + +/* + * 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..f60015d3ec6 --- /dev/null +++ b/Framework/Assert.php @@ -0,0 +1,1095 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Extensions/MockObject/Mock.php'; +require_once 'PHPUnit2/Extensions/MockObject/Matcher/InvokedAtLeastOnce.php'; +require_once 'PHPUnit2/Extensions/MockObject/Matcher/InvokedAtIndex.php'; +require_once 'PHPUnit2/Extensions/MockObject/Matcher/InvokedCount.php'; +require_once 'PHPUnit2/Extensions/MockObject/Stub/ConsecutiveCalls.php'; +require_once 'PHPUnit2/Extensions/MockObject/Stub/Return.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!class_exists('PHPUnit2_Framework_Assert')) { + +/** + * 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 +{ + /** + * Protect constructor since it is a static only class. + * + * @access protected + */ + protected function __construct() + { + } + + /** + * Asserts that an array has a specified key. + * + * @param mixed $key + * @param array $array + * @param string $message + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function assertArrayHasKey($key, Array $array, $message = '') + { + if (!(is_integer($key) || is_string($key))) { + throw new InvalidArgumentException; + } + + $constraint = new PHPUnit2_Framework_Constraint_ArrayHasKey($key); + + if (!$constraint->evaluate($array)) { + self::failConstraint($constraint, $array, $message); + } + } + + /** + * Asserts that an array does not have a specified key. + * + * @param mixed $key + * @param array $array + * @param string $message + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function assertArrayNotHasKey($key, Array $array, $message = '') + { + if (!(is_integer($key) || is_string($key))) { + throw new InvalidArgumentException; + } + + $constraint = new PHPUnit2_Framework_Constraint_Not( + new PHPUnit2_Framework_Constraint_ArrayHasKey($key) + ); + + if (!$constraint->evaluate($array)) { + self::failConstraint($constraint, $array, $message); + } + } + + /** + * 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 = '') + { + if (is_array($haystack) || + is_object($haystack) && $haystack instanceof Iterator) { + $constraint = new PHPUnit2_Framework_Constraint_TraversableContains($needle); + } + + else if (is_string($haystack)) { + $constraint = new PHPUnit2_Framework_Constraint_StringContains($needle); + } + + else { + throw new InvalidArgumentException; + } + + if (!$constraint->evaluate($haystack)) { + self::failConstraint($constraint, $haystack, $message); + } + } + + /** + * Asserts that a haystack that is stored in an attribute of an object + * contains a needle. + * + * @param mixed $needle + * @param string $haystackAttributeName + * @param object $haystackObject + * @param string $message + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function assertAttributeContains($needle, $haystackAttributeName, $haystackObject, $message = '') + { + if (!is_string($haystackAttributeName) || !is_object($haystackObject)) { + throw new InvalidArgumentException; + } + + self::assertContains( + $needle, + self::getAttribute($haystackObject, $haystackAttributeName), + $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 = '') + { + if (is_array($haystack) || + is_object($haystack) && $haystack instanceof Iterator) { + $constraint = new PHPUnit2_Framework_Constraint_Not( + new PHPUnit2_Framework_Constraint_TraversableContains($needle) + ); + } + + else if (is_string($haystack)) { + $constraint = new PHPUnit2_Framework_Constraint_Not( + new PHPUnit2_Framework_Constraint_StringContains($needle) + ); + } + + else { + throw new InvalidArgumentException; + } + + if (!$constraint->evaluate($haystack)) { + self::failConstraint($constraint, $haystack, $message); + } + } + + /** + * Asserts that a haystack that is stored in an attribute of an object + * does not contain a needle. + * + * @param mixed $needle + * @param string $haystackAttributeName + * @param object $haystackObject + * @param string $message + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function assertAttributeNotContains($needle, $haystackAttributeName, $haystackObject, $message = '') + { + if (!is_string($haystackAttributeName) || !is_object($haystackObject)) { + throw new InvalidArgumentException; + } + + self::assertNotContains( + $needle, + self::getAttribute($haystackObject, $haystackAttributeName), + $message + ); + } + + /** + * 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) + { + $constraint = new PHPUnit2_Framework_Constraint_IsEqual($expected, $delta); + + if (!$constraint->evaluate($actual)) { + self::failConstraint($constraint, $actual, $message); + } + } + + /** + * Asserts that a variable is equal to an attribute of an object. + * + * @param mixed $expected + * @param string $actualAttributeName + * @param string $actualObject + * @param string $message + * @param mixed $delta + * @access public + * @static + */ + public static function assertAttributeEquals($expected, $actualAttributeName, $actualObject, $message = '', $delta = 0) + { + if (!is_string($actualAttributeName) || !is_object($actualObject)) { + throw new InvalidArgumentException; + } + + self::assertEquals( + $expected, + self::getAttribute($actualObject, $actualAttributeName), + $message, + $delta + ); + } + + /** + * 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) + { + $constraint = new PHPUnit2_Framework_Constraint_Not( + new PHPUnit2_Framework_Constraint_IsEqual($expected, $delta) + ); + + if (!$constraint->evaluate($actual)) { + self::failConstraint($constraint, $actual, $message); + } + } + + /** + * Asserts that a variable is not equal to an attribute of an object. + * + * @param mixed $expected + * @param string $actualAttributeName + * @param string $actualObject + * @param string $message + * @param mixed $delta + * @access public + * @static + */ + public static function assertAttributeNotEquals($expected, $actualAttributeName, $actualObject, $message = '', $delta = 0) + { + if (!is_string($actualAttributeName) || !is_object($actualObject)) { + throw new InvalidArgumentException; + } + + self::assertNotEquals( + $expected, + self::getAttribute($actualObject, $actualAttributeName), + $message, + $delta + ); + } + + /** + * Asserts that a file exists. + * + * @param string $filename + * @param string $message + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function assertFileExists($filename, $message = '') + { + if (!is_string($filename)) { + throw new InvalidArgumentException; + } + + $constraint = new PHPUnit2_Framework_Constraint_FileExists; + + if (!$constraint->evaluate($filename)) { + self::failConstraint($constraint, $filename, $message); + } + } + + /** + * Asserts that a file does not exist. + * + * @param string $filename + * @param string $message + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function assertFileNotExists($filename, $message = '') + { + if (!is_string($filename)) { + throw new InvalidArgumentException; + } + + $constraint = new PHPUnit2_Framework_Constraint_Not( + new PHPUnit2_Framework_Constraint_FileExists + ); + + if (!$constraint->evaluate($filename)) { + self::failConstraint($constraint, $filename, $message); + } + } + + /** + * Asserts that a condition is true. + * + * @param boolean $condition + * @param string $message + * @throws PHPUnit2_Framework_ComparisonFailure + * @throws InvalidArgumentException + * @access public + * @static + */ + public static function assertTrue($condition, $message = '') + { + if (!is_bool($condition)) { + throw new InvalidArgumentException; + } + + $constraint = new PHPUnit2_Framework_Constraint_IsIdentical(TRUE); + + if (!$constraint->evaluate($condition)) { + self::failConstraint($constraint, $condition, $message, TRUE); + } + } + + /** + * Asserts that a condition is false. + * + * @param boolean $condition + * @param string $message + * @throws PHPUnit2_Framework_ComparisonFailure + * @throws InvalidArgumentException + * @access public + * @static + */ + public static function assertFalse($condition, $message = '') + { + if (!is_bool($condition)) { + throw new InvalidArgumentException; + } + + $constraint = new PHPUnit2_Framework_Constraint_IsIdentical(FALSE); + + if (!$constraint->evaluate($condition)) { + self::failConstraint($constraint, $condition, $message, TRUE); + } + } + + /** + * Asserts that a variable is not NULL. + * + * @param mixed $actual + * @param string $message + * @access public + * @static + */ + public static function assertNotNull($actual, $message = '') + { + $constraint = new PHPUnit2_Framework_Constraint_Not( + new PHPUnit2_Framework_Constraint_IsIdentical(NULL) + ); + + if (!$constraint->evaluate($actual)) { + self::failConstraint($constraint, $actual, $message, TRUE); + } + } + + /** + * Asserts that a variable is NULL. + * + * @param mixed $actual + * @param string $message + * @access public + * @static + */ + public static function assertNull($actual, $message = '') + { + $constraint = new PHPUnit2_Framework_Constraint_IsIdentical(NULL); + + if (!$constraint->evaluate($actual)) { + self::failConstraint($constraint, $actual, $message, TRUE); + } + } + + /** + * Asserts that an object has a specified attribute. + * + * @param string $attributeName + * @param object $object + * @param string $message + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function assertObjectHasAttribute($attributeName, $object, $message = '') + { + if (!is_string($attributeName) || !is_object($object)) { + throw new InvalidArgumentException; + } + + $constraint = new PHPUnit2_Framework_Constraint_ObjectHasAttribute($attributeName); + + if (!$constraint->evaluate($object)) { + self::failConstraint($constraint, $object, $message); + } + } + + /** + * Asserts that an object does not have a specified attribute. + * + * @param string $attributeName + * @param object $object + * @param string $message + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function assertObjectNotHasAttribute($attributeName, $object, $message = '') + { + if (!is_string($attributeName) || !is_object($object)) { + throw new InvalidArgumentException; + } + + $constraint = new PHPUnit2_Framework_Constraint_Not( + new PHPUnit2_Framework_Constraint_ObjectHasAttribute($attributeName) + ); + + if (!$constraint->evaluate($object)) { + self::failConstraint($constraint, $object, $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 = '') + { + $constraint = new PHPUnit2_Framework_Constraint_IsIdentical($expected); + + if (!$constraint->evaluate($actual)) { + self::failConstraint($constraint, $actual, $message, TRUE); + } + } + + /** + * Asserts that a variable and an attribute of an object have the same type + * and value. + * + * @param mixed $expected + * @param string $actualAttributeName + * @param object $actualObject + * @param string $message + * @access public + * @static + */ + public static function assertAttributeSame($expected, $actualAttributeName, $actualObject, $message = '') + { + if (!is_string($actualAttributeName) || !is_object($actualObject)) { + throw new InvalidArgumentException; + } + + self::assertSame( + $expected, + self::getAttribute($actualObject, $actualAttributeName), + $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 = '') + { + $constraint = new PHPUnit2_Framework_Constraint_Not( + new PHPUnit2_Framework_Constraint_IsIdentical($expected) + ); + + if (!$constraint->evaluate($actual)) { + self::failConstraint($constraint, $actual, $message, TRUE); + } + } + + /** + * Asserts that a variable and an attribute of an object have not the same + * type and value. + * + * @param mixed $expected + * @param string $actualAttributeName + * @param object $actualObject + * @param string $message + * @access public + * @static + */ + public static function assertAttributeNotSame($expected, $actualAttributeName, $actualObject, $message = '') + { + if (!is_string($actualAttributeName) || !is_object($actualObject)) { + throw new InvalidArgumentException; + } + + self::assertNotSame( + $expected, + self::getAttribute($actualObject, $actualAttributeName), + $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 = '') + { + if (is_string($expected)) { + if (class_exists($expected) || interface_exists($expected)) { + $constraint = self::logicalAnd( + new PHPUnit2_Framework_Constraint_IsType('object'), + new PHPUnit2_Framework_Constraint_IsInstanceOf($expected) + ); + } else { + $constraint = new PHPUnit2_Framework_Constraint_IsType($expected); + } + } else { + throw new InvalidArgumentException; + } + + if (!$constraint->evaluate($actual)) { + self::failConstraint($constraint, $actual, $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 = '') + { + if (is_string($expected)) { + if (class_exists($expected) || interface_exists($expected)) { + $constraint = new PHPUnit2_Framework_Constraint_Not( + self::logicalAnd( + new PHPUnit2_Framework_Constraint_IsType('object'), + new PHPUnit2_Framework_Constraint_IsInstanceOf($expected) + ) + ); + } else { + $constraint = new PHPUnit2_Framework_Constraint_Not( + new PHPUnit2_Framework_Constraint_IsType($expected) + ); + } + } else { + throw new InvalidArgumentException; + } + + if (!$constraint->evaluate($actual)) { + self::failConstraint($constraint, $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 = '') + { + if (!is_string($pattern) || !is_string($string)) { + throw new InvalidArgumentException; + } + + $constraint = new PHPUnit2_Framework_Constraint_PCREMatch($pattern); + + if (!$constraint->evaluate($string)) { + $constraint->fail( + $string, + sprintf( + '%sfailed asserting that string <%s> %s', + + $message, + var_export($string, TRUE), + $constraint->toString() + ) + ); + } + } + + /** + * 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 = '') + { + if (!is_string($pattern) || !is_string($string)) { + throw new InvalidArgumentException; + } + + $constraint = new PHPUnit2_Framework_Constraint_Not( + new PHPUnit2_Framework_Constraint_PCREMatch($pattern) + ); + + if (!$constraint->evaluate($string)) { + self::failConstraint($constraint, $string, $message); + } + } + + /** + * + * + * @param mixed $value + * @param PHPUnit2_Framework_Constraint $constraint + * @param string $message + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function assertThat($value, PHPUnit2_Framework_Constraint $constraint, $message = '') + { + if (!$constraint->evaluate($value)) { + self::failConstraint($constraint, $value, $message, TRUE); + } + } + + /** + * Logical AND. + * + * @return PHPUnit2_Framework_Constraint_And + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function logicalAnd() + { + $constraints = func_get_args(); + + $constraint = new PHPUnit2_Framework_Constraint_And; + $constraint->setConstraints($constraints); + + return $constraint; + } + + /** + * Logical OR. + * + * @return PHPUnit2_Framework_Constraint_Or + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function logicalOr() + { + $constraints = func_get_args(); + + $constraint = new PHPUnit2_Framework_Constraint_Or; + $constraint->setConstraints($constraints); + + return $constraint; + } + + /** + * Logical NOT. + * + * @param PHPUnit2_Framework_Constraint $constraint + * @return PHPUnit2_Framework_Constraint_Not + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function logicalNot(PHPUnit2_Framework_Constraint $constraint) + { + return new PHPUnit2_Framework_Constraint_Not($constraint); + } + + /** + * + * + * @return PHPUnit2_Framework_Constraint_IsAnything + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function anything() + { + return new PHPUnit2_Framework_Constraint_IsAnything; + } + + /** + * + * + * @param mixed $value + * @return PHPUnit2_Framework_Constraint_TraversableContains + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function arrayContains($value) + { + return new PHPUnit2_Framework_Constraint_TraversableContains($value); + } + + /** + * + * + * @param mixed $key + * @return PHPUnit2_Framework_Constraint_ArrayHasKey + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function arrayHasKey($key) + { + return new PHPUnit2_Framework_Constraint_ArrayHasKey($key); + } + + /** + * + * + * @param mixed $value + * @param mixed $delta + * @return PHPUnit2_Framework_Constraint_IsEqual + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function equalTo($value, $delta = 0) + { + return new PHPUnit2_Framework_Constraint_IsEqual($value, $delta); + } + + /** + * + * + * @return PHPUnit2_Framework_Constraint_FileExists + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function fileExists() + { + return new PHPUnit2_Framework_Constraint_FileExists; + } + + /** + * + * + * @param mixed $value + * @return PHPUnit2_Framework_Constraint_GreaterThan + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function greaterThan($value) + { + return new PHPUnit2_Framework_Constraint_GreaterThan($value); + } + + /** + * + * + * @param string $attributeName + * @return PHPUnit2_Framework_Constraint_ObjectHasAttribute + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function objectHasAttribute($attributeName) + { + return new PHPUnit2_Framework_Constraint_ObjectHasAttribute($attributeName); + } + + /** + * + * + * @param mixed $value + * @return PHPUnit2_Framework_Constraint_IsIdentical + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function identicalTo($value) + { + return new PHPUnit2_Framework_Constraint_IsIdentical($value); + } + + /** + * + * + * @param string $className + * @return PHPUnit2_Framework_Constraint_IsInstanceOf + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function isInstanceOf($className) + { + return new PHPUnit2_Framework_Constraint_IsInstanceOf($className); + } + + /** + * + * + * @param string $type + * @return PHPUnit2_Framework_Constraint_IsType + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function isType($type) + { + return new PHPUnit2_Framework_Constraint_IsType($type); + } + + /** + * + * + * @param mixed $value + * @return PHPUnit2_Framework_Constraint_LessThan + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function lessThan($value) + { + return new PHPUnit2_Framework_Constraint_LessThan($value); + } + + /** + * + * + * @param string $pattern + * @return PHPUnit2_Framework_Constraint_PCREMatch + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function matchesRegularExpression($pattern) + { + return new PHPUnit2_Framework_Constraint_PCREMatch($pattern); + } + + /** + * + * + * @param string $string + * @param boolean $case + * @return PHPUnit2_Framework_Constraint_StringContains + * @access public + * @since Method available since Release 3.0.0 + * @static + */ + public static function stringContains($string, $case) + { + return new PHPUnit2_Framework_Constraint_StringContains($string, $case); + } + + + /** + * 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); + } + + /** + * Fails a test based on a failed constraint. + * + * @param PHPUnit2_Framework_Constraint $constraint + * @param mixed $value + * @param string $message + * @param boolean $type + * @throws PHPUnit2_Framework_ExpectationFailedException + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function failConstraint(PHPUnit2_Framework_Constraint $constraint, $value, $message, $type = FALSE) + { + $constraint->fail( + $value, + sprintf( + '%sfailed asserting that <%s%s> %s', + + $message, + $type ? gettype($value) . ':' : '', + var_export($value, TRUE), + $constraint->toString() + ) + ); + } + + /** + * Returns the value of an object's attribute. + * This also works for attributes that are declared protected or private. + * + * @param object $object + * @param string $attributeName + * @return mixed + * @throws InvalidArgumentException + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function getAttribute($object, $attributeName) + { + if (!is_object($object) || !is_string($attributeName)) { + throw new InvalidArgumentException; + } + + self::assertObjectHasAttribute($attributeName, $object); + + $class = new ReflectionClass($object); + $attribute = $class->getProperty($attributeName); + + if ($attribute->isPublic()) { + return $object->$attributeName; + } else { + if ($attribute->isProtected()) { + $attributeName = "\0*\0" . $attributeName; + } else { + $attributeName = sprintf( + "\0%s\0%s", + + get_class($object), + $attributeName + ); + } + + $tmp = (array) $object; + + return $tmp[$attributeName]; + } + } + + /** + * Mark the test as incomplete. + * + * @param string $message + * @throws PHPUnit2_Framework_IncompleteTestError + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function markTestIncomplete($message = '') + { + throw new PHPUnit2_Framework_IncompleteTestError($message); + } + + /** + * Mark the test as skipped. + * + * @param string $message + * @throws PHPUnit2_Framework_SkippedTestError + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function markTestSkipped($message = '') + { + throw new PHPUnit2_Framework_SkippedTestError($message); + } +} + +} + +/* + * 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..459ff7caed3 --- /dev/null +++ b/Framework/AssertionFailedError.php @@ -0,0 +1,114 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!class_exists('PHPUnit2_Framework_AssertionFailedError')) { + +/** + * 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 implements PHPUnit2_Framework_SelfDescribing +{ + /** + * Returns the location where this failure occured. + * + * @return array + * @access public + * @since Method available since Release 3.0.0 + */ + public function getLocation() + { + foreach ($this->getTrace() as $frame) { + if (!isset($frame['line'])) { + break; + } + + $result = array( + 'file' => $frame['file'], + 'line' => $frame['line'] + ); + } + + return $result; + } + + /** + * 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..8b4cf71413e --- /dev/null +++ b/Framework/ComparisonFailure.php @@ -0,0 +1,278 @@ +. + * 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 Jan Borsodi + * Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!class_exists('PHPUnit2_Framework_ComparisonFailure')) { + +/** + * Thrown when an assertion for string equality failed. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * 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 class PHPUnit2_Framework_ComparisonFailure extends PHPUnit2_Framework_AssertionFailedError +{ + /** + * Expected value of the retrieval which does not match $actual. + * @var mixed + */ + protected $expected; + + /** + * Actually retrieved value which does not match $expected. + * @var mixed + */ + protected $actual; + + /** + * Optional message which is placed in front of the first line + * returned by toString(). + * @var string + */ + protected $message; + + /** + * Initialises with the expected value and the actual value. + * + * @param mixed $expected Expected value retrieved. + * @param mixed $actual Actual value retrieved. + * @param string $message A string which is prefixed on all returned lines + * in the difference output. + */ + public function __construct($expected, $actual, $message = '') + { + $this->expected = $expected; + $this->actual = $actual; + $this->message = $message; + } + + /** + * Figures out which diff class to use for the input types then + * instantiates that class and returns the object. + * @note The diff is type sensitive, if the type differs only the types + * are shown. + * + * @param mixed $expected Expected value retrieved. + * @param mixed $actual Actual value retrieved. + * @param string $message A string which is prefixed on all returned lines + * in the difference output. + * @return PHPUnit2_Framework_ComparisonFailure + */ + public static function diffIdentical($expected, $actual, $message = '') + { + if (gettype($expected) !== gettype($actual)) { + return new PHPUnit2_Framework_ComparisonFailure_Type($expected, $actual, $message); + } + + elseif (is_string($expected)) { + return new PHPUnit2_Framework_ComparisonFailure_String($expected, $actual, $message); + } + + elseif (is_bool($expected) || is_int($expected) || is_float($expected)) { + return new PHPUnit2_Framework_ComparisonFailure_Scalar($expected, $actual, $message); + } + + elseif (is_array($expected)) { + return new PHPUnit2_Framework_ComparisonFailure_Array($expected, $actual, $message); + } + + elseif (is_object($expected)) { + return new PHPUnit2_Framework_ComparisonFailure_Object($expected, $actual, $message); + } + } + + /** + * Figures out which diff class to use for the input types then + * instantiates that class and returns the object. + * @note The diff is not type sensitive, if the type differs the $actual + * value will be converted to the same type as the $expected. + * + * @param mixed $expected Expected value retrieved. + * @param mixed $actual Actual value retrieved. + * @param string $message A string which is prefixed on all returned lines + * in the difference output. + * @return PHPUnit2_Framework_ComparisonFailure + */ + public static function diffEqual($expected, $actual, $message = '') + { + if (gettype($expected) !== gettype($actual)) { + $expected = (string)$expected; + $actual = (string)$actual; + } + + if (is_string($expected)) { + return new PHPUnit2_Framework_ComparisonFailure_String($expected, $actual, $message); + } + + elseif (is_bool($expected) || is_int($expected) || is_float($expected)) { + return new PHPUnit2_Framework_ComparisonFailure_Scalar($expected, $actual, $message); + } + + elseif (is_array($expected)) { + return new PHPUnit2_Framework_ComparisonFailure_Array($expected, $actual, $message); + } + + elseif (is_object($expected)) { + return new PHPUnit2_Framework_ComparisonFailure_Object($expected, $actual, $message); + } + } + + /** + * Exports the value $value to a string but in a shortened form. + * + * @param mixed $value The value to export as string. + * @return string + */ + public static function shortenedExport($value) + { + if (is_string($value)) { + return self::shortenedString($value); + } + + elseif (is_array($value)) { + if (count($value) == 0) { + return 'array()'; + } + + $a1 = array_slice($value, 0, 1, TRUE); + $k1 = key($a1); + $v1 = $a1[$k1]; + + if (is_string($v1)) { + $v1 = self::shortenedString($v1); + } + + elseif (is_array($v1)) { + $v1 = 'array(...)'; + } else { + $v1 = var_export($v1, TRUE); + } + + $a2 = false; + + if (count($value) > 1) { + $a2 = array_slice($value, -1, 1, TRUE); + $k2 = key($a2); + $v2 = $a2[$k2]; + + if (is_string($v2)) { + $v2 = self::shortenedString($v2); + } + + elseif (is_array($v2)) { + $v2 = 'array(...)'; + } else { + $v2 = var_export($v2, TRUE); + } + } + + $text = 'array( ' . var_export($k1, TRUE) . ' => ' . $v1; + + if ($a2 !== FALSE) { + $text .= ', ..., ' . var_export($k2, TRUE) . ' => ' . $v2 . ' )'; + } else { + $text .= ' )'; + } + + return $text; + } + + elseif (is_object($value)) { + return 'class ' . get_class($value) . '(...)'; + } + + return var_export($value, TRUE); + } + + /** + * Shortens the string $string and returns it. If the string is already short + * enough it is returned as it was. + * + * @param string $string The string value which must be shortened. + * @return string + */ + private static function shortenedString($string) + { + $string = preg_replace('#\n|\r\n|\r#', ' ', $string); + + if (strlen($string) > 14) { + return var_export(substr($string, 0, 7), TRUE) . '...' . var_export(substr($string, -7), TRUE); + } else { + return var_export($string, TRUE); + } + } +} + +} + +require_once 'PHPUnit2/Framework/ComparisonFailure/Array.php'; +require_once 'PHPUnit2/Framework/ComparisonFailure/Object.php'; +require_once 'PHPUnit2/Framework/ComparisonFailure/Scalar.php'; +require_once 'PHPUnit2/Framework/ComparisonFailure/String.php'; +require_once 'PHPUnit2/Framework/ComparisonFailure/Type.php'; + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/ComparisonFailure/Array.php b/Framework/ComparisonFailure/Array.php new file mode 100644 index 00000000000..5833b548b59 --- /dev/null +++ b/Framework/ComparisonFailure/Array.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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Thrown when an assertion for array equality failed. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +class PHPUnit2_Framework_ComparisonFailure_Array extends PHPUnit2_Framework_ComparisonFailure +{ + /** + * Returns a string describing the difference between the expected and the + * actual array. + * + * @note Diffing is only done for one level. + */ + public function toString() + { + $expectedOnly = array(); + $actualOnly = array(); + $diff = ''; + + foreach($this->expected as $expectedKey => $expectedValue) { + if (!array_key_exists($expectedKey, $this->actual)) { + $expectedOnly[] = $expectedKey; + continue; + } + + if ($expectedValue === $this->actual[$expectedKey]) continue; + + $diffObject = PHPUnit2_Framework_ComparisonFailure::diffIdentical($expectedValue, $this->actual[$expectedKey], $this->message . "array key <{$expectedKey}>: "); + $diff .= $diffObject->toString() . "\n"; + } + + foreach($this->actual as $actualKey => $actualValue) { + if (!array_key_exists($actualKey, $this->expected)) { + $actualOnly[] = $actualKey; + continue; + } + } + + foreach($expectedOnly as $expectedKey) { + $expectedValue = $this->expected[$expectedKey]; + $diff .= "array key <{$expectedKey}>: only in expected <{$expectedValue}>\n"; + } + + foreach($actualOnly as $actualKey) { + $actualValue = $this->actual[$actualKey]; + $diff .= "array key <{$actualKey}>: only in actual <{$actualValue}>\n"; + } + + return $diff; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/ComparisonFailure/Object.php b/Framework/ComparisonFailure/Object.php new file mode 100644 index 00000000000..80da9b3f836 --- /dev/null +++ b/Framework/ComparisonFailure/Object.php @@ -0,0 +1,147 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Thrown when an assertion for object equality failed. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +class PHPUnit2_Framework_ComparisonFailure_Object extends PHPUnit2_Framework_ComparisonFailure +{ + /** + * Returns a string describing the difference between the expected and the + * actual object. + * + * @note Diffing is only done for one level. + */ + public function toString() + { + $expectedClass = get_class($this->expected); + $actualClass = get_class($this->actual); + + if ($expectedClass !== $actualClass) { + return sprintf( + "%s%sexpected class <%s>\n" . + '%sgot class <%s>', + + $this->message, + ($this->message != '') ? ' ' : '', + $expectedClass, + ($this->message != '') ? str_repeat(' ', strlen($this->message) + 1) : '', + $actualClass + ); + } else { + $expectedReflection = new ReflectionClass($expectedClass); + $actualReflection = new ReflectionClass($actualClass); + + $diff = "in object of class <{$expectedClass}>:\n"; + $i = 0; + + foreach($expectedReflection->getProperties() as $expectedAttribute) { + if ($expectedAttribute->isPrivate() || $expectedAttribute->isProtected()) continue; + + $actualAttribute = $actualReflection->getProperty($expectedAttribute->getName()); + $expectedValue = $expectedAttribute->getValue($this->expected); + $actualValue = $actualAttribute->getValue($this->actual); + + if ($expectedValue !== $actualValue) { + if ($i > 0) { + $diff .= "\n"; + } + + ++$i; + + $expectedType = gettype($expectedValue); + $actualType = gettype($actualValue); + + if ($expectedType !== $actualType) { + $diffObject = new PHPUnit2_Framework_ComparisonFailure_Type($expectedValue, $actualValue, $this->message . 'attribute <' . $expectedAttribute->getName() . '>: '); + $diff .= $diffObject->toString(); + } + + elseif (is_object($expectedValue)) { + if (get_class($expectedValue) !== get_class($actualValue)) { + $diffObject = new PHPUnit2_Framework_ComparisonFailure_Type($expectedValue, $actualValue, $this->message . 'attribute <' . $expectedAttribute->getName() . '>: '); + $diff .= $diffObject->toString(); + } else { + $diff .= 'attribute <' . $expectedAttribute->getName() . '> contains object <' . get_class($expectedValue) . '> with different attributes'; + } + } else { + $diffObject = PHPUnit2_Framework_ComparisonFailure::diffIdentical($expectedValue, $actualValue, $this->message . 'attribute <' . $expectedAttribute->getName() . '>: '); + $diff .= $diffObject->toString(); + } + } + } + + return $diff; + } + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/ComparisonFailure/Scalar.php b/Framework/ComparisonFailure/Scalar.php new file mode 100644 index 00000000000..3983ea06169 --- /dev/null +++ b/Framework/ComparisonFailure/Scalar.php @@ -0,0 +1,131 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Thrown when an assertion for scalar equality failed. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +class PHPUnit2_Framework_ComparisonFailure_Scalar extends PHPUnit2_Framework_ComparisonFailure +{ + /** + * Returns a string describing the difference between the expected and the + * actual scalar value. + */ + public function toString() + { + if (is_bool($this->expected)) { + return sprintf( + "%s%sexpected bool <%s>\n" . + '%sgot bool <%s>', + + $this->message, + ($this->message != '') ? ' ' : '', + var_export($this->expected, TRUE), + ($this->message != '') ? str_repeat(' ', strlen($this->message) + 1) : '', + var_export($this->actual, TRUE) + ); + } + + elseif (is_int($this->expected) || is_float($this->expected)) { + $type = gettype($this->expected); + $expectedString = var_export($this->expected, TRUE); + $actualString = var_export($this->actual, TRUE); + $differenceString = var_export(abs($this->actual - $this->expected), TRUE); + + $expectedLen = strlen($expectedString); + $actualLen = strlen($actualString); + $differenceLen = strlen($differenceString); + $maxLen = max($expectedLen, $actualLen, $differenceLen); + + $expectedString = str_pad($expectedString, $maxLen, ' ', STR_PAD_LEFT); + $differenceString = str_pad($differenceString, $maxLen, ' ', STR_PAD_LEFT); + $actualString = str_pad($actualString, $maxLen, ' ', STR_PAD_LEFT); + + return sprintf( + "%s%sexpected %s <%s>\n" . + "%sdifference%s<%s>\n" . + '%sgot %s <%s>', + + $this->message, + ($this->message != '') ? ' ' : '', + $type, + $expectedString, + ($this->message != '') ? str_repeat(' ', strlen($this->message) + 1) : '', + str_repeat(' ', strlen($type)), + $differenceString, + ($this->message != '') ? str_repeat(' ', strlen($this->message) + 1) : '', + $type, + $actualString + ); + } + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/ComparisonFailure/String.php b/Framework/ComparisonFailure/String.php new file mode 100644 index 00000000000..6dd77a77fab --- /dev/null +++ b/Framework/ComparisonFailure/String.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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Thrown when an assertion for string equality failed. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +class PHPUnit2_Framework_ComparisonFailure_String extends PHPUnit2_Framework_ComparisonFailure +{ + /** + * Returns a string describing the difference between + * the expected and the actual string value. + */ + public function toString() + { + $expected = (string)$this->expected; + $actual = (string)$this->actual; + + $expectedLen = strlen($expected); + $actualLen = strlen($actual); + $minLen = min($expectedLen, $actualLen); + $maxLen = max($expectedLen, $actualLen); + + for ($i = 0; $i < $minLen; ++$i) { + if ($expected[$i] != $actual[$i]) break; + } + + $startPos = $i; + $endPos = $minLen; + + if ($minLen > 0) { + for ($i = $minLen - 1; $i > $startPos; --$i) { + if ($expected[$i] != $actual[$i]) break; + } + + $endPos = $i + 1; + } + + return sprintf( + "%s%sexpected string <%s>\n" . + "%sdifference <%s>\n" . + '%sgot string <%s>', + + $this->message, + ($this->message != '') ? ' ' : '', + $expected, + ($this->message != '') ? str_repeat(' ', strlen($this->message) + 1) : '', + str_repeat(' ', $startPos) . str_repeat('x', $endPos - $startPos) . str_repeat('?', $maxLen - $minLen), + ($this->message != '') ? str_repeat(' ', strlen($this->message) + 1) : '', + $actual + ); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/ComparisonFailure/Type.php b/Framework/ComparisonFailure/Type.php new file mode 100644 index 00000000000..8ee9874259b --- /dev/null +++ b/Framework/ComparisonFailure/Type.php @@ -0,0 +1,173 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Thrown when an assertion for type equality failed. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +class PHPUnit2_Framework_ComparisonFailure_Type extends PHPUnit2_Framework_ComparisonFailure +{ + private $expectedIsType; + + /** + * Initialises with the expected value and the actual value. + * + * @param mixed $expected Expected value retrieved. + * @param mixed $actual Actual value retrieved. + * @param string $message A string which is prefixed on all returned lines + * in the difference output. + * @param boolean $expectedIsType + */ + public function __construct($expected, $actual, $message = '', $expectedIsType = FALSE) + { + parent::__construct($expected, $actual, $message); + + $this->expectedIsType = $expectedIsType; + } + + /** + * Returns a string describing the type difference between the expected + * and the actual value. + */ + public function toString() + { + $actualType = gettype($this->actual); + + if ($this->expectedIsType) { + $expectedType = $this->expected; + } else { + $expectedType = gettype($this->expected); + } + + $expectedDiffLen = strlen($expectedType) - strlen($actualType); + $actualDiffLen = -$expectedDiffLen; + + if ($expectedDiffLen > 0) { + $expectedType .= str_repeat(' ', $expectedDiffLen); + } + + if ($actualDiffLen > 0) { + $actualType .= str_repeat(' ', $actualDiffLen); + } + + $actualValue = ''; + + if (is_string($this->actual) || is_bool($this->actual) || is_int($this->actual) || is_float($this->actual)) { + $actualValue = '<' . var_export($this->actual, TRUE) . '>'; + } + + elseif (is_object($this->actual)) { + $actualValue = '<' . get_class($this->actual) . '>'; + } + + $expectedValue = ''; + + if ($this->expectedIsType) { + $expectedValue = '<' . $this->expected . '>'; + } else { + if (is_string($this->expected) || is_bool($this->expected) || is_int($this->expected) || is_float($this->expected)) { + $expectedValue = '<' . var_export($this->expected, TRUE) . '>'; + } + + elseif (is_object($this->expected)) { + $expectedValue = '<' . get_class($this->expected) . '>'; + } + } + + if ($this->expectedIsType) { + return sprintf( + "%s%sexpected type %s\n" . + '%sgot type %s %s', + + $this->message, + ($this->message != '') ? ' ' : '', + $expectedType, + ($this->message != '') ? str_repeat(' ', strlen($this->message) + 1) : '', + $actualType, + $actualValue + ); + } else { + return sprintf( + "%s%sexpected %s %s\n" . + '%sgot %s %s', + + $this->message, + ($this->message != '') ? ' ' : '', + $expectedType, + $expectedValue, + ($this->message != '') ? str_repeat(' ', strlen($this->message) + 1) : '', + $actualType, + $actualValue + ); + } + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/Constraint.php b/Framework/Constraint.php new file mode 100644 index 00000000000..38d1c526011 --- /dev/null +++ b/Framework/Constraint.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 Jan Borsodi + * Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!interface_exists('PHPUnit2_Framework_Constraint')) { + +/** + * Interface for constraints which are placed upon any value. + * + * The constraint can be used in method name matching and parameter value matching + * to perform more advanced checking than simply matching two values with ==. + * + * A constraint must provides the following methods: + * - evaluate() check if a given object meets the constraint. If it does + * not, fail() can be called to create an exception. + * - toStrint() returns a description of the constraint. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * 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 3.0.0 + */ +interface PHPUnit2_Framework_Constraint extends PHPUnit2_Framework_SelfDescribing +{ + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @parameter mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other); + + /** + * Creates the appropriate exception for the constraint which can be caught + * by the unit test system. This can be called if a call to evaluate() fails. + * + * @param mixed $other The value passed to evaluate() which failed the + * constraint check. + * @param string $description A string with extra description of what was + * going on while the evaluation failed. + * @throws PHPUnit2_Framework_ExpectationFailedException + */ + public function fail($other, $description); +} + +} + +require_once 'PHPUnit2/Framework/Constraint/And.php'; +require_once 'PHPUnit2/Framework/Constraint/ArrayHasKey.php'; +require_once 'PHPUnit2/Framework/Constraint/FileExists.php'; +require_once 'PHPUnit2/Framework/Constraint/GreaterThan.php'; +require_once 'PHPUnit2/Framework/Constraint/IsAnything.php'; +require_once 'PHPUnit2/Framework/Constraint/IsEqual.php'; +require_once 'PHPUnit2/Framework/Constraint/IsIdentical.php'; +require_once 'PHPUnit2/Framework/Constraint/IsInstanceOf.php'; +require_once 'PHPUnit2/Framework/Constraint/IsType.php'; +require_once 'PHPUnit2/Framework/Constraint/LessThan.php'; +require_once 'PHPUnit2/Framework/Constraint/Not.php'; +require_once 'PHPUnit2/Framework/Constraint/ObjectHasAttribute.php'; +require_once 'PHPUnit2/Framework/Constraint/Or.php'; +require_once 'PHPUnit2/Framework/Constraint/PCREMatch.php'; +require_once 'PHPUnit2/Framework/Constraint/StringContains.php'; +require_once 'PHPUnit2/Framework/Constraint/TraversableContains.php'; + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/Constraint/And.php b/Framework/Constraint/And.php new file mode 100644 index 00000000000..f8fc04a9b5f --- /dev/null +++ b/Framework/Constraint/And.php @@ -0,0 +1,169 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Constraint which will only evaluate to true if all sub-constraints does the same. + * + * This means the constraint behaves like a logical and. All parameters passed + * to the constructor will be considered a constraint to check. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +class PHPUnit2_Framework_Constraint_And implements PHPUnit2_Framework_Constraint +{ + private $constraints = array(); + + private $failedConstraint = NULL; + + public function setConstraints(Array $constraints) + { + $this->constraints = array(); + + foreach($constraints as $key => $constraint) { + if (!($constraint instanceof PHPUnit2_Framework_Constraint)) { + throw new InvalidArgumentException('All parameters to ' . __CLASS__ . ' must be a constraint object.'); + } + + $this->constraints[] = $constraint; + } + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @parameter mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + $this->failedConstraint = NULL; + + foreach($this->constraints as $key => $constraint) { + if (!$constraint->evaluate($other)) { + $this->failedConstraint = $constraint; + + return FALSE; + } + } + + return TRUE; + } + + /** + * @param mixed $other The value passed to evaluate() which failed the + * constraint check. + * @param string $description A string with extra description of what was + * going on while the evaluation failed. + * @throws PHPUnit2_Framework_ExpectationFailedException + */ + public function fail($other, $description) + { + if ($this->failedConstraint !== NULL) { + $this->failedConstraint->fail( + $other, + $description . "\n" . + 'Expected that <' . $other . '> ' . $this->toString() + ); + } else { + throw new PHPUnit2_Framework_ExpectationFailedException( + sprintf( + "%s\nExpected that <%s> %s", + + $description, + var_export($other, 1), + $this->toString() + ) + ); + } + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + $text = ''; + + foreach($this->constraints as $key => $constraint) { + if ($key > 0) { + $text .= ' and '; + } + + $text .= $constraint->toString(); + } + + return $text; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/Constraint/ArrayHasKey.php b/Framework/Constraint/ArrayHasKey.php new file mode 100644 index 00000000000..5200ee4ccd7 --- /dev/null +++ b/Framework/Constraint/ArrayHasKey.php @@ -0,0 +1,139 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Constraint which checks if a certain key is found in the input array. + * + * Uses array_key_exists() to check if the key is found in the input array, if not + * found the evaluaton fails. + * + * The array key is passed in the constructor. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +class PHPUnit2_Framework_Constraint_ArrayHasKey implements PHPUnit2_Framework_Constraint +{ + private $key; + + public function __construct($key) + { + $this->key = $key; + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @parameter mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + return array_key_exists($this->key, $other); + } + + /** + * @param mixed $other The value passed to evaluate() which failed the + * constraint check. + * @param string $description A string with extra description of what was + * going on while the evaluation failed. + * @throws PHPUnit2_Framework_ExpectationFailedException + */ + public function fail($other, $description) + { + throw new PHPUnit2_Framework_ExpectationFailedException( + sprintf( + "%s\nexpected array key <%s:%s> not found in array <%s>", + + $description, + gettype($this->key), + var_export($this->key, TRUE), + var_export($other, TRUE) + ) + ); + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + return sprintf( + 'has key <%s:%s>', + + gettype($this->key), + var_export($this->key, TRUE) + ); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/Constraint/FileExists.php b/Framework/Constraint/FileExists.php new file mode 100644 index 00000000000..648e9eebd89 --- /dev/null +++ b/Framework/Constraint/FileExists.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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Constraint which checks if a given file exists. + * + * The file path to check is passed as $other in evaluate(). + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +class PHPUnit2_Framework_Constraint_FileExists implements PHPUnit2_Framework_Constraint +{ + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @parameter mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + return file_exists($other); + } + + /** + * @param mixed $other The value passed to evaluate() which failed the + * constraint check. + * @param string $description A string with extra description of what was + * going on while the evaluation failed. + * @throws PHPUnit2_Framework_ExpectationFailedException + */ + public function fail($other, $description) + { + throw new PHPUnit2_Framework_ExpectationFailedException( + sprintf( + "%s\nfile <%s> does not exist", + + $description, + $other + ) + ); + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + return 'file exists'; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/Constraint/GreaterThan.php b/Framework/Constraint/GreaterThan.php new file mode 100644 index 00000000000..483da753a12 --- /dev/null +++ b/Framework/Constraint/GreaterThan.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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Constraint which checks if one value is greater than another. + * + * The expected value is passed in the constructor. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +class PHPUnit2_Framework_Constraint_GreaterThan implements PHPUnit2_Framework_Constraint +{ + private $value; + + public function __construct($value) + { + $this->value = $value; + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @parameter mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + return $this->value < $other; + } + + /** + * @param mixed $other The value passed to evaluate() which failed the + * constraint check. + * @param string $description A string with extra description of what was + * going on while the evaluation failed. + * @throws PHPUnit2_Framework_ExpectationFailedException + */ + public function fail($other, $description) + { + throw new PHPUnit2_Framework_ExpectationFailedException( + $description, + PHPUnit2_Framework_ComparisonFailure::diffIdentical($this->value, $other) + ); + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + $type = ''; + + if (!is_null($this->value)) { + $type = gettype($this->value) . ':'; + } + + return sprintf( + 'is greater than <%s>', + + $type . var_export($this->value, TRUE) + ); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/Constraint/IsAnything.php b/Framework/Constraint/IsAnything.php new file mode 100644 index 00000000000..04e3cb25692 --- /dev/null +++ b/Framework/Constraint/IsAnything.php @@ -0,0 +1,111 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Constraint which accepts any input value. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +class PHPUnit2_Framework_Constraint_IsAnything implements PHPUnit2_Framework_Constraint +{ + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @parameter mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + return TRUE; + } + + /** + * @param mixed $other The value passed to evaluate() which failed the + * constraint check. + * @param string $description A string with extra description of what was + * going on while the evaluation failed. + */ + public function fail($other, $description) + { + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + return 'can be anything'; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/Constraint/IsEqual.php b/Framework/Constraint/IsEqual.php new file mode 100644 index 00000000000..4c64fdfde68 --- /dev/null +++ b/Framework/Constraint/IsEqual.php @@ -0,0 +1,333 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Array.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!class_exists('DualIterator')) { +class DualIterator implements Iterator +{ + const CURRENT_LHS = 0x01; + const CURRENT_RHS = 0x02; + const CURRENT_ARRAY = 0x03; + const CURRENT_0 = 0x00; + + const KEY_LHS = 0x10; + const KEY_RHS = 0x20; + const KEY_ARRAY = 0x30; + const KEY_0 = 0x00; + + const DEFAULT_FLAGS = 0x33; + + private $lhs; + private $rhs; + private $flags; + + public function __construct(Iterator $lhs, Iterator $rhs, $flags = 0x33) + { + $this->lhs = $lhs; + $this->rhs = $rhs; + $this->flags = $flags; + } + + public function getLHS() + { + return $this->lhs; + } + + public function getRHS() + { + return $this->rhs; + } + + public function setFlags($flags) + { + $this->flags = $flags; + } + + public function getFlags() + { + return $this->flags; + } + + public function rewind() + { + $this->lhs->rewind(); + $this->rhs->rewind(); + } + + public function valid() + { + return $this->lhs->valid() && $this->rhs->valid(); + } + + public function current() + { + switch($this->flags & 0x0F) { + default: + case self::CURRENT_ARRAY: { + return array($this->lhs->current(), $this->rhs->current()); + } + + case self::CURRENT_LHS: { + return $this->lhs->current(); + } + + case self::CURRENT_RHS: { + return $this->rhs->current(); + } + + case self::CURRENT_0: { + return NULL; + } + } + } + + public function key() + { + switch($this->flags & 0xF0) { + default: + case self::CURRENT_ARRAY: { + return array($this->lhs->key(), $this->rhs->key()); + } + + case self::CURRENT_LHS: { + return $this->lhs->key(); + } + + case self::CURRENT_RHS: { + return $this->rhs->key(); + } + + case self::CURRENT_0: { + return NULL; + } + } + } + + public function next() + { + $this->lhs->next(); + $this->rhs->next(); + } + + public function areIdentical() + { + return $this->valid() + ? $this->lhs->current() === $this->rhs->current() + && $this->lhs->key() === $this->rhs->key() + : $this->lhs->valid() == $this->rhs->valid(); + } + + public function areEqual() + { + return $this->valid() + ? $this->lhs->current() == $this->rhs->current() + && $this->lhs->key() == $this->rhs->key() + : $this->lhs->valid() == $this->rhs->valid(); + } + + public static function compareIterators(Iterator $lhs, Iterator $rhs, $identical = FALSE) + { + if ($lhs instanceof RecursiveIterator) { + if ($rhs instanceof RecursiveIterator) { + $it = new RecursiveDualIterator($lhs, $rhs, self::CURRENT_0 | self::KEY_0); + } else { + return FALSE; + } + } else { + $it = new DualIterator($lhs, $rhs, self::CURRENT_0 | self::KEY_0); + } + + if ($identical) { + foreach (new RecursiveIteratorIterator($it) as $n) { + if (!$it->areIdentical()) { + return FALSE; + } + } + } else { + foreach ($it as $n) { + if (!$it->areEqual()) { + return FALSE; + } + } + } + + return $identical ? $it->areIdentical() : $it->areEqual(); + } +} +} + +/** + * Constraint which checks if one value is equal to another. + * + * Equality is checked with PHP's == operator, the operator is explained in detail + * at {@url http://www.php.net/manual/en/types.comparisons.php}. + * Two values are equal if they have the same value disregarding type. + * + * The expected value is passed in the constructor. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +class PHPUnit2_Framework_Constraint_IsEqual implements PHPUnit2_Framework_Constraint +{ + private $value; + private $delta = 0; + + public function __construct($value, $delta = 0) + { + $this->value = $value; + $this->delta = $delta; + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @parameter mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + if (is_array($this->value) && is_array($other)) { + if (count($this->value) != count($other)) { + return FALSE; + } + + return DualIterator::compareIterators( + new RecursiveIteratorIterator( + new RecursiveArrayIterator( + PHPUnit2_Util_Array::sortRecursively($this->value) + ), + RecursiveIteratorIterator::SELF_FIRST + ), + new RecursiveIteratorIterator( + new RecursiveArrayIterator( + PHPUnit2_Util_Array::sortRecursively($other) + ), + RecursiveIteratorIterator::SELF_FIRST + ) + ); + } + + else if (is_float($this->value) && is_float($other) && is_float($this->delta)) { + return (abs($this->value - $other) <= $this->delta); + } + + else { + return $this->value == $other; + } + } + + /** + * @param mixed $other The value passed to evaluate() which failed the + * constraint check. + * @param string $description A string with extra description of what was + * going on while the evaluation failed. + * @throws PHPUnit2_Framework_ExpectationFailedException + */ + public function fail($other, $description) + { + throw new PHPUnit2_Framework_ExpectationFailedException( + $description, + PHPUnit2_Framework_ComparisonFailure::diffIdentical($this->value, $other) + ); + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + $delta = ''; + $type = ''; + + if ($this->delta != 0) { + $delta = sprintf( + ' with delta <%d>', + + $this->delta + ); + } + + if (!is_null($this->value)) { + $type = gettype($this->value) . ':'; + } + + return sprintf( + 'is equal to <%s>%s', + + $type . var_export($this->value, TRUE), + $delta + ); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/Constraint/IsIdentical.php b/Framework/Constraint/IsIdentical.php new file mode 100644 index 00000000000..c4a73aabaa9 --- /dev/null +++ b/Framework/Constraint/IsIdentical.php @@ -0,0 +1,140 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Constraint which checks if one value is identical to another. + * + * Identical check is performed with PHP's === operator, the operator is explained + * in detail at {@url http://www.php.net/manual/en/types.comparisons.php}. + * Two values are identical if they have the same value and are of the same type. + * + * The expected value is passed in the constructor. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +class PHPUnit2_Framework_Constraint_IsIdentical implements PHPUnit2_Framework_Constraint +{ + private $value; + + public function __construct($value) + { + $this->value = $value; + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @parameter mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + return $this->value === $other; + } + + /** + * @param mixed $other The value passed to evaluate() which failed the + * constraint check. + * @param string $description A string with extra description of what was + * going on while the evaluation failed. + * @throws PHPUnit2_Framework_ExpectationFailedException + */ + public function fail($other, $description) + { + throw new PHPUnit2_Framework_ExpectationFailedException( + $description, + PHPUnit2_Framework_ComparisonFailure::diffIdentical($this->value, $other) + ); + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + $type = ''; + + if (!is_null($this->value)) { + $type = gettype($this->value) . ':'; + } + + return sprintf( + 'is identical to <%s%s>', + + $type, + var_export($this->value, TRUE) + ); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/Constraint/IsInstanceOf.php b/Framework/Constraint/IsInstanceOf.php new file mode 100644 index 00000000000..fadf9df3149 --- /dev/null +++ b/Framework/Constraint/IsInstanceOf.php @@ -0,0 +1,147 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Constraint which checks if one object is and instance of a given class. + * + * The expected class name is passed in the constructor. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +class PHPUnit2_Framework_Constraint_IsInstanceOf implements PHPUnit2_Framework_Constraint +{ + private $className; + + public function __construct($className) + { + $this->className = $className; + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @parameter mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + return ($other instanceof $this->className); + } + + /** + * @param mixed $other The value passed to evaluate() which failed the + * constraint check. + * @param string $description A string with extra description of what was + * going on while the evaluation failed. + * @throws PHPUnit2_Framework_ExpectationFailedException + */ + public function fail($other, $description) + { + if (!is_object($other)) { + throw new PHPUnit2_Framework_ExpectationFailedException( + sprintf( + "%s\nexpected object instance of class <%s>, got %s <%s>", + + $description, + $this->className, + gettype($other), + var_export($other, TRUE) + ) + ); + } else { + throw new PHPUnit2_Framework_ExpectationFailedException( + sprintf( + "%s\nexpected object instance of class <%s>, got class <%s>", + + $description, + $this->className, + get_class($other) + ) + ); + } + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + return sprintf( + 'is instance of <%s>', + + $this->className + ); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/Constraint/IsType.php b/Framework/Constraint/IsType.php new file mode 100644 index 00000000000..57e7cc5bf4a --- /dev/null +++ b/Framework/Constraint/IsType.php @@ -0,0 +1,222 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Constraint which checks if a value is of a specified type. + * + * The expected value is passed in the constructor. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +class PHPUnit2_Framework_Constraint_IsType implements PHPUnit2_Framework_Constraint +{ + private $type; + + public function __construct($type) + { + switch ($type) { + case 'integer': + case 'int': + case 'float': + case 'string': + case 'boolean': + case 'bool': + case 'null': + case 'array': + case 'object': { + break; + } + + default: { + throw new InvalidArgumentException( + sprintf( + 'Type specified for PHPUnit2_Framework_Constraint_IsType <%s> is not a valid type.', + + $type + ) + ); + } + } + + $this->type = $type; + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @parameter mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + switch ($this->type) { + case 'integer': + case 'int': { + return is_integer($other); + } + + case 'float': { + return is_float($other); + } + + case 'string': { + return is_string($other); + } + + case 'boolean': + case 'bool': { + return is_bool($other); + } + + case 'null': { + return is_null($other); + } + + case 'array': { + return is_array($other); + } + + case 'object': { + return is_object($other); + } + } + } + + /** + * @param mixed $other The value passed to evaluate() which failed the + * constraint check. + * @param string $description A string with extra description of what was + * going on while the evaluation failed. + * @throws PHPUnit2_Framework_ExpectationFailedException + */ + public function fail($other, $description) + { + switch ($this->type) { + case 'integer': + case 'int': { + $expected = 1; + } + break; + + case 'float': { + $expected = 1.1; + } + break; + + case 'string': { + $expected = 'str'; + } + break; + + case 'boolean': + case 'bool': { + $expected = TRUE; + } + break; + + case 'null': { + $expected = NULL; + } + break; + + case 'array': { + $expected = array(1); + } + break; + + case 'object': { + $expected = new Exception(); + } + break; + } + + throw new PHPUnit2_Framework_ExpectationFailedException( + $description, + new PHPUnit2_Framework_ComparisonFailure_Type($expected, $other) + ); + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + return sprintf( + 'is type <%s>', + + $this->type + ); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/Constraint/LessThan.php b/Framework/Constraint/LessThan.php new file mode 100644 index 00000000000..b4dae00ca76 --- /dev/null +++ b/Framework/Constraint/LessThan.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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Constraint which checks if one value is less than another. + * + * The expected value is passed in the constructor. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +class PHPUnit2_Framework_Constraint_LessThan implements PHPUnit2_Framework_Constraint +{ + private $value; + + public function __construct($value) + { + $this->value = $value; + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @parameter mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + return $this->value > $other; + } + + /** + * @param mixed $other The value passed to evaluate() which failed the + * constraint check. + * @param string $description A string with extra description of what was + * going on while the evaluation failed. + * @throws PHPUnit2_Framework_ExpectationFailedException + */ + public function fail($other, $description) + { + throw new PHPUnit2_Framework_ExpectationFailedException( + $description, + PHPUnit2_Framework_ComparisonFailure::diffIdentical($this->value, $other) + ); + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + $type = ''; + + if (!is_null($this->value)) { + $type = gettype($this->value) . ':'; + } + + return sprintf( + 'is less than <%s>', + + $type . var_export($this->value, TRUE) + ); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/Constraint/Not.php b/Framework/Constraint/Not.php new file mode 100644 index 00000000000..0cabfc8db6a --- /dev/null +++ b/Framework/Constraint/Not.php @@ -0,0 +1,130 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Constraint which inverts the evaluation result of a sub-constraint. + * + * This class will evaluate the sub-constraint and invert (not) the value, + * this means true becomes false and false becomes true. + * + * The sub-constrainted is passed in the constructor. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ + +class PHPUnit2_Framework_Constraint_Not implements PHPUnit2_Framework_Constraint +{ + private $constraint; + + public function __construct($constraint) + { + if (!($constraint instanceof PHPUnit2_Framework_Constraint)) { + $constraint = new PHPUnit2_Framework_Constraint_IsEqual($constraint); + } + + $this->constraint = $constraint; + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @parameter mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + return !$this->constraint->evaluate($other); + } + + /** + * @param mixed $other The value passed to evaluate() which failed the + * constraint check. + * @param string $description A string with extra description of what was + * going on while the evaluation failed. + * @throws PHPUnit2_Framework_ExpectationFailedException + */ + public function fail($other, $description) + { + $this->constraint->fail($other, $description); + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + return 'not ' . $this->constraint->toString(); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/Constraint/ObjectHasAttribute.php b/Framework/Constraint/ObjectHasAttribute.php new file mode 100644 index 00000000000..9a29f22ecdc --- /dev/null +++ b/Framework/Constraint/ObjectHasAttribute.php @@ -0,0 +1,137 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Constraint which checks if an object has a certain attribute. + * + * The attribute name is passed in the constructor. + * + * @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 3.0.0 + */ +class PHPUnit2_Framework_Constraint_ObjectHasAttribute implements PHPUnit2_Framework_Constraint +{ + private $attributeName; + + public function __construct($attributeName) + { + $this->attributeName = $attributeName; + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @parameter mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + $object = new ReflectionObject($other); + + return $object->hasProperty($this->attributeName); + } + + /** + * @param mixed $other The value passed to evaluate() which failed the + * constraint check. + * @param string $description A string with extra description of what was + * going on while the evaluation failed. + * @throws PHPUnit2_Framework_ExpectationFailedException + */ + public function fail($other, $description) + { + throw new PHPUnit2_Framework_ExpectationFailedException( + sprintf( + "%s\nexpected attribute <%s:%s> not found in object <%s>", + + $description, + gettype($this->attributeName), + var_export($this->attributeName, TRUE), + var_export($other, TRUE) + ) + ); + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + return sprintf( + 'has attribute <%s:%s>', + + gettype($this->attributeName), + var_export($this->attributeName, TRUE) + ); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/Constraint/Or.php b/Framework/Constraint/Or.php new file mode 100644 index 00000000000..683c4d9afa3 --- /dev/null +++ b/Framework/Constraint/Or.php @@ -0,0 +1,155 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Constraint which will only evaluate to true if at least one of the sub-constraints does the same. + * + * This means the constraint behaves like a logical or. All parameters passed + * to the constructor will be considered a constraint to check. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +class PHPUnit2_Framework_Constraint_Or implements PHPUnit2_Framework_Constraint +{ + private $constraints = array(); + + public function setConstraints(Array $constraints) + { + $this->constraints = array(); + + foreach($constraints as $key => $constraint) { + if (!($constraint instanceof PHPUnit2_Framework_Constraint)) { + $constraint = new PHPUnit2_Framework_Constraint_IsEqual($constraint); + } + + $this->constraints[] = $constraint; + } + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @parameter mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + foreach($this->constraints as $key => $constraint) { + if ($constraint->evaluate($other)) { + return TRUE; + } + } + + return FALSE; + } + + /** + * @param mixed $other The value passed to evaluate() which failed the + * constraint check. + * @param string $description A string with extra description of what was + * going on while the evaluation failed. + * @throws PHPUnit2_Framework_ExpectationFailedException + */ + public function fail($other, $description) + { + throw new PHPUnit2_Framework_ExpectationFailedException( + sprintf( + "%s\nexpected <%s> %s", + + $description, + var_export($other, 1), + $this->toString() + ) + ); + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + $text = ''; + + foreach($this->constraints as $key => $constraint) { + if ($key > 0) { + $text .= ' or '; + } + + $text .= $constraint->toString(); + } + + return $text; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/Constraint/PCREMatch.php b/Framework/Constraint/PCREMatch.php new file mode 100644 index 00000000000..9ef74656785 --- /dev/null +++ b/Framework/Constraint/PCREMatch.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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Constraint which performas a PCRE pattern match with another value. + * + * Checks a given value using the Perl Compatible Regular Expression extension + * in PHP. The pattern is matched by executing preg_match(). + * + * The pattern string passed in the constructor. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +class PHPUnit2_Framework_Constraint_PCREMatch implements PHPUnit2_Framework_Constraint +{ + private $pattern; + + public function __construct($pattern) + { + $this->pattern = $pattern; + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @parameter mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + return preg_match($this->pattern, $other); + } + + /** + * @param mixed $other The value passed to evaluate() which failed the + * constraint check. + * @param string $description A string with extra description of what was + * going on while the evaluation failed. + * @throws PHPUnit2_Framework_ExpectationFailedException + */ + public function fail($other, $description) + { + throw new PHPUnit2_Framework_ExpectationFailedException( + sprintf( + "%s\nPCRE pattern <%s> did not find a match in value <%s:%s>", + + $description, + var_export($this->pattern, TRUE), + gettype($other), + var_export($other, TRUE) + ) + ); + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + return sprintf( + 'matches PCRE pattern <%s>', + + var_export($this->pattern, TRUE) + ); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/Constraint/StringContains.php b/Framework/Constraint/StringContains.php new file mode 100644 index 00000000000..eb3c395a566 --- /dev/null +++ b/Framework/Constraint/StringContains.php @@ -0,0 +1,158 @@ +. + * 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 Jan Borsodi + * @author Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Constraint which checks if a certain string is found in the input string. + * + * Uses strpos() to find the position of the string in the input, if not found + * the evaluaton fails. + * + * The sub-string is passed in the constructor. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * @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 3.0.0 + */ +class PHPUnit2_Framework_Constraint_StringContains implements PHPUnit2_Framework_Constraint +{ + private $string; + + private $case; + + public function __construct($string, $case = TRUE) + { + $this->string = $string; + $this->case = $case; + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @parameter mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + if ($this->case) { + return strpos($other, $this->string) !== FALSE; + } else { + return stripos($other, $this->string) !== FALSE; + } + } + + /** + * @param mixed $other The value passed to evaluate() which failed the + * constraint check. + * @param string $description A string with extra description of what was + * going on while the evaluation failed. + * @throws PHPUnit2_Framework_ExpectationFailedException + */ + public function fail($other, $description) + { + if ($this->case) { + $string = var_export($this->string, TRUE); + $otherString = var_export($other, TRUE); + } else { + $string = var_export(strtolower($this->string), TRUE); + $otherString = var_export(strtolower($other), TRUE); + } + + throw new PHPUnit2_Framework_ExpectationFailedException( + sprintf( + "%s\nexpected string <%s> not found in string <%s>", + + $description, + $string, + $otherString + ) + ); + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + if ($this->case) { + $string = var_export($this->string, TRUE); + } else { + $string = var_export(strtolower($this->string), TRUE); + } + + return sprintf( + 'contains string <%s>', + + $string + ); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/Constraint/TraversableContains.php b/Framework/Constraint/TraversableContains.php new file mode 100644 index 00000000000..e27b437811d --- /dev/null +++ b/Framework/Constraint/TraversableContains.php @@ -0,0 +1,141 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, '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 3.0.0 + */ +class PHPUnit2_Framework_Constraint_TraversableContains implements PHPUnit2_Framework_Constraint +{ + private $value; + + public function __construct($value) + { + $this->value = $value; + } + + /** + * Evaluates the constraint for parameter $other. Returns TRUE if the + * constraint is met, FALSE otherwise. + * + * @parameter mixed $other Value or object to evaluate. + * @return bool + */ + public function evaluate($other) + { + $found = FALSE; + + foreach ($other as $straw) { + if ($straw === $this->value) { + $found = TRUE; + break; + } + } + + return $found; + } + + /** + * @param mixed $other The value passed to evaluate() which failed the + * constraint check. + * @param string $description A string with extra description of what was + * going on while the evaluation failed. + * @throws PHPUnit2_Framework_ExpectationFailedException + */ + public function fail($other, $description) + { + throw new PHPUnit2_Framework_ExpectationFailedException( + sprintf( + "%s\nexpected value <%s:%s> not found in object <%s>", + + $description, + gettype($this->value), + var_export($this->value, TRUE), + var_export($other, TRUE) + ) + ); + } + + /** + * Returns a string representation of the constraint. + * + * @return string + * @access public + */ + public function toString() + { + return sprintf( + 'contains value <%s:%s>', + + gettype($this->value), + var_export($this->value, TRUE) + ); + } +} + +/* + * 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..0a38b0662bc --- /dev/null +++ b/Framework/Error.php @@ -0,0 +1,98 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.2.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!class_exists('PHPUnit2_Framework_Error')) { + +/** + * 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/ExpectationFailedException.php b/Framework/ExpectationFailedException.php new file mode 100644 index 00000000000..6164d48b96f --- /dev/null +++ b/Framework/ExpectationFailedException.php @@ -0,0 +1,111 @@ +. + * 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 Jan Borsodi + * Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!class_exists('PHPUnit2_Framework_ExpectationFailedException')) { + +/** + * Exception for expectations which failed their check. + * + * The exception contains the error message and optionally a + * PHPUnit2_Framework_ComparisonFailure which is used to + * generate diff output of the failed expectations. + * + * @category Testing + * @package PHPUnit2 + * @author Jan Borsodi + * 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 3.0.0 + */ +class PHPUnit2_Framework_ExpectationFailedException extends PHPUnit2_Framework_AssertionFailedError +{ + private $comparisonFailure; + private $description; + + public function __construct($message, PHPUnit2_Framework_ComparisonFailure $comparisonFailure = NULL) + { + $this->comparisonFailure = $comparisonFailure; + $this->description = $message; + + if ($comparisonFailure !== NULL) { + $message .= "\n" . $comparisonFailure->toString(); + } + + parent::__construct($message); + } + + public function getComparisonFailure() + { + return $this->comparisonFailure; + } + + public function getDescription() + { + return $this->description; + } +} + +} + +/* + * 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..43d384dceee --- /dev/null +++ b/Framework/IncompleteTest.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!interface_exists('PHPUnit2_Framework_IncompleteTest')) { + +/** + * 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..f028483e533 --- /dev/null +++ b/Framework/IncompleteTestError.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!class_exists('PHPUnit2_Framework_IncompleteTestError')) { + +/** + * 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/SelfDescribing.php b/Framework/SelfDescribing.php new file mode 100644 index 00000000000..27e57abeb12 --- /dev/null +++ b/Framework/SelfDescribing.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 Jan Borsodi + * Sebastian Bergmann + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!interface_exists('PHPUnit2_Framework_SelfDescribing')) { + +/** + * Interface for classes that can return a description of itself. + * + * @category Testing + * @package PHPUnit2 + * 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 3.0.0 + */ +interface PHPUnit2_Framework_SelfDescribing +{ + /** + * Returns a string representation of the object. + * + * @return string + * @access public + */ + public function toString(); +} + +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/SkippedTest.php b/Framework/SkippedTest.php new file mode 100644 index 00000000000..3a95e76ad29 --- /dev/null +++ b/Framework/SkippedTest.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!interface_exists('PHPUnit2_Framework_SkippedTest')) { + +/** + * A marker interface for marking a unit test as being skipped. + * + * @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 3.0.0 + */ +interface PHPUnit2_Framework_SkippedTest +{ +} + +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Framework/SkippedTestError.php b/Framework/SkippedTestError.php new file mode 100644 index 00000000000..8bad6653ae8 --- /dev/null +++ b/Framework/SkippedTestError.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!class_exists('PHPUnit2_Framework_SkippedTestError')) { + +/** + * Extension to PHPUnit2_Framework_AssertionFailedError to mark the special + * case of a skipped 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 3.0.0 + */ +class PHPUnit2_Framework_SkippedTestError extends PHPUnit2_Framework_AssertionFailedError implements PHPUnit2_Framework_SkippedTest +{ +} + +} + +/* + * 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..82541d6fe90 --- /dev/null +++ b/Framework/Test.php @@ -0,0 +1,89 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!interface_exists('PHPUnit2_Framework_Test')) { + +/** + * 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 extends Countable +{ + /** + * 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(PHPUnit2_Framework_TestResult $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..5add72a6631 --- /dev/null +++ b/Framework/TestCase.php @@ -0,0 +1,473 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!class_exists('PHPUnit2_Framework_TestCase')) { + +/** + * 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, PHPUnit2_Framework_SelfDescribing +{ + /** + * The name of the test case. + * + * @var string + * @access private + */ + private $name = NULL; + + /** + * @var Array + * @access private + */ + private $iniSettings = Array(); + + /** + * @var Array + * @access private + */ + private $mockObjects = Array(); + + /** + * 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 count() + { + 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 InvalidArgumentException + * @access public + */ + public function run(PHPUnit2_Framework_TestResult $result = NULL) + { + if ($result === NULL) { + $result = $this->createResult(); + } + + $result->run($this); + + return $result; + } + + /** + * Runs the bare test sequence. + * + * @access public + */ + public function runBare() + { + // Workaround for missing "finally". + $catchedException = NULL; + + // Set up the fixture. + $this->setUp(); + + // Run the test. + try { + $this->runTest(); + + // Verify Mock Object conditions. + foreach ($this->mockObjects as $mockObject) { + $mockObject->verify(); + } + + $this->mockObjects = Array(); + } + + catch (Exception $e) { + $catchedException = $e; + } + + // Tear down the fixture. + $this->tearDown(); + + // Clean up INI settings. + foreach ($this->iniSettings as $varName => $oldValue) { + ini_set($varName, $oldValue); + } + + $this->iniSettings = Array(); + + // 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; + } + + /** + * This method is a wrapper for the ini_set() function that automatically + * resets the modified php.ini setting to its original value after the + * test is run. + * + * @param string $varName + * @param string $newValue + * @throws InvalidArgumentException + * @throws RuntimeException + * @access protected + * @since Method available since Release 3.0.0 + */ + protected function iniSet($varName, $newValue) + { + if (!is_string($varName) || !is_string($newValue)) { + throw new InvalidArgumentException; + } + + $currentValue = ini_set($varName, $newValue); + + if ($currentValue !== FALSE) { + $this->iniSettings[$varName] = $currentValue; + } else { + throw new RuntimeException; + } + } + + /** + * Returns a mock object for the specified class. + * + * @param string $className + * @param array $methods + * @param array $arguments + * @param string $mockClassName + * @return object + * @access protected + * @since Method available since Release 3.0.0 + */ + protected function getMock($className, Array $methods = array(), Array $arguments = array(), $mockClassName = '') + { + if (!is_string($className) || !is_string($mockClassName)) { + throw new InvalidArgumentException; + } + + $mock = PHPUnit2_Extensions_MockObject_Mock::generate($className, $methods, $mockClassName); + $mockClass = new ReflectionClass($mock->mockClassName); + $mockObject = $mockClass->newInstanceArgs($arguments); + + $this->mockObjects[] = $mockObject; + + return $mockObject; + } + + /** + * + * + * @return PHPUnit2_Extensions_MockObject_Matcher_InvokedCount + * @access protected + * @since Method available since Release 3.0.0 + */ + protected function never() + { + return new PHPUnit2_Extensions_MockObject_Matcher_InvokedCount(0); + } + + /** + * + * + * @return PHPUnit2_Extensions_MockObject_Matcher_InvokedAtLeastOnce + * @access protected + * @since Method available since Release 3.0.0 + */ + protected function atLeastOnce() + { + return new PHPUnit2_Extensions_MockObject_Matcher_InvokedAtLeastOnce; + } + + /** + * + * + * @return PHPUnit2_Extensions_MockObject_Matcher_InvokedCount + * @access protected + * @since Method available since Release 3.0.0 + */ + protected function once() + { + return new PHPUnit2_Extensions_MockObject_Matcher_InvokedCount(1); + } + + /** + * + * + * @param integer $count + * @return PHPUnit2_Extensions_MockObject_Matcher_InvokedCount + * @access protected + * @since Method available since Release 3.0.0 + */ + protected function exactly($count) + { + return new PHPUnit2_Extensions_MockObject_Matcher_InvokedCount($count); + } + + /** + * + * + * @param integer $index + * @return PHPUnit2_Extensions_MockObject_Matcher_InvokedAtIndex + * @access protected + * @since Method available since Release 3.0.0 + */ + protected function at($index) + { + return new PHPUnit2_Extensions_MockObject_Matcher_InvokedAtIndex($index); + } + + /** + * + * + * @param mixed $value + * @return PHPUnit2_Extensions_MockObject_Stub_Return + * @access protected + * @since Method available since Release 3.0.0 + */ + protected function returnValue($value) + { + return new PHPUnit2_Extensions_MockObject_Stub_Return($value); + } + + /** + * + * + * @param mixed $value, ... + * @return PHPUnit2_Extensions_MockObject_Stub_ConsecutiveCalls + * @access protected + * @since Method available since Release 3.0.0 + */ + protected function onConsecutiveCalls() + { + $args = func_get_args(); + + return new PHPUnit2_Extensions_MockObject_Stub_ConsecutiveCalls($args); + } + + /** + * 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..ea822263717 --- /dev/null +++ b/Framework/TestFailure.php @@ -0,0 +1,166 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!class_exists('PHPUnit2_Framework_TestFailure')) { + +/** + * 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..f47a28a3cfd --- /dev/null +++ b/Framework/TestListener.php @@ -0,0 +1,151 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!interface_exists('PHPUnit2_Framework_TestListener')) { + +/** + * 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); + + /** + * Skipped test. + * + * @param PHPUnit2_Framework_Test $test + * @param Exception $e + * @access public + * @since Method available since Release 3.0.0 + */ + public function addSkippedTest(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..a8cd91f61ce --- /dev/null +++ b/Framework/TestResult.php @@ -0,0 +1,595 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/ErrorHandler.php'; +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Util/Printer.php'; +require_once 'PHPUnit2/Util/Test.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!class_exists('PHPUnit2_Framework_TestResult')) { + +/** + * 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 implements Countable +{ + /** + * @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 $skipped = array(); + + /** + * @var array + * @access protected + */ + protected $listeners = array(); + + /** + * @var integer + * @access protected + */ + protected $runTests = 0; + + /** + * @var PHPUnit2_Framework_TestSuite + * @access protected + */ + protected $topTestSuite = NULL; + + /** + * 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) + { + $max = count($this->listeners); + + for ($i = 0; $i < $max; $i++) { + if ($this->listeners[$i] === $listener) { + unset($this->listeners[$i]); + } + } + } + + /** + * Flushes all flushable TestListeners. + * + * @access public + * @since Method available since Release 3.0.0 + */ + public function flushListeners() + { + foreach ($this->listeners as $listener) { + if ($listener instanceof PHPUnit2_Util_Printer) { + $listener->flush(); + } + } + } + + /** + * 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 if ($e instanceof PHPUnit2_Framework_SkippedTest) { + $this->skipped[] = new PHPUnit2_Framework_TestFailure($test, $e); + + foreach ($this->listeners as $listener) { + $listener->addSkippedTest($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 if ($e instanceof PHPUnit2_Framework_SkippedTest) { + $this->skipped[] = new PHPUnit2_Framework_TestFailure($test, $e); + + foreach ($this->listeners as $listener) { + $listener->addSkippedTest($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) + { + if ($this->topTestSuite === NULL) { + $this->topTestSuite = $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 += count($test); + + 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 count($this->notImplemented); + } + + /** + * Returns an Enumeration for the incomplete tests. + * + * @return array + * @access public + */ + public function notImplemented() + { + return $this->notImplemented; + } + + /** + * Returns TRUE if no test has been skipped. + * + * @return boolean + * @access public + * @since Method available since Release 3.0.0 + */ + public function noneSkipped() + { + return $this->skippedCount() == 0; + } + + /** + * Gets the number of skipped tests. + * + * @return integer + * @access public + * @since Method available since Release 3.0.0 + */ + public function skippedCount() + { + return count($this->skipped); + } + + /** + * Returns an Enumeration for the skipped tests. + * + * @return array + * @access public + * @since Method available since Release 3.0.0 + */ + public function skipped() + { + return $this->skipped; + } + + /** + * Gets the number of detected errors. + * + * @return integer + * @access public + */ + public function errorCount() + { + return count($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 count($this->failures); + } + + /** + * Returns an Enumeration for the failures. + * + * @return array + * @access public + */ + public function failures() + { + return $this->failures; + } + + /** + * Returns the (top) test suite. + * + * @return PHPUnit2_Framework_TestSuite + * @access public + * @since Method available since Release 3.0.0 + */ + public function topTestSuite() + { + return $this->topTestSuite; + } + + /** + * Enables or disables the collection of Code Coverage information. + * + * @param boolean $flag + * @throws InvalidArgumentException + * @access public + * @since Method available since Release 2.3.0 + */ + public function collectCodeCoverageInformation($flag) + { + if (is_bool($flag)) { + $this->collectCodeCoverageInformation = $flag; + } else { + throw new InvalidArgumentException; + } + } + + /** + * Returns Code Coverage data per test case. + * + * Format of the result array: + * + * + * array( + * array( + * 'test' => PHPUnit2_Framework_Test + * 'files' => array( + * "/tested/code.php" => array( + * linenumber => flag + * ) + * ) + * ) + * ) + * + * + * flag < 0: Line is executable but was not executed. + * flag > 0: Line was executed. + * + * @param boolean $filterTests + * @param boolean $filterPHPUnit + * @return array + * @access public + */ + public function getCodeCoverageInformation($filterTests = TRUE, $filterPHPUnit = TRUE) + { + return PHPUnit2_Util_Filter::getFilteredCodeCoverage( + $this->codeCoverageInformation, + $filterTests, + $filterPHPUnit + ); + } + + /** + * Runs a TestCase. + * + * @param PHPUnit2_Framework_Test $test + * @access public + */ + public function run(PHPUnit2_Framework_Test $test) + { + $this->startTest($test); + + $errorHandlerSet = FALSE; + $oldErrorHandler = set_error_handler('PHPUnit2_Util_ErrorHandler', E_USER_ERROR); + + if ($oldErrorHandler === NULL) { + $errorHandlerSet = TRUE; + } else { + restore_error_handler(); + } + + $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[] = array( + 'test' => $test, + 'files' => xdebug_get_code_coverage() + ); + + xdebug_stop_code_coverage(); + } + + if ($errorHandlerSet === TRUE) { + restore_error_handler(); + } + + $this->endTest($test); + } + + /** + * Gets the number of run tests. + * + * @return integer + * @access public + */ + public function count() + { + 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..41c13956001 --- /dev/null +++ b/Framework/TestSuite.php @@ -0,0 +1,606 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Runner/BaseTestRunner.php'; +require_once 'PHPUnit2/Util/Fileloader.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!class_exists('PHPUnit2_Framework_TestSuite')) { + +/** + * 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, PHPUnit2_Framework_SelfDescribing +{ + /** + * 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(); + + /** + * The number of tests in the test suite. + * + * @var integer + * @access private + */ + private $numTests = -1; + + /** + * 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 InvalidArgumentException + * @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 InvalidArgumentException; + } + + PHPUnit2_Util_Filter::addFileToFilter( + realpath($theClass->getFilename()), + 'TESTS' + ); + + 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; + } + + $names = array(); + + foreach ($theClass->getMethods() 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; + $this->numTests = -1; + } + + /** + * 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)); + } + + $this->numTests = -1; + } + + /** + * 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 InvalidArgumentException + * @access public + * @since Method available since Release 2.3.0 + * @author Stefano F. Rausch + */ + public function addTestFile($filename) + { + if (!is_string($filename)) { + throw new InvalidArgumentException; + } + + if (!file_exists($filename)) { + $includePaths = PHPUnit2_Util_Fileloader::getIncludePaths(); + + foreach ($includePaths as $includePath) { + $file = $includePath . DIRECTORY_SEPARATOR . $filename; + + if (file_exists($file)) { + $filename = $file; + break; + } + } + } + + $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) + ); + } + + $this->numTests = -1; + } + + /** + * Wrapper for addTestFile() that adds multiple test files. + * + * @param Array $filenames + * @throws InvalidArgumentException + * @access public + * @since Method available since Release 2.3.0 + */ + public function addTestFiles(Array $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 count() + { + if ($this->numTests > -1) { + return $this->numTests; + } + + $this->numTests = 0; + + foreach ($this->tests as $test) { + $this->numTests += count($test); + } + + return $this->numTests; + } + + /** + * @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 (count($parameters) == 0) { + $test = $theClass->newInstance(); + + if ($test instanceof PHPUnit2_Framework_TestCase) { + $test->setName($name); + } + } + + else if (count($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 InvalidArgumentException + * @access public + */ + public function run(PHPUnit2_Framework_TestResult $result = NULL) + { + if ($result === NULL) { + $result = $this->createResult(); + } + + $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 count($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, Array &$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) + { + 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..ca1819020bf --- /dev/null +++ b/Framework/Warning.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +if (!class_exists('PHPUnit2_Framework_Warning')) { + +/** + * 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..48b877a32d1 --- /dev/null +++ b/Runner/BaseTestRunner.php @@ -0,0 +1,312 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Runner/StandardTestSuiteLoader.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * 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_PASSED = 0; + const STATUS_ERROR = 1; + const STATUS_FAILURE = 2; + const STATUS_INCOMPLETE = 3; + const STATUS_SKIPPED = 4; + 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); + } + + /** + * Skipped test. + * + * @param PHPUnit2_Framework_Test $test + * @param Exception $e + * @access public + * @since Method available since Release 3.0.0 + */ + public function addSkippedTest(PHPUnit2_Framework_Test $test, Exception $e) + { + $this->testFailed(self::STATUS_SKIPPED, $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 + */ + abstract protected 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 + */ + abstract public function testStarted($testName); + + /** + * A test ended. + * + * @param string $testName + * @access public + * @abstract + */ + abstract public function testEnded($testName); + + /** + * A test failed. + * + * @param integer $status + * @param PHPUnit2_Framework_Test $test + * @param PHPUnit2_Framework_AssertionFailedError $e + * @access public + * @abstract + */ + abstract public 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..a1477da43af --- /dev/null +++ b/Runner/IncludePathTestCollector.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.1.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Runner/TestCollector.php'; +require_once 'PHPUnit2/Runner/TestFilterIterator.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * 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 +{ + /** + * @var string + * @access private + */ + private $filterIterator = NULL; + + /** + * @return array + * @access public + */ + public function collectTests() + { + $includePathsIterator = new AppendIterator; + $result = array(); + + $includePaths = PHPUnit2_Util_Fileloader::getIncludePaths(); + + foreach ($includePaths as $includePath) { + $includePathsIterator->append( + new RecursiveIteratorIterator( + new RecursiveDirectoryIterator($includePath) + ) + ); + } + + $filterIterator = new PHPUnit2_Runner_TestFilterIterator( + $includePathsIterator + ); + + if ($this->filterIterator !== NULL) { + $class = new ReflectionClass($this->filterIterator); + $filterIterator = $class->newInstance($filterIterator); + } + + foreach ($filterIterator as $file) { + $result[] = $file; + } + + return $result; + } + + /** + * Adds a FilterIterator to filter the source files to be collected. + * + * @param string $filterIterator + * @throws InvalidArgumentException + * @access public + */ + public function setFilterIterator($filterIterator) + { + if (is_string($filterIterator) && class_exists($filterIterator)) { + try { + $class = new ReflectionClass($filterIterator); + + if ($class->isSubclassOf('FilterIterator')) { + $this->filterIterator = $filterIterator; + } + } + + catch (ReflectionException $e) { + throw new InvalidArgumentException; + } + } else { + throw new InvalidArgumentException; + } + } +} + +/* + * 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..0f9853c149a --- /dev/null +++ b/Runner/StandardTestSuiteLoader.php @@ -0,0 +1,130 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Runner/TestSuiteLoader.php'; +require_once 'PHPUnit2/Util/Fileloader.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * 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 RuntimeException + * @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)) { + $includePaths = PHPUnit2_Util_Fileloader::getIncludePaths(); + + 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 RuntimeException( + 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..30f1ba5dae2 --- /dev/null +++ b/Runner/TestCollector.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * 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/TestFilterIterator.php b/Runner/TestFilterIterator.php new file mode 100644 index 00000000000..af964f1afa3 --- /dev/null +++ b/Runner/TestFilterIterator.php @@ -0,0 +1,89 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, '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 3.0.0 + */ + +class PHPUnit2_Runner_TestFilterIterator extends FilterIterator +{ + /** + * Considers a file to contain a test class when its name ends with + * "Test.php". + * + * @param string $classFileName + * @return boolean + * @access public + */ + public function accept() + { + return substr($this->getInnerIterator()->current(), -8) == 'Test.php'; + } +} + +/* + * 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..bdefdb58a8a --- /dev/null +++ b/Runner/TestSuiteLoader.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * 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..38d892e2236 --- /dev/null +++ b/Runner/Version.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * 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/.cvsignore b/Samples/BankAccount/.cvsignore new file mode 100644 index 00000000000..53752db253e --- /dev/null +++ b/Samples/BankAccount/.cvsignore @@ -0,0 +1 @@ +output diff --git a/Samples/BankAccount/BankAccount.php b/Samples/BankAccount/BankAccount.php new file mode 100644 index 00000000000..1dca647afd9 --- /dev/null +++ b/Samples/BankAccount/BankAccount.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 SVN: $Id$ + * @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 InvalidArgumentException + * @access public + */ + public function setBalance($balance) + { + if ($balance >= 0) { + $this->balance = $balance; + } else { + throw new InvalidArgumentException; + } + } + + /** + * Deposits an amount of money to the bank account. + * + * @param float $balance + * @throws InvalidArgumentException + * @access public + */ + public function depositMoney($amount) + { + if ($amount >= 0) { + $this->balance += $amount; + } else { + throw new InvalidArgumentException; + } + } + + /** + * Withdraws an amount of money from the bank account. + * + * @param float $balance + * @throws InvalidArgumentException + * @access public + */ + public function withdrawMoney($amount) + { + if ($amount >= 0 && $this->balance >= $amount) { + $this->balance -= $amount; + } else { + throw new InvalidArgumentException; + } + } +} + +/* + * 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..f0cfffee24c --- /dev/null +++ b/Samples/BankAccount/BankAccountTest.php @@ -0,0 +1,156 @@ +. + * 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 SVN: $Id$ + * @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 (InvalidArgumentException $e) { + return; + } + + $this->fail(); + } + + /** + * Asserts that the balance cannot become negative. + * + * @access public + */ + public function testBalanceCannotBecomeNegative2() + { + try { + $this->ba->depositMoney(-1); + } + + catch (InvalidArgumentException $e) { + return; + } + + $this->fail(); + } + + /** + * Asserts that the balance cannot become negative. + * + * @access public + */ + public function testBalanceCannotBecomeNegative3() + { + try { + $this->ba->setBalance(-1); + } + + catch (InvalidArgumentException $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/.cvsignore b/Samples/Money/.cvsignore new file mode 100644 index 00000000000..53752db253e --- /dev/null +++ b/Samples/Money/.cvsignore @@ -0,0 +1 @@ +output diff --git a/Samples/Money/IMoney.php b/Samples/Money/IMoney.php new file mode 100644 index 00000000000..0c989b71963 --- /dev/null +++ b/Samples/Money/IMoney.php @@ -0,0 +1,83 @@ +. + * 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 SVN: $Id$ + * @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..7f4d152a7c3 --- /dev/null +++ b/Samples/Money/Money.php @@ -0,0 +1,161 @@ +. + * 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 SVN: $Id$ + * @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..713e7582c50 --- /dev/null +++ b/Samples/Money/MoneyBag.php @@ -0,0 +1,260 @@ +. + * 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 SVN: $Id$ + * @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); + $max = count($keys); + + for ($i = 0; $i < $max; $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 (count($anObject->monies()) != count($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 count($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 (count($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..8f9c4bde399 --- /dev/null +++ b/Samples/Money/MoneyTest.php @@ -0,0 +1,258 @@ +. + * 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 SVN: $Id$ + * @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')); + + $this->assertTrue($expected->equals($this->fMB1->multiply(2))); + $this->assertTrue($this->fMB1->equals($this->fMB1->multiply(1))); + $this->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')); + $this->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')); + $this->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')); + $this->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')); + $this->assertTrue($expected->equals($this->fMB1->add($this->fMB2))); + } + + public function testIsZero() + { + //$this->assertTrue($this->fMB1->subtract($this->fMB1)->isZero()); + $this->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); + $this->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); + $this->assertFalse($bag1->equals($bag2)); + } + + public function testMoneyBagEquals() + { + $this->assertTrue(!$this->fMB1->equals(NULL)); + + $this->assertTrue($this->fMB1->equals($this->fMB1)); + $equal = MoneyBag::create(new Money(12, 'EUR'), new Money(7, 'USD')); + $this->assertTrue($this->fMB1->equals($equal)); + $this->assertTrue(!$this->fMB1->equals($this->f12EUR)); + $this->assertTrue(!$this->f12EUR->equals($this->fMB1)); + $this->assertTrue(!$this->fMB1->equals($this->fMB2)); + } + + public function testMoneyBagHash() + { + $equal = MoneyBag::create(new Money(12, 'EUR'), new Money(7, 'USD')); + $this->assertEquals($this->fMB1->hashCode(), $equal->hashCode()); + } + + public function testMoneyEquals() + { + $this->assertTrue(!$this->f12EUR->equals(NULL)); + $equalMoney = new Money(12, 'EUR'); + $this->assertTrue($this->f12EUR->equals($this->f12EUR)); + $this->assertTrue($this->f12EUR->equals($equalMoney)); + $this->assertEquals($this->f12EUR->hashCode(), $equalMoney->hashCode()); + $this->assertFalse($this->f12EUR->equals($this->f14EUR)); + } + + public function testMoneyHash() + { + $this->assertNotNull($this->f12EUR); + $equal= new Money(12, 'EUR'); + $this->assertEquals($this->f12EUR->hashCode(), $equal->hashCode()); + } + + public function testSimplify() + { + $money = MoneyBag::create(new Money(26, 'EUR'), new Money(28, 'EUR')); + $this->assertTrue($money->equals(new Money(54, 'EUR'))); + } + + public function testNormalize2() + { + // {[12 EUR][7 USD]} - [12 EUR] == [7 USD] + $expected = new Money(7, 'USD'); + $this->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'); + $this->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'); + $this->assertTrue($expected->equals($this->f12EUR->subtract($ms1))); + } + + public function testPrint() + { + $this->assertEquals('[12 EUR]', $this->f12EUR->toString()); + } + + public function testSimpleAdd() + { + // [12 EUR] + [14 EUR] == [26 EUR] + $expected = new Money(26, 'EUR'); + $this->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')); + $this->assertTrue($expected->equals($this->f14EUR->add($this->fMB1))); + } + + public function testSimpleMultiply() + { + // [14 EUR] *2 == [28 EUR] + $expected = new Money(28, 'EUR'); + $this->assertTrue($expected->equals($this->f14EUR->multiply(2))); + } + + public function testSimpleNegate() + { + // [14 EUR] negate == [-14 EUR] + $expected = new Money(-14, 'EUR'); + $this->assertTrue($expected->equals($this->f14EUR->negate())); + } + + public function testSimpleSubtract() + { + // [14 EUR] - [12 EUR] == [2 EUR] + $expected = new Money(2, 'EUR'); + $this->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..23253fc13e7 --- /dev/null +++ b/Tests/AllTests.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 SVN: $Id$ + * @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'); + chdir(dirname(__FILE__)); +} + +if (!defined('PHPUnit2_INSIDE_OWN_TESTSUITE')) { + define('PHPUnit2_INSIDE_OWN_TESTSUITE', TRUE); +} + +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('PHPUnit2'); + + $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/Extensions/AllTests.php b/Tests/Extensions/AllTests.php new file mode 100644 index 00000000000..60d9b6a39d8 --- /dev/null +++ b/Tests/Extensions/AllTests.php @@ -0,0 +1,114 @@ +. + * 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 SVN: $Id$ + * @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'); + chdir(dirname(dirname(__FILE__))); +} + +if (!defined('PHPUnit2_INSIDE_OWN_TESTSUITE')) { + define('PHPUnit2_INSIDE_OWN_TESTSUITE', TRUE); +} + +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/MockObjectTest.php'; +require_once 'Extensions/OutputTestCaseTest.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('PHPUnit2_Extensions'); + + $suite->addTestSuite('Extensions_ExceptionTestCaseTest'); + $suite->addTestSuite('Extensions_ExtensionTest'); + $suite->addTestSuite('Extensions_MockObjectTest'); + $suite->addTestSuite('Extensions_OutputTestCaseTest'); + $suite->addTestSuite('Extensions_PerformanceTestCaseTest'); + $suite->addTestSuite('Extensions_RepeatedTestTest'); + + 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..aac2ebcd3b1 --- /dev/null +++ b/Tests/Extensions/ExceptionTestCaseTest.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; + +require_once '_files/ThrowExceptionTestCase.php'; +require_once '_files/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, count($result)); + $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, count($result)); + } + + public function testWrongException() + { + $test = new ThrowExceptionTestCase('test'); + $test->setExpectedException('RuntimeException'); + + $result = $test->run(); + + $this->assertEquals(1, $result->errorCount()); + $this->assertEquals(1, count($result)); + } +} + +/* + * 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..177b9a13d6c --- /dev/null +++ b/Tests/Extensions/ExtensionTest.php @@ -0,0 +1,124 @@ +. + * 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 SVN: $Id$ + * @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 '_files/Error.php'; +require_once '_files/Failure.php'; +require_once '_files/Success.php'; +require_once '_files/TornDown6.php'; +require_once '_files/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/MockObjectTest.php b/Tests/Extensions/MockObjectTest.php new file mode 100644 index 00000000000..39de3af6328 --- /dev/null +++ b/Tests/Extensions/MockObjectTest.php @@ -0,0 +1,112 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; + +require_once '_files/AnInterface.php'; + +/** + * + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @author Patrick Müller + * @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 3.0.0 + */ +class Extensions_MockObjectTest extends PHPUnit2_Framework_TestCase +{ + public function testMockedMethodIsCalledOnceWithCorrectParameter() + { + $mock = PHPUnit2_Extensions_MockObject_Mock::generate('AnInterface'); + $mockClass = new ReflectionClass($mock->mockClassName); + $mockObject = $mockClass->newInstance(); + + $mockObject->expects($this->once()) + ->method('doSomething') + ->with($this->equalTo('something') + ); + + $mockObject->doSomething('something'); + } + + public function testMockedMethodIsCalledOnceWithWrongParameter() + { + $mock = PHPUnit2_Extensions_MockObject_Mock::generate('AnInterface'); + $mockClass = new ReflectionClass($mock->mockClassName); + $mockObject = $mockClass->newInstance(); + + $mockObject->expects($this->once()) + ->method('doSomething') + ->with($this->equalTo('something') + ); + + try { + $mockObject->doSomething('anything'); + } + + 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/Tests/Extensions/OutputTestCaseTest.php b/Tests/Extensions/OutputTestCaseTest.php new file mode 100644 index 00000000000..78172521cf9 --- /dev/null +++ b/Tests/Extensions/OutputTestCaseTest.php @@ -0,0 +1,111 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; + +require_once '_files/OutputTestCase.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 3.0.0 + */ +class Extensions_OutputTestCaseTest extends PHPUnit2_Framework_TestCase +{ + public function testExpectOutputStringFooActualFoo() + { + $test = new OutputTestCase('testExpectOutputStringFooActualFoo'); + $result = $test->run(); + + $this->assertEquals(1, count($result)); + $this->assertTrue($result->wasSuccessful()); + } + + public function testExpectOutputStringFooActualBar() + { + $test = new OutputTestCase('testExpectOutputStringFooActualBar'); + $result = $test->run(); + + $this->assertEquals(1, count($result)); + $this->assertFalse($result->wasSuccessful()); + } + + public function testExpectOutputRegexFooActualFoo() + { + $test = new OutputTestCase('testExpectOutputRegexFooActualFoo'); + $result = $test->run(); + + $this->assertEquals(1, count($result)); + $this->assertTrue($result->wasSuccessful()); + } + + public function testExpectOutputRegexFooActualBar() + { + $test = new OutputTestCase('testExpectOutputRegexFooActualBar'); + $result = $test->run(); + + $this->assertEquals(1, count($result)); + $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..7ea5d9c014d --- /dev/null +++ b/Tests/Extensions/PerformanceTestCaseTest.php @@ -0,0 +1,95 @@ +. + * 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 SVN: $Id$ + * @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 '_files/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..befa2ba43a2 --- /dev/null +++ b/Tests/Extensions/RepeatedTestTest.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 SVN: $Id$ + * @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 '_files/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, count($test)); + + $result = $test->run(); + $this->assertEquals(2, count($result)); + } + + public function testRepeatedMoreThanOnce() + { + $test = new PHPUnit2_Extensions_RepeatedTest($this->suite, 3); + $this->assertEquals(6, count($test)); + + $result = $test->run(); + $this->assertEquals(6, count($result)); + } + + public function testRepeatedZero() + { + $test = new PHPUnit2_Extensions_RepeatedTest($this->suite, 0); + $this->assertEquals(0, count($test)); + + $result = $test->run(); + $this->assertEquals(0, count($result)); + } + + 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/Framework/AllTests.php b/Tests/Framework/AllTests.php new file mode 100644 index 00000000000..ecb974a1277 --- /dev/null +++ b/Tests/Framework/AllTests.php @@ -0,0 +1,114 @@ +. + * 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 SVN: $Id$ + * @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'); + chdir(dirname(dirname(__FILE__))); +} + +if (!defined('PHPUnit2_INSIDE_OWN_TESTSUITE')) { + define('PHPUnit2_INSIDE_OWN_TESTSUITE', TRUE); +} + +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('PHPUnit2_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'); + + 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..5e28ce8a9e7 --- /dev/null +++ b/Tests/Framework/AssertTest.php @@ -0,0 +1,1237 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; + +require_once '_files/ClassWithNonPublicAttributes.php'; +require_once '_files/SampleClass.php'; +require_once '_files/TestIterator.php'; +require_once '_files/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_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 testAssertArrayHasIntegerKey() + { + $this->assertArrayHasKey(0, array('foo')); + + try { + $this->assertArrayHasKey(1, array('foo')); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertArrayNotHasIntegerKey() + { + $this->assertArrayNotHasKey(1, array('foo')); + + try { + $this->assertArrayNotHasKey(0, array('foo')); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertArrayHasStringKey() + { + $this->assertArrayHasKey('foo', array('foo' => 'bar')); + + try { + $this->assertArrayHasKey('bar', array('foo' => 'bar')); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertArrayNotHasStringKey() + { + $this->assertArrayNotHasKey('bar', array('foo' => 'bar')); + + try { + $this->assertArrayNotHasKey('foo', array('foo' => '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(1, 2)), array('a', 'b' => array(1, 2))); + + try { + $this->assertEquals(array('a', 'b' => array(1, 2)), array('a', 'b' => array(2, 1))); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotEqualsArray() + { + $this->assertNotEquals(array('a', 'b' => array(1, 2)), array('a', 'b' => array(2, 1))); + + try { + $this->assertNotEquals(array('a', 'b' => array(1, 2)), array('a', 'b' => array(1, 2))); + } + + 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() + { + $a = new SampleClass( 4, 8, 15); + $b = new SampleClass(16, 23, 42); + + $this->assertEquals($a, $a); + + try { + $this->assertEquals($a, $b); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotEqualsObject() + { + $a = new SampleClass( 4, 8, 15); + $b = new SampleClass(16, 23, 42); + + $this->assertNotEquals($a, $b); + + try { + $this->assertNotEquals($a, $a); + } + + 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 testAssertFileExists() + { + $this->assertFileExists(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'AllTests.php'); + + try { + $this->assertFileExists(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'NotExisting'); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertFileNotExists() + { + $this->assertFileNotExists(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'NotExisting'); + + try { + $this->assertFileNotExists(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'AllTests.php'); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertObjectHasAttribute() + { + $o = new WasRun('runTest'); + + $this->assertObjectHasAttribute('wasRun', $o); + + try { + $this->assertObjectHasAttribute('foo', $o); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertObjectNotHasAttribute() + { + $o = new WasRun('runTest'); + + $this->assertObjectNotHasAttribute('foo', $o); + + try { + $this->assertObjectNotHasAttribute('wasRun', $o); + } + + 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 testAssertRegExp() + { + $this->assertRegExp('/foo/', 'foobar'); + + try { + $this->assertRegExp('/foo/', 'bar'); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotRegExp() + { + $this->assertNotRegExp('/foo/', 'bar'); + + try { + $this->assertNotRegExp('/foo/', 'foobar'); + } + + 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 testAssertTypeArray() + { + $this->assertType('array', array()); + + try { + $this->assertType('array', 'string'); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotTypeArray() + { + $this->assertNotType('array', 'string'); + + try { + $this->assertNotType('array', array()); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertTypeBool() + { + $this->assertType('bool', TRUE); + + try { + $this->assertType('bool', 'string'); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotTypeBool() + { + $this->assertNotType('bool', 'string'); + + try { + $this->assertNotType('bool', TRUE); + } + + 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 testAssertTypeFloat() + { + $this->assertType('float', 22.04); + + try { + $this->assertType('integer', 'string'); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotTypeFloat() + { + $this->assertNotType('float', 'string'); + + try { + $this->assertNotType('float', 22.04); + } + + 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 testAssertTypeNull() + { + $this->assertType('null', NULL); + + try { + $this->assertType('null', 'string'); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotTypeNull() + { + $this->assertNotType('null', 'string'); + + try { + $this->assertNotType('null', NULL); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertTypeObject() + { + $this->assertType('object', new stdClass); + + try { + $this->assertType('object', 'string'); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertNotTypeObject() + { + $this->assertNotType('object', 'string'); + + try { + $this->assertNotType('object', new stdClass); + } + + 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(); + } + + public function testGetAttribute() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertEquals('foo', $this->getAttribute($obj, 'publicAttribute')); + $this->assertEquals('bar', $this->getAttribute($obj, 'protectedAttribute')); + $this->assertEquals('baz', $this->getAttribute($obj, 'privateAttribute')); + } + + public function testAssertPublicAttributeContains() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertAttributeContains('foo', 'publicArray', $obj); + + try { + $this->assertAttributeContains('bar', 'publicArray', $obj); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertPublicAttributeNotContains() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertAttributeNotContains('bar', 'publicArray', $obj); + + try { + $this->assertAttributeNotContains('foo', 'publicArray', $obj); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertProtectedAttributeContains() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertAttributeContains('bar', 'protectedArray', $obj); + + try { + $this->assertAttributeContains('foo', 'protectedArray', $obj); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertProtectedAttributeNotContains() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertAttributeNotContains('foo', 'protectedArray', $obj); + + try { + $this->assertAttributeNotContains('bar', 'protectedArray', $obj); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertPrivateAttributeContains() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertAttributeContains('baz', 'privateArray', $obj); + + try { + $this->assertAttributeContains('foo', 'privateArray', $obj); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertPrivateAttributeNotContains() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertAttributeNotContains('foo', 'privateArray', $obj); + + try { + $this->assertAttributeNotContains('baz', 'privateArray', $obj); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertPublicAttributeEquals() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertAttributeEquals('foo', 'publicAttribute', $obj); + + try { + $this->assertAttributeEquals('bar', 'publicAttribute', $obj); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertPublicAttributeNotEquals() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertAttributeNotEquals('bar', 'publicAttribute', $obj); + + try { + $this->assertAttributeNotEquals('foo', 'publicAttribute', $obj); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertProtectedAttributeEquals() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertAttributeEquals('bar', 'protectedAttribute', $obj); + + try { + $this->assertAttributeEquals('foo', 'protectedAttribute', $obj); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertProtectedAttributeNotEquals() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertAttributeNotEquals('foo', 'protectedAttribute', $obj); + + try { + $this->assertAttributeNotEquals('bar', 'protectedAttribute', $obj); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertPrivateAttributeEquals() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertAttributeEquals('baz', 'privateAttribute', $obj); + + try { + $this->assertAttributeEquals('foo', 'privateAttribute', $obj); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testAssertPrivateAttributeNotEquals() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertAttributeNotEquals('foo', 'privateAttribute', $obj); + + try { + $this->assertAttributeNotEquals('baz', 'privateAttribute', $obj); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testObjectHasPublicAttribute() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertObjectHasAttribute('publicAttribute', $obj); + + try { + $this->assertObjectHasAttribute('attribute', $obj); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testObjectNotHasPublicAttribute() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertObjectNotHasAttribute('attribute', $obj); + + try { + $this->assertObjectNotHasAttribute('publicAttribute', $obj); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testObjectHasProtectedAttribute() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertObjectHasAttribute('protectedAttribute', $obj); + + try { + $this->assertObjectHasAttribute('attribute', $obj); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testObjectNotHasProtectedAttribute() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertObjectNotHasAttribute('attribute', $obj); + + try { + $this->assertObjectNotHasAttribute('protectedAttribute', $obj); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testObjectHasPrivateAttribute() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertObjectHasAttribute('privateAttribute', $obj); + + try { + $this->assertObjectHasAttribute('attribute', $obj); + } + + catch (PHPUnit2_Framework_AssertionFailedError $e) { + return; + } + + $this->fail(); + } + + public function testObjectNotHasPrivateAttribute() + { + $obj = new ClassWithNonPublicAttributes; + + $this->assertObjectNotHasAttribute('attribute', $obj); + + try { + $this->assertObjectNotHasAttribute('privateAttribute', $obj); + } + + 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..0d24444f82d --- /dev/null +++ b/Tests/Framework/ComparisonFailureTest.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 SVN: $Id$ + * @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 = PHPUnit2_Framework_ComparisonFailure::diffEqual('a', 'b', 'c'); + + $this->assertEquals( + "c expected string \n difference \n got string ", + $failure->toString() + ); + } + + public function testComparisonErrorStartSame() + { + $failure = PHPUnit2_Framework_ComparisonFailure::diffEqual('ba', 'bc'); + + $this->assertEquals( + "expected string \ndifference < x>\ngot string ", + $failure->toString() + ); + } + + public function testComparisonErrorEndSame() + { + $failure = PHPUnit2_Framework_ComparisonFailure::diffEqual('ab', 'cb'); + + $this->assertEquals( + "expected string \ndifference \ngot string ", + $failure->toString() + ); + } + + public function testComparisonErrorStartAndEndSame() + { + $failure = PHPUnit2_Framework_ComparisonFailure::diffEqual('abc', 'adc'); + + $this->assertEquals( + "expected string \ndifference < x>\ngot string ", + $failure->toString() + ); + } + + public function testComparisonErrorStartSameComplete() + { + $failure = PHPUnit2_Framework_ComparisonFailure::diffEqual('ab', 'abc'); + + $this->assertEquals( + "expected string \ndifference < ?>\ngot string ", + $failure->toString() + ); + } + + public function testComparisonErrorEndSameComplete() + { + $failure = PHPUnit2_Framework_ComparisonFailure::diffEqual('bc', 'abc'); + + $this->assertEquals( + "expected string \ndifference \ngot string ", + $failure->toString() + ); + } + + public function testComparisonErrorOverlapingMatches() + { + $failure = PHPUnit2_Framework_ComparisonFailure::diffEqual('abc', 'abbc'); + + $this->assertEquals( + "expected string \ndifference < x?>\ngot string ", + $failure->toString() + ); + } + + public function testComparisonErrorOverlapingMatches2() + { + $failure = PHPUnit2_Framework_ComparisonFailure::diffEqual('abcdde', 'abcde'); + + $this->assertEquals( + "expected string \ndifference < x?>\ngot string ", + $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..bd6631ebb4e --- /dev/null +++ b/Tests/Framework/SuiteTest.php @@ -0,0 +1,208 @@ +. + * 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 SVN: $Id$ + * @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 '_files/InheritedTestCase.php'; +require_once '_files/NoTestCaseClass.php'; +require_once '_files/NoTestCases.php'; +require_once '_files/NotPublicTestCase.php'; +require_once '_files/NotVoidTestCase.php'; +require_once '_files/OneTestCase.php'; +require_once '_files/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, count($this->result)); + } + + public function testInheritedTests() + { + $suite = new PHPUnit2_Framework_TestSuite( + 'InheritedTestCase' + ); + + $suite->run($this->result); + + $this->assertTrue($this->result->wasSuccessful()); + $this->assertEquals(2, count($this->result)); + } + + 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, count($this->result)); + } + + public function testNoTestCaseClass() + { + $suite = new PHPUnit2_Framework_TestSuite( + 'NoTestCaseClass' + ); + + $suite->run($this->result); + + $this->assertTrue(!$this->result->wasSuccessful()); + $this->assertEquals(1, count($this->result)); + } + + 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, count($this->result)); + } + + public function testNotPublicTestCase() + { + $suite = new PHPUnit2_Framework_TestSuite( + 'NotPublicTestCase' + ); + + $this->assertEquals(2, count($suite)); + } + + public function testNotVoidTestCase() + { + $suite = new PHPUnit2_Framework_TestSuite( + 'NotVoidTestCase' + ); + + $this->assertEquals(1, count($suite)); + } + + 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, count($this->result)); + $this->assertTrue($this->result->wasSuccessful()); + } + + public function testShadowedTests() + { + $suite = new PHPUnit2_Framework_TestSuite( + 'OverrideTestCase' + ); + + $suite->run($this->result); + + $this->assertEquals(1, count($this->result)); + } +} + +/* + * 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..508f38fabe6 --- /dev/null +++ b/Tests/Framework/TestCaseTest.php @@ -0,0 +1,210 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; + +require_once '_files/Error.php'; +require_once '_files/Failure.php'; +require_once '_files/NoArgTestCaseTest.php'; +require_once '_files/SetupFailure.php'; +require_once '_files/Success.php'; +require_once '_files/TearDownFailure.php'; +require_once '_files/TornDown2.php'; +require_once '_files/TornDown3.php'; +require_once '_files/TornDown4.php'; +require_once '_files/TornDown5.php'; +require_once '_files/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, count($result)); + $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, count($result)); + } + + protected function verifyFailure(PHPUnit2_Framework_TestCase $test) + { + $result = $test->run(); + + $this->assertEquals(0, $result->errorCount()); + $this->assertEquals(1, $result->failureCount()); + $this->assertEquals(1, count($result)); + } + + protected function verifySuccess(PHPUnit2_Framework_TestCase $test) + { + $result = $test->run(); + + $this->assertEquals(0, $result->errorCount()); + $this->assertEquals(0, $result->failureCount()); + $this->assertEquals(1, count($result)); + } +} + +/* + * 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..d83adca82f9 --- /dev/null +++ b/Tests/Framework/TestImplementorTest.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 SVN: $Id$ + * @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 '_files/DoubleTestCase.php'; +require_once '_files/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(count($this->test), count($result)); + $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..52f5d2a5c33 --- /dev/null +++ b/Tests/Framework/TestListenerTest.php @@ -0,0 +1,164 @@ +. + * 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 SVN: $Id$ + * @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 '_files/Error.php'; +require_once '_files/Failure.php'; +require_once '_files/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 $skippedCount; + 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 addSkippedTest(PHPUnit2_Framework_Test $test, Exception $e) + { + $this->skippedCount++; + } + + 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->skippedCount = 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/Runner/AllTests.php b/Tests/Runner/AllTests.php new file mode 100644 index 00000000000..c9e9e6891bd --- /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 SVN: $Id$ + * @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'); + chdir(dirname(dirname(__FILE__))); +} + +if (!defined('PHPUnit2_INSIDE_OWN_TESTSUITE')) { + define('PHPUnit2_INSIDE_OWN_TESTSUITE', TRUE); +} + +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('PHPUnit2_Runner'); + + $suite->addTestSuite('Runner_BaseTestRunnerTest'); + + 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..972017ff0f3 --- /dev/null +++ b/Tests/Runner/BaseTestRunnerTest.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework/TestCase.php'; + +require_once '_files/MockRunner.php'; +require_once '_files/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/Util/AllTests.php b/Tests/Util/AllTests.php new file mode 100644 index 00000000000..cf4818ac9c8 --- /dev/null +++ b/Tests/Util/AllTests.php @@ -0,0 +1,103 @@ +. + * 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 SVN: $Id$ + * @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_AllTests::main'); + chdir(dirname(dirname(__FILE__))); +} + +if (!defined('PHPUnit2_INSIDE_OWN_TESTSUITE')) { + define('PHPUnit2_INSIDE_OWN_TESTSUITE', TRUE); +} + +require_once 'PHPUnit2/Framework/TestSuite.php'; +require_once 'PHPUnit2/TextUI/TestRunner.php'; + +require_once 'Util/TestDox/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 Util_AllTests +{ + public static function main() + { + PHPUnit2_TextUI_TestRunner::run(self::suite()); + } + + public static function suite() + { + $suite = new PHPUnit2_Framework_TestSuite('PHPUnit2_Util'); + + $suite->addTest(Util_TestDox_AllTests::suite()); + + return $suite; + } +} + +if (PHPUnit2_MAIN_METHOD == 'Util_AllTests::main') { + Util_AllTests::main(); +} + +/* + * 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..da5c8283fb4 --- /dev/null +++ b/Tests/Util/TestDox/AllTests.php @@ -0,0 +1,103 @@ +. + * 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 SVN: $Id$ + * @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'); + chdir(dirname(dirname(dirname(__FILE__)))); +} + +if (!defined('PHPUnit2_INSIDE_OWN_TESTSUITE')) { + define('PHPUnit2_INSIDE_OWN_TESTSUITE', TRUE); +} + +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_Util_TestDox'); + + $suite->addTestSuite('Util_TestDox_NamePrettifierTest'); + + 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..c00799d0db7 --- /dev/null +++ b/Tests/Util/TestDox/NamePrettifierTest.php @@ -0,0 +1,124 @@ +. + * 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 SVN: $Id$ + * @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/_files/AnInterface.php b/Tests/_files/AnInterface.php new file mode 100644 index 00000000000..d98da35bd82 --- /dev/null +++ b/Tests/_files/AnInterface.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__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 3.0.0 + */ +interface AnInterface +{ + public function doSomething(); +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/_files/ClassWithNonPublicAttributes.php b/Tests/_files/ClassWithNonPublicAttributes.php new file mode 100644 index 00000000000..1ce57b9e232 --- /dev/null +++ b/Tests/_files/ClassWithNonPublicAttributes.php @@ -0,0 +1,83 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__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 3.0.0 + */ +class ClassWithNonPublicAttributes +{ + public $publicAttribute = 'foo'; + protected $protectedAttribute = 'bar'; + private $privateAttribute = 'baz'; + + public $publicArray = array('foo'); + public $protectedArray = array('bar'); + public $privateArray = array('baz'); +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/_files/DoubleTestCase.php b/Tests/_files/DoubleTestCase.php new file mode 100644 index 00000000000..b9b1ef886a2 --- /dev/null +++ b/Tests/_files/DoubleTestCase.php @@ -0,0 +1,98 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__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 + */ +class DoubleTestCase implements PHPUnit2_Framework_Test +{ + private $testCase; + + public function __construct(PHPUnit2_Framework_TestCase $testCase) + { + $this->testCase = $testCase; + } + + public function count() + { + return 2; + } + + public function run(PHPUnit2_Framework_TestResult $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/_files/Error.php b/Tests/_files/Error.php new file mode 100644 index 00000000000..2eff80f0906 --- /dev/null +++ b/Tests/_files/Error.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__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 + */ +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/_files/Failure.php b/Tests/_files/Failure.php new file mode 100644 index 00000000000..4efe80daa1e --- /dev/null +++ b/Tests/_files/Failure.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__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 + */ +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/_files/InheritedTestCase.php b/Tests/_files/InheritedTestCase.php new file mode 100644 index 00000000000..6a69b787456 --- /dev/null +++ b/Tests/_files/InheritedTestCase.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__); + +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/_files/MockRunner.php b/Tests/_files/MockRunner.php new file mode 100644 index 00000000000..75dba2eccd7 --- /dev/null +++ b/Tests/_files/MockRunner.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Runner/BaseTestRunner.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__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 + */ +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/_files/NoArgTestCaseTest.php b/Tests/_files/NoArgTestCaseTest.php new file mode 100644 index 00000000000..6d41d6d1939 --- /dev/null +++ b/Tests/_files/NoArgTestCaseTest.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__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 + */ +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/_files/NoTestCaseClass.php b/Tests/_files/NoTestCaseClass.php new file mode 100644 index 00000000000..6528255e9d0 --- /dev/null +++ b/Tests/_files/NoTestCaseClass.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__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 + */ +class NoTestCaseClass +{ +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/_files/NoTestCases.php b/Tests/_files/NoTestCases.php new file mode 100644 index 00000000000..5b2d4cd4a4d --- /dev/null +++ b/Tests/_files/NoTestCases.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__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 + */ +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/_files/NonStatic.php b/Tests/_files/NonStatic.php new file mode 100644 index 00000000000..1c5047d810c --- /dev/null +++ b/Tests/_files/NonStatic.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__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 + */ +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/_files/NotPublicTestCase.php b/Tests/_files/NotPublicTestCase.php new file mode 100644 index 00000000000..939f3b79e5f --- /dev/null +++ b/Tests/_files/NotPublicTestCase.php @@ -0,0 +1,84 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__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 + */ +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/_files/NotVoidTestCase.php b/Tests/_files/NotVoidTestCase.php new file mode 100644 index 00000000000..48cb3b88f60 --- /dev/null +++ b/Tests/_files/NotVoidTestCase.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__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 + */ +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/_files/OneTestCase.php b/Tests/_files/OneTestCase.php new file mode 100644 index 00000000000..d8cbd4b6bfe --- /dev/null +++ b/Tests/_files/OneTestCase.php @@ -0,0 +1,84 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__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 + */ +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/_files/OutputTestCase.php b/Tests/_files/OutputTestCase.php new file mode 100644 index 00000000000..ce7ea9b28f4 --- /dev/null +++ b/Tests/_files/OutputTestCase.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__); + +require_once 'PHPUnit2/Extensions/OutputTestCase.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 OutputTestCase extends PHPUnit2_Extensions_OutputTestCase +{ + public function testExpectOutputStringFooActualFoo() + { + $this->expectOutputString('foo'); + print 'foo'; + } + + public function testExpectOutputStringFooActualBar() + { + $this->expectOutputString('foo'); + print 'bar'; + } + + public function testExpectOutputRegexFooActualFoo() + { + $this->expectOutputRegex('/foo/'); + print 'foo'; + } + + public function testExpectOutputRegexFooActualBar() + { + $this->expectOutputRegex('/foo/'); + print 'bar'; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/_files/OverrideTestCase.php b/Tests/_files/OverrideTestCase.php new file mode 100644 index 00000000000..954077010ef --- /dev/null +++ b/Tests/_files/OverrideTestCase.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__); + +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($arg = '') + { + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/_files/SampleClass.php b/Tests/_files/SampleClass.php new file mode 100644 index 00000000000..315434d636b --- /dev/null +++ b/Tests/_files/SampleClass.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__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 3.0.0 + */ +class SampleClass +{ + public $a; + protected $b; + private $c; + + public function __construct($a, $b, $c) + { + $this->a = $a; + $this->b = $b; + $this->c = $c; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Tests/_files/SetupFailure.php b/Tests/_files/SetupFailure.php new file mode 100644 index 00000000000..06e0a06fe22 --- /dev/null +++ b/Tests/_files/SetupFailure.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__); + +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/_files/Sleep.php b/Tests/_files/Sleep.php new file mode 100644 index 00000000000..27716922062 --- /dev/null +++ b/Tests/_files/Sleep.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__); + +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/_files/Success.php b/Tests/_files/Success.php new file mode 100644 index 00000000000..6743f295f4e --- /dev/null +++ b/Tests/_files/Success.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__); + +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/_files/TearDownFailure.php b/Tests/_files/TearDownFailure.php new file mode 100644 index 00000000000..8ff592362e2 --- /dev/null +++ b/Tests/_files/TearDownFailure.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__); + +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/_files/TestIterator.php b/Tests/_files/TestIterator.php new file mode 100644 index 00000000000..36d7884b71f --- /dev/null +++ b/Tests/_files/TestIterator.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__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 + */ +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 < count($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/_files/ThrowExceptionTestCase.php b/Tests/_files/ThrowExceptionTestCase.php new file mode 100644 index 00000000000..07968f9e8e1 --- /dev/null +++ b/Tests/_files/ThrowExceptionTestCase.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__); + +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/_files/ThrowNoExceptionTestCase.php b/Tests/_files/ThrowNoExceptionTestCase.php new file mode 100644 index 00000000000..0172aec4c80 --- /dev/null +++ b/Tests/_files/ThrowNoExceptionTestCase.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__); + +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/_files/TornDown.php b/Tests/_files/TornDown.php new file mode 100644 index 00000000000..a065fc789d7 --- /dev/null +++ b/Tests/_files/TornDown.php @@ -0,0 +1,84 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__); + +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/_files/TornDown2.php b/Tests/_files/TornDown2.php new file mode 100644 index 00000000000..fcc91fcdf90 --- /dev/null +++ b/Tests/_files/TornDown2.php @@ -0,0 +1,89 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__); + +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/_files/TornDown3.php b/Tests/_files/TornDown3.php new file mode 100644 index 00000000000..109b9a60b1b --- /dev/null +++ b/Tests/_files/TornDown3.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__); + +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/_files/TornDown4.php b/Tests/_files/TornDown4.php new file mode 100644 index 00000000000..647724b3d72 --- /dev/null +++ b/Tests/_files/TornDown4.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__); + +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/_files/TornDown5.php b/Tests/_files/TornDown5.php new file mode 100644 index 00000000000..72dbf39ba35 --- /dev/null +++ b/Tests/_files/TornDown5.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__); + +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/_files/TornDown6.php b/Tests/_files/TornDown6.php new file mode 100644 index 00000000000..46fce92ace8 --- /dev/null +++ b/Tests/_files/TornDown6.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__); + +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/_files/WasRun.php b/Tests/_files/WasRun.php new file mode 100644 index 00000000000..f64d0c7cb5b --- /dev/null +++ b/Tests/_files/WasRun.php @@ -0,0 +1,83 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__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 + */ +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..5602178a2ce --- /dev/null +++ b/TextUI/ResultPrinter.php @@ -0,0 +1,449 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Util/Printer.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * 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 $timeElapsed + * @access public + */ + public function printResult(PHPUnit2_Framework_TestResult $result, $timeElapsed) + { + $this->printHeader($timeElapsed); + $this->printErrors($result); + $this->printFailures($result); + $this->printIncompletes($result); + $this->printSkipped($result); + $this->printFooter($result); + } + + /** + * @param array $defects + * @param integer $count + * @param string $type + * @access protected + */ + protected function printDefects(Array $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) + { + $failedTest = $defect->failedTest(); + $message = ''; + + if ($failedTest instanceof PHPUnit2_Framework_SelfDescribing) { + $message = $failedTest->toString(); + } + + $this->write( + sprintf( + "%d) %s\n", + + $count, + $message + ) + ); + } + + /** + * @param PHPUnit2_Framework_TestFailure $defect + * @access protected + */ + protected function printDefectTrace(PHPUnit2_Framework_TestFailure $defect) + { + $e = $defect->thrownException(); + + if ($e instanceof PHPUnit2_Framework_SelfDescribing) { + $message = $e->toString(); + } else { + $message = $e->getMessage(); + } + + $this->write($message . "\n"); + + $this->write( + PHPUnit2_Util_Filter::getFilteredStacktrace( + $defect->thrownException(), + FALSE + ) + ); + } + + /** + * @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'); + } + + /** + * @param PHPUnit2_Framework_TestResult $result + * @access protected + * @since Method available since Release 3.0.0 + */ + protected function printSkipped(PHPUnit2_Framework_TestResult $result) + { + $this->printDefects($result->skipped(), $result->skippedCount(), 'skipped test'); + } + + /** + * @param float $timeElapsed + * @access protected + */ + protected function printHeader($timeElapsed) + { + $minutes = ($timeElapsed >= 60) ? floor($timeElapsed / 60) : 0; + + $this->write( + sprintf( + "\n\nTime: %02d:%02d\n", + + $minutes, + $timeElapsed - $minutes * 60 + ) + ); + } + + /** + * @param PHPUnit2_Framework_TestResult $result + * @access protected + */ + protected function printFooter(PHPUnit2_Framework_TestResult $result) + { + if ($result->wasSuccessful() && + $result->allCompletlyImplemented() && + $result->noneSkipped()) { + $this->write( + sprintf( + "\nOK (%d test%s)\n", + + count($result), + (count($result) == 1) ? '' : 's' + ) + ); + } + + else if ((!$result->allCompletlyImplemented() || + !$result->noneSkipped())&& + $result->wasSuccessful()) { + $this->write( + sprintf( + "\nOK, but incomplete or skipped tests!\n" . + "Tests: %d%s%s.\n", + + count($result), + $this->getCountString($result->notImplementedCount(), 'Incomplete'), + $this->getCountString($result->skippedCount(), 'Skipped') + ) + ); + } + + else { + $this->write( + sprintf( + "\nFAILURES!\n" . + "Tests: %d%s%s%s%s.\n", + + count($result), + $this->getCountString($result->failureCount(), 'Failures'), + $this->getCountString($result->errorCount(), 'Errors'), + $this->getCountString($result->notImplementedCount(), 'Incomplete'), + $this->getCountString($result->skippedCount(), 'Skipped') + ) + ); + } + } + + /** + * @param integer $count + * @param string $name + * @return string + * @access protected + * @since Method available since Release 3.0.0 + */ + protected function getCountString($count, $name) + { + $string = ''; + + if ($count > 0) { + $string = sprintf( + ', %s: %d', + + $name, + $count + ); + } + + return $string; + } + + /** + * @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; + } + + /** + * Skipped test. + * + * @param PHPUnit2_Framework_Test $test + * @param Exception $e + * @access public + * @since Method available since Release 3.0.0 + */ + public function addSkippedTest(PHPUnit2_Framework_Test $test, Exception $e) + { + $this->write('S'); + $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..828c732f97c --- /dev/null +++ b/TextUI/TestRunner.php @@ -0,0 +1,687 @@ +. + * 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 SVN: $Id$ + * @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.php'; +require_once 'PHPUnit2/Runner/BaseTestRunner.php'; +require_once 'PHPUnit2/Extensions/RepeatedTest.php'; +require_once 'PHPUnit2/Runner/StandardTestSuiteLoader.php'; +require_once 'PHPUnit2/Runner/Version.php'; +require_once 'PHPUnit2/TextUI/ResultPrinter.php'; +require_once 'PHPUnit2/Util/TestDox/ResultPrinter.php'; +require_once 'PHPUnit2/Util/Fileloader.php'; +require_once 'PHPUnit2/Util/Getopt.php'; +require_once 'PHPUnit2/Util/Report.php'; +require_once 'PHPUnit2/Util/Timer.php'; +require_once 'PHPUnit2/Util/Skeleton.php'; +require_once 'PHPUnit2/Util/Log/Eclipse.php'; +require_once 'PHPUnit2/Util/Log/GraphViz.php'; +require_once 'PHPUnit2/Util/Log/TAP.php'; +require_once 'PHPUnit2/Util/Log/XML.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * 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 RuntimeException + * @access protected + */ + protected function start(Array $arguments) + { + $loaderName = FALSE; + $parameters = array(); + $repeat = FALSE; + + $possibleOptions = array( + 'help', + 'loader=', + 'log-eclipse=', + 'log-tap=', + 'log-xml=', + 'printer=', + 'repeat=', + 'report=', + 'skeleton', + 'testdox-html=', + 'testdox-text=', + 'version', + 'wait' + ); + + if (class_exists('Image_GraphViz')) { + $possibleOptions[] = 'log-graphviz='; + } + + try { + $options = PHPUnit2_Util_Getopt::getopt( + $arguments, + '', + $possibleOptions + ); + } + + catch (RuntimeException $e) { + $this->showError($e->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 '--help': { + $this->showHelp(); + exit(self::SUCCESS_EXIT); + } + break; + + case '--loader': { + $loaderName = $option[1]; + } + break; + + case '--log-eclipse': { + $$parameters['eclipseLogfile'] = $option[1]; + } + break; + + case '--log-graphviz': { + $parameters['graphvizDirectory'] = $option[1]; + } + break; + + case '--log-tap': { + $parameters['tapLogfile'] = $option[1]; + } + break; + + case '--log-xml': { + $parameters['xmlLogfile'] = $option[1]; + } + break; + + case '--printer': { + switch (strtolower($option[1])) { + case 'tap': { + $parameters['printer'] = new PHPUnit2_Util_Log_TAP; + } + break; + } + } + break; + + case '--repeat': { + $repeat = (int)$option[1]; + } + break; + + case '--report': { + $parameters['reportDirectory'] = $option[1]; + } + break; + + case '--skeleton': { + $this->doSkeleton($test, $testFile); + } + break; + + case '--testdox-html': { + $parameters['testdoxHTMLFile'] = $option[1]; + } + break; + + case '--testdox-text': { + $parameters['testdoxTextFile'] = $option[1]; + } + break; + + case '--version': { + self::printVersionString(); + exit(self::SUCCESS_EXIT); + } + break; + + case '--wait': { + $parameters['wait'] = TRUE; + } + break; + } + } + + if ($test === FALSE) { + $this->showHelp(); + + exit(self::SUCCESS_EXIT); + } + + if ($loaderName !== FALSE) { + $this->handleLoader($loaderName); + } + + if (!isset($parameters['printer'])) { + $printer = new PHPUnit2_TextUI_ResultPrinter; + } + + $test = $this->getTest($test, $testFile); + + if ($repeat !== FALSE) { + $test = new PHPUnit2_Extensions_RepeatedTest($test, $repeat); + } + + try { + return $this->doRun( + $test, + $parameters + ); + } + + catch (Exception $e) { + throw new RuntimeException( + 'Could not create and run test suite: ' . $e->getMessage() + ); + } + } + + /** + * @param mixed $test + * @param array $parameters + * @access public + * @static + */ + public static function run($test, Array $parameters = array()) + { + 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, + $parameters + ); + } + } + + /** + * 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, + array( + 'wait' => TRUE + ) + ); + + } + + /** + * @return PHPUnit2_Framework_TestResult + * @access protected + */ + protected function createTestResult() + { + return new PHPUnit2_Framework_TestResult; + } + + /** + * @param PHPUnit2_Framework_Test $suite + * @param array $parameters + * @return PHPUnit2_Framework_TestResult + * @access public + */ + public function doRun(PHPUnit2_Framework_Test $suite, Array $parameters = array()) + { + if (isset($parameters['graphvizDirectory'])) { + $parameters['graphvizDirectory'] = $this->getDirectory($parameters['graphvizDirectory']); + } + + if (isset($parameters['reportDirectory'])) { + $parameters['reportDirectory'] = $this->getDirectory($parameters['reportDirectory']); + } + + $result = $this->createTestResult(); + + if ($this->printer === NULL) { + if (isset($parameters['printer']) && $parameters instanceof PHPUnit2_Util_Printer) { + $this->printer = $parameters['printer']; + } else { + $this->printer = new PHPUnit2_TextUI_ResultPrinter; + } + } + + $this->printer->write( + PHPUnit2_Runner_Version::getVersionString() . "\n\n" + ); + + $result->addListener($this->printer); + + if (isset($parameters['testdoxHTMLFile'])) { + $result->addListener( + PHPUnit2_Util_TestDox_ResultPrinter::factory( + 'HTML', + $parameters['testdoxHTMLFile'] + ) + ); + } + + if (isset($parameters['testdoxTextFile'])) { + $result->addListener( + PHPUnit2_Util_TestDox_ResultPrinter::factory( + 'Text', + $parameters['testdoxTextFile'] + ) + ); + } + + if (isset($parameters['graphvizDirectory'])) { + $result->addListener( + new PHPUnit2_Util_Log_GraphViz($parameters['graphvizDirectory']) + ); + } + + if (isset($parameters['reportDirectory'])) { + $result->addListener( + new PHPUnit2_Util_Log_GraphViz($parameters['reportDirectory']) + ); + + $result->collectCodeCoverageInformation(TRUE); + } + + if (isset($parameters['eclipseLogfile'])) { + $result->addListener( + new PHPUnit2_Util_Log_Eclipse($parameters['eclipseLogfile']) + ); + } + + if (isset($parameters['tapLogfile'])) { + $result->addListener( + new PHPUnit2_Util_Log_TAP($parameters['tapLogfile']) + ); + } + + if (isset($parameters['xmlLogfile'])) { + $result->addListener( + new PHPUnit2_Util_Log_XML($parameters['xmlLogfile']) + ); + } + + PHPUnit2_Util_Timer::start(); + $suite->run($result); + $timeElapsed = PHPUnit2_Util_Timer::stop(); + + $result->flushListeners(); + + if (isset($parameters['reportDirectory'])) { + PHPUnit2_Util_Report::render($result, $parameters['reportDirectory']); + } + + $this->pause($parameters['wait']); + + if ($this->printer instanceof PHPUnit2_TextUI_ResultPrinter) { + $this->printer->printResult($result, $timeElapsed); + } + + 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; + } + + /** + * @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\n"; + + if (class_exists('Image_GraphViz')) { + print " --log-graphviz Log test execution in GraphViz markup.\n"; + } + + print " --log-tap Log test execution in TAP format to file.\n" . + " --log-xml Log test execution in XML format to file.\n\n"; + + if (extension_loaded('xdebug')) { + print " --report Generate combined test/coverage report in HTML format.\n"; + } else { + print " --report Generate test report in HTML format.\n"; + } + + print " --testdox-html Write agile documentation in HTML format to file.\n" . + " --testdox-text Write agile documentation in Text format to file.\n\n" . + " --printer {dots|tap} Report test execution progress in DOTS or TAP format.\n" . + " --loader TestSuiteLoader implementation to use.\n\n" . + " --skeleton Generate skeleton UnitTest class for Unit in Unit.php.\n\n" . + " --repeat Runs the test(s) repeatedly.\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; + } + + if ($this->printer instanceof PHPUnit2_TextUI_ResultPrinter) { + $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); + } + + /** + * @param string $test + * @param string $testFile + * @access private + * @since Method available since Release 3.0.0 + */ + private function doSkeleton($test, $testFile) + { + if ($test !== FALSE) { + self::printVersionString(); + + try { + $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, + $testFile + ); + + exit(self::FAILURE_EXIT); + } + + printf( + "Wrote test class skeleton for %s to %s.\n", + $test, + $skeleton->getTestSourceFile() + ); + + exit(self::SUCCESS_EXIT); + } + } + + /** + * @param string $loaderName + * @access private + * @since Method available since Release 3.0.0 + */ + private function handleLoader($loaderName) + { + if (!class_exists($loaderName)) { + PHPUnit2_Util_Fileloader::checkAndLoad( + str_replace('_', '/', $loaderName) . '.php' + ); + } + + if (class_exists($loaderName)) { + $class = new ReflectionClass($loaderName); + + 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.', + + $loaderName + ) + ); + } + } + + /** + * @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; + } + } + + /** + * @access private + * @since Method available since Release 3.0.0 + */ + private function getDirectory($directory) + { + if (substr($directory, -1, 1) != DIRECTORY_SEPARATOR) { + $directory .= DIRECTORY_SEPARATOR; + } + + return $directory; + } +} + +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/Array.php b/Util/Array.php new file mode 100644 index 00000000000..c4c0af531a6 --- /dev/null +++ b/Util/Array.php @@ -0,0 +1,95 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Array helpers. + * + * @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 3.0.0 + */ +class PHPUnit2_Util_Array +{ + /** + * Sorts an array recursively by its keys. + * + * @param array $array + * @access public + * @static + */ + public static function sortRecursively(Array $array) + { + ksort($array); + + foreach($array as $k => $v) { + if (is_array($v)) { + $array[$k] = self::sortRecursively($array[$k]); + } + } + + return $array; + } +} + +/* + * 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..191b6ded2ae --- /dev/null +++ b/Util/ErrorHandler.php @@ -0,0 +1,83 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * @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..7e55284b1b4 --- /dev/null +++ b/Util/Fileloader.php @@ -0,0 +1,177 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +ini_set('xdebug.show_local_vars', 1); + +/** + * + * + * @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 RuntimeException + * @access public + * @static + */ + public static function checkAndLoad($filename) + { + if (!is_readable($filename)) { + $filename = './' . $filename; + } + + if (!is_readable($filename)) { + throw new RuntimeException( + sprintf( + '%s could not be found or is not readable.', + + str_replace('./', '', $filename) + ) + ); + } + + self::syntaxCheck($filename); + self::load($filename); + } + + /** + * + * + * @return Array + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function getIncludePaths() + { + $includePaths = explode(PATH_SEPARATOR, get_include_path()); + + @include_once 'PEAR/Config.php'; + + if (class_exists('PEAR_Config')) { + $config = new PEAR_Config; + $includePaths[] = $config->get('test_dir'); + } + + return $includePaths; + } + + /** + * @param string $filename + * @access protected + * @static + * @since Method available since Release 3.0.0 + */ + protected static function load($filename) + { + if (function_exists('xdebug_get_declared_vars')) { + $variables = array('variables', xdebug_get_declared_vars()); + } + + include_once $filename; + + if (function_exists('xdebug_get_declared_vars')) { + $variables = array_values( + array_diff(xdebug_get_declared_vars(), $variables) + ); + + foreach ($variables as $variable) { + if (isset($$variable)) { + $GLOBALS[$variable] = $$variable; + } + } + } + } + + /** + * @param string $filename + * @throws RuntimeException + * @access protected + * @static + * @since Method available since Release 3.0.0 + */ + protected static function syntaxCheck($filename) + { + if (isset($_SERVER['PHPBIN'])) { + $phpbin = $_SERVER['PHPBIN']; + } else { + $phpbin = 'php'; + } + + $output = shell_exec($phpbin . ' -l ' . escapeshellarg($filename)); + + if (strpos($output, 'Errors parsing') === TRUE) { + throw new RuntimeException($output); + } + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Util/Filesystem.php b/Util/Filesystem.php new file mode 100644 index 00000000000..4282e819349 --- /dev/null +++ b/Util/Filesystem.php @@ -0,0 +1,91 @@ +. + * 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 + * @author Michael Lively Jr. + * @copyright 2002-2006 Sebastian Bergmann + * @license http://www.opensource.org/licenses/bsd-license.php BSD License + * @version SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Filesystem helpers. + * + * @category Testing + * @package PHPUnit2 + * @author Sebastian Bergmann + * @author Michael Lively Jr. + * @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 3.0.0 + * @abstract + */ +class PHPUnit2_Util_Filesystem +{ + /** + * Returns a filesystem safe version of the passed filename. + * This function does not operate on full paths, just filenames. + * + * @param string $filename + * @access public + */ + static public function getSafeFilename($filename) + { + /* characters allowed: A-Z, a-z, 0-9, _ and . */ + return preg_replace('#[^\w.]#', '_', $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..7f099d85858 --- /dev/null +++ b/Util/Filter.php @@ -0,0 +1,282 @@ +. + * 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 SVN: $Id$ + * @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 +{ + /** + * @var boolean + * @access private + * @static + */ + private static $filter = TRUE; + + /** + * Source files that are to be filtered. + * + * @var array + * @access protected + * @static + */ + protected static $filteredFiles = array( + 'DEFAULT' => array(), + 'PHPUNIT' => array(), + 'TESTS' => array(), + 'PEAR' => array( + 'Image/GraphViz.php', + 'Log/composite.php', + 'Log/console.php', + 'Log/daemon.php', + 'Log/display.php', + 'Log/error_log.php', + 'Log/file.php', + 'Log/mail.php', + 'Log/mcal.php', + 'Log/mdb2.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 $filename + * @param string $group + * @access public + * @static + * @since Method available since Release 2.1.0 + */ + public static function addFileToFilter($filename, $group = 'DEFAULT') + { + self::$filteredFiles[$group][] = self::getCanonicalFilename($filename); + } + + /** + * Removes a file from the filter. + * + * @param string $filename + * @param string $group + * @access public + * @static + * @since Method available since Release 2.1.0 + */ + public static function removeFileFromFilter($filename, $group = 'DEFAULT') + { + if (isset(self::$filteredFiles[$group])) { + $filename = self::getCanonicalFilename($filename); + $max = count(self::$filteredFiles[$group]); + + for ($i = 0; $i < $max; $i++) { + if (self::$filteredFiles[$group][$i] == $filename) { + unset(self::$filteredFiles[$group][$i]); + } + } + } + } + + /** + * Filters source lines from PHPUnit classes. + * + * @param array $codeCoverageInformation + * @param boolean $filterTests + * @param boolean $filterPHPUnit + * @return array + * @access public + * @static + */ + public static function getFilteredCodeCoverage(Array $codeCoverageInformation, $filterTests = TRUE, $filterPHPUnit = TRUE) + { + if (self::$filter) { + $max = count($codeCoverageInformation); + + for ($i = 0; $i < $max; $i++) { + foreach (array_keys($codeCoverageInformation[$i]['files']) as $file) { + if (self::isFiltered($file, $filterTests, $filterPHPUnit)) { + unset($codeCoverageInformation[$i]['files'][$file]); + } + } + } + } + + return $codeCoverageInformation; + } + + /** + * Filters stack frames from PHPUnit classes. + * + * @param Exception $e + * @param boolean $filterTests + * @param boolean $filterPHPUnit + * @return string + * @access public + * @static + */ + public static function getFilteredStacktrace(Exception $e, $filterTests = TRUE, $filterPHPUnit = TRUE) + { + $filteredStacktrace = ''; + + foreach ($e->getTrace() as $frame) { + if (!self::$filter || (isset($frame['file']) && !self::isFiltered($frame['file'], $filterTests, $filterPHPUnit))) { + $filteredStacktrace .= sprintf( + "%s:%s\n", + + $frame['file'], + isset($frame['line']) ? $frame['line'] : '?' + ); + } + } + + return $filteredStacktrace; + } + + /** + * Activates or deactivates filtering. + * + * @param boolean $filter + * @throws InvalidArgumentException + * @access public + * @static + * @since Method available since Release 3.0.0 + */ + public static function setFilter($filter) + { + if (is_bool($filter)) { + self::$filter = $filter; + } else { + throw new InvalidArgumentException; + } + } + + /** + * Canonicalizes a source file name. + * + * @param string $filename + * @return string + * @access protected + * @static + */ + protected static function getCanonicalFilename($filename) + { + return str_replace('\\', '/', $filename); + } + + /** + * @param string $filename + * @param boolean $filterTests + * @param boolean $filterPHPUnit + * @return boolean + * @access protected + * @static + * @since Method available since Release 2.1.3 + */ + protected static function isFiltered($filename, $filterTests = TRUE, $filterPHPUnit = TRUE) + { + $filename = self::getCanonicalFilename($filename); + + $filteredFiles = array_merge( + self::$filteredFiles['DEFAULT'], + self::$filteredFiles['PEAR'] + ); + + if ($filterTests) { + $filteredFiles = array_merge( + $filteredFiles, + self::$filteredFiles['TESTS'] + ); + } + + if ($filterPHPUnit) { + $filteredFiles = array_merge( + $filteredFiles, + self::$filteredFiles['PHPUNIT'] + ); + } + + if (in_array($filename, $filteredFiles)) { + return TRUE; + } + + foreach ($filteredFiles as $filteredFile) { + if (strpos($filename, $filteredFile) !== FALSE) { + return TRUE; + } + } + + return FALSE; + } +} + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Util/Getopt.php b/Util/Getopt.php new file mode 100644 index 00000000000..738473766af --- /dev/null +++ b/Util/Getopt.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Command-line options parsing class. + * + * @category Testing + * @package PHPUnit2 + * @author Andrei Zmievski + * @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 3.0.0 + * @abstract + */ +class PHPUnit2_Util_Getopt { + public static function getopt(Array $args, $short_options, $long_options = null) + { + if (empty($args)) { + return array(array(), array()); + } + + $opts = array(); + $non_opts = array(); + + if ($long_options) { + sort($long_options); + } + + if (isset($args[0]{0}) && $args[0]{0} != '-') { + array_shift($args); + } + + reset($args); + + while (list($i, $arg) = each($args)) { + if ($arg == '--') { + $non_opts = array_merge($non_opts, array_slice($args, $i + 1)); + break; + } + + if ($arg{0} != '-' || (strlen($arg) > 1 && $arg{1} == '-' && !$long_options)) { + $non_opts = array_merge($non_opts, array_slice($args, $i)); + break; + } + + elseif (strlen($arg) > 1 && $arg{1} == '-') { + self::parseLongOption(substr($arg, 2), $long_options, $opts, $args); + } + + else { + self::parseShortOption(substr($arg, 1), $short_options, $opts, $args); + } + } + + return array($opts, $non_opts); + } + + private static function parseShortOption($arg, $short_options, &$opts, &$args) + { + for ($i = 0; $i < strlen($arg); $i++) { + $opt = $arg{$i}; + $opt_arg = null; + + if (($spec = strstr($short_options, $opt)) === false || $arg{$i} == ':') { + throw new RuntimeException("unrecognized option -- $opt"); + } + + if (strlen($spec) > 1 && $spec{1} == ':') { + if (strlen($spec) > 2 && $spec{2} == ':') { + if ($i + 1 < strlen($arg)) { + $opts[] = array($opt, substr($arg, $i + 1)); + break; + } + } else { + if ($i + 1 < strlen($arg)) { + $opts[] = array($opt, substr($arg, $i + 1)); + break; + } + + else if (list(, $opt_arg) = each($args)) { + } + + else { + throw new RuntimeException("option requires an argument -- $opt"); + } + } + } + + $opts[] = array($opt, $opt_arg); + } + } + + private static function parseLongOption($arg, $long_options, &$opts, &$args) + { + @list($opt, $opt_arg) = explode('=', $arg); + $opt_len = strlen($opt); + + for ($i = 0; $i < count($long_options); $i++) { + $long_opt = $long_options[$i]; + $opt_start = substr($long_opt, 0, $opt_len); + + if ($opt_start != $opt) continue; + + $opt_rest = substr($long_opt, $opt_len); + + if ($opt_rest != '' && $opt{0} != '=' && + $i + 1 < count($long_options) && + $opt == substr($long_options[$i+1], 0, $opt_len)) { + throw new RuntimeException("option --$opt is ambiguous"); + } + + if (substr($long_opt, -1) == '=') { + if (substr($long_opt, -2) != '==') { + if (!strlen($opt_arg) && !(list(, $opt_arg) = each($args))) { + throw new RuntimeException("option --$opt requires an argument"); + } + } + } + + else if ($opt_arg) { + throw new RuntimeException("option --$opt doesn't allow an argument"); + } + + $opts[] = array('--' . $opt, $opt_arg); + return; + } + + throw new RuntimeException("unrecognized option --$opt"); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Util/Log/Eclipse.php b/Util/Log/Eclipse.php new file mode 100644 index 00000000000..263681c31c3 --- /dev/null +++ b/Util/Log/Eclipse.php @@ -0,0 +1,300 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Util/Printer.php'; +require_once 'PHPUnit2/Util/Timer.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * A TestListener that passes a log of the test execution as a JSON string + * to Eclipse via a socket connection. + * + * @category Testing + * @package PHPUnit2 + * @author Steven Balthazor + * @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 3.0.0 + */ +class PHPUnit2_Util_Log_Eclipse extends PHPUnit2_Util_Printer implements PHPUnit2_Framework_TestListener +{ + /** + * @var string + * @access private + */ + private $currentTestSuiteName = ''; + + /** + * @var string + * @access private + */ + private $currentTestCaseName = ''; + + /** + * @var string + * @access private + */ + private $currentTestMethodName = ''; + + /** + * @var boolean + * @access private + */ + private $currentTestCasePass = TRUE; + + /** + * Constructor. + * + * @param mixed $out + * @access public + */ + public function __construct($out = NULL) + { + $this->out = @fsockopen('127.0.0.1', $out, $errnum, $error, 10); + + if (!$this->out){ + throw new RuntimeException( + sprintf( + 'Error opening socket %s : %s (%s)', + + $out, + $error, + $errnum + ) + ); + } + } + + /** + * @param string $buffer + * @access public + */ + public function write($buffer) + { + if ($this->out !== NULL) { + fwrite($this->out, $buffer); + } + } + + /** + * @param string $status + * @param string $message + * @access private + */ + private function writeCase($status, $message = '') + { + $this->write( + sprintf( + '{status:"%s",message:"%s",group:"%s",case:"%s",method:"%s"}', + + $status, + $this->escapeValue($message), + $this->currentTestSuiteName, + $this->currentTestCaseName, + $this->currentTestMethodName + ) + ); + } + + /** + * @param string $value + * @return string + * @access private + */ + private function escapeValue($value) + { + return str_replace( + array("\\","\"","/","\b","\f","\n","\r","\t"), + array('\\\\','\"','\/','\b','\f','\n','\r','\t'), + $value + ); + } + + /** + * An error occurred. + * + * @param PHPUnit2_Framework_Test $test + * @param Exception $e + * @access public + */ + public function addError(PHPUnit2_Framework_Test $test, Exception $e) + { + $this->writeCase( + 'error', + sprintf( + '%s:%s', + get_class($e), + $e->getMessage() + ) + ); + + $this->currentTestCasePass = FALSE; + } + + /** + * 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) + { + $location = $e->getLocation(); + + $this->writeCase( + 'fail', + sprintf( + '%s[%s line %s]', + + $e->getMessage(), + $location['file'], + $location['line'] + ) + ); + + $this->currentTestCasePass = FALSE; + } + + /** + * Incomplete test. + * + * @param PHPUnit2_Framework_Test $test + * @param Exception $e + * @access public + */ + public function addIncompleteTest(PHPUnit2_Framework_Test $test, Exception $e) + { + $this->writeCase('error', 'Incomplete Test'); + + $this->currentTestCasePass = FALSE; + } + + /** + * Skipped test. + * + * @param PHPUnit2_Framework_Test $test + * @param Exception $e + * @access public + */ + public function addSkippedTest(PHPUnit2_Framework_Test $test, Exception $e) + { + $this->writeCase('error', 'Skipped Test'); + + $this->currentTestCasePass = FALSE; + } + + /** + * 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) + { + $this->currentTestSuiteName = $this->escapeValue($suite->getName()); + $this->currentTestCaseName = ''; + $this->currentTestMethodName = ''; + } + + /** + * 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->currentTestCaseName = ''; + $this->currentTestMethodName = ''; + $this->currentTestSuiteName = ''; + } + + /** + * A test started. + * + * @param PHPUnit2_Framework_Test $test + * @access public + */ + public function startTest(PHPUnit2_Framework_Test $test) + { + $this->currentTestCaseName = $this->escapeValue(get_class($test)); + $this->currentTestMethodName = $this->escapeValue($test->getName()); + $this->currentTestCasePass = TRUE; + } + + /** + * A test ended. + * + * @param PHPUnit2_Framework_Test $test + * @access public + */ + public function endTest(PHPUnit2_Framework_Test $test) + { + if ($this->currentTestCasePass) { + $this->writeCase('pass'); + } + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Util/Log/GraphViz.php b/Util/Log/GraphViz.php new file mode 100644 index 00000000000..e7cd225ecfa --- /dev/null +++ b/Util/Log/GraphViz.php @@ -0,0 +1,348 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +@include_once 'Image/GraphViz.php'; + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Util/Filesystem.php'; +require_once 'PHPUnit2/Util/Test.php'; +require_once 'PHPUnit2/Util/Timer.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * A TestListener that generates maps of the executed tests + * in GraphViz markup. + * + * @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 3.0.0 + */ +class PHPUnit2_Util_Log_GraphViz implements PHPUnit2_Framework_TestListener +{ + /** + * @var Image_GraphViz[] + * @access private + */ + private $graphs = array(); + + /** + * @var string + * @access private + */ + private $target; + + /** + * @var boolean + * @access private + */ + private $currentTestSuccess = TRUE; + + /** + * @var string[] + * @access private + */ + private $testSuites = array(); + + /** + * @var integer + * @access private + */ + private $testSuiteLevel = 0; + + /** + * @var integer[] + * @access private + */ + private $testSuiteFailureOrErrorCount = array(0); + + /** + * @var integer[] + * @access private + */ + private $testSuiteIncompleteOrSkippedCount = array(0); + + /** + * Constructor. + * + * @param string $target + * @access public + */ + public function __construct($target) + { + $this->target = $target; + } + + /** + * An error occurred. + * + * @param PHPUnit2_Framework_Test $test + * @param Exception $e + * @access public + */ + public function addError(PHPUnit2_Framework_Test $test, Exception $e) + { + $this->addTestNode($test, 'red'); + $this->testSuiteFailureOrErrorCount[$this->testSuiteLevel]++; + + $this->currentTestSuccess = FALSE; + } + + /** + * 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->addTestNode($test, 'red'); + $this->testSuiteFailureOrErrorCount[$this->testSuiteLevel]++; + + $this->currentTestSuccess = FALSE; + } + + /** + * Incomplete test. + * + * @param PHPUnit2_Framework_Test $test + * @param Exception $e + * @access public + */ + public function addIncompleteTest(PHPUnit2_Framework_Test $test, Exception $e) + { + $this->addTestNode($test, 'yellow'); + $this->testSuiteIncompleteOrSkippedCount[$this->testSuiteLevel]++; + + $this->currentTestSuccess = FALSE; + } + + /** + * Skipped test. + * + * @param PHPUnit2_Framework_Test $test + * @param Exception $e + * @access public + */ + public function addSkippedTest(PHPUnit2_Framework_Test $test, Exception $e) + { + $this->addTestNode($test, 'yellow'); + $this->testSuiteIncompleteOrSkippedCount[$this->testSuiteLevel]++; + + $this->currentTestSuccess = FALSE; + } + + /** + * A testsuite started. + * + * @param PHPUnit2_Framework_TestSuite $suite + * @access public + */ + public function startTestSuite(PHPUnit2_Framework_TestSuite $suite) + { + $this->testSuiteLevel++; + $this->testSuites[$this->testSuiteLevel] = $suite->getName(); + $this->testSuiteFailureOrErrorCount[$this->testSuiteLevel] = 0; + $this->testSuiteIncompleteOrSkippedCount[$this->testSuiteLevel] = 0; + + $this->graphs[$this->testSuiteLevel] = new Image_GraphViz( + TRUE, + array( + 'overlap' => 'scale', + 'splines' => 'true', + 'sep' => '.1', + 'fontsize' => '8' + ) + ); + + $this->graphs[$this->testSuiteLevel]->addNode($suite->getName()); + + if ($this->testSuiteLevel > 1) { + $this->graphs[$this->testSuiteLevel]->addNode( + $this->testSuites[$this->testSuiteLevel - 1], + array( + 'URL' => PHPUnit2_Util_Filesystem::getSafeFilename($this->testSuites[$this->testSuiteLevel - 1]) . '-test.htm' + ) + ); + + $this->graphs[$this->testSuiteLevel]->addEdge( + array( + $this->testSuites[$this->testSuiteLevel - 1] => $suite->getName() + ) + ); + + $this->graphs[$this->testSuiteLevel - 1]->addNode($suite->getName()); + + $this->graphs[$this->testSuiteLevel - 1]->addEdge( + array( + $this->testSuites[$this->testSuiteLevel - 1] => $suite->getName() + ) + ); + } + } + + /** + * A testsuite ended. + * + * @param PHPUnit2_Framework_TestSuite $suite + * @access public + */ + public function endTestSuite(PHPUnit2_Framework_TestSuite $suite) + { + $color = 'red'; + + if ($this->testSuiteFailureOrErrorCount[$this->testSuiteLevel] == 0 && + $this->testSuiteIncompleteOrSkippedCount[$this->testSuiteLevel] == 0) { + $color = 'green'; + } + + else if ($this->testSuiteFailureOrErrorCount[$this->testSuiteLevel] == 0 && + $this->testSuiteIncompleteOrSkippedCount[$this->testSuiteLevel] > 0) { + $color = 'yellow'; + } + + $safeSuiteName = PHPUnit2_Util_Filesystem::getSafeFilename($suite->getName()); + + $this->graphs[$this->testSuiteLevel]->addNode( + $this->testSuites[$this->testSuiteLevel], + array( + 'color' => $color, + 'URL' => $safeSuiteName . '-test.htm' + ) + ); + + if ($this->testSuiteLevel > 1) { + $this->graphs[$this->testSuiteLevel - 1]->addNode( + $this->testSuites[$this->testSuiteLevel], + array( + 'color' => $color, + 'URL' => $safeSuiteName . '-test.htm' + ) + ); + + $this->testSuiteFailureOrErrorCount[$this->testSuiteLevel - 1] += $this->testSuiteFailureOrErrorCount[$this->testSuiteLevel]; + $this->testSuiteIncompleteOrSkippedCount[$this->testSuiteLevel - 1] += $this->testSuiteIncompleteOrSkippedCount[$this->testSuiteLevel]; + } + + $fp = fopen($this->target . $safeSuiteName . '.dot', 'wt'); + fputs($fp, $this->graphs[$this->testSuiteLevel]->parse()); + fclose($fp); + + $this->testSuiteLevel--; + } + + /** + * A test started. + * + * @param PHPUnit2_Framework_Test $test + * @access public + */ + public function startTest(PHPUnit2_Framework_Test $test) + { + $this->currentTestSuccess = TRUE; + } + + /** + * A test ended. + * + * @param PHPUnit2_Framework_Test $test + * @access public + */ + public function endTest(PHPUnit2_Framework_Test $test) + { + if ($this->currentTestSuccess) { + $this->addTestNode($test, 'green'); + } + } + + /** + * @param PHPUnit2_Framework_Test $test + * @param string $color + * @access private + */ + private function addTestNode(PHPUnit2_Framework_Test $test, $color) + { + $name = PHPUnit2_Util_Test::describe($test, FALSE); + + $this->graphs[$this->testSuiteLevel]->addNode( + $name[1], + array( + 'color' => $color, + 'URL' => sprintf( + '%s-test.htm#%s', + + PHPUnit2_Util_Filesystem::getSafeFilename($name[0]), + $name[1] + ) + ), + $this->testSuites[$this->testSuiteLevel] + ); + + $this->graphs[$this->testSuiteLevel]->addEdge( + array( + $this->testSuites[$this->testSuiteLevel] => $name[1] + ) + ); + } +} + +/* + * 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..a481812d3be --- /dev/null +++ b/Util/Log/PEAR.php @@ -0,0 +1,252 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +@include_once 'Log.php'; + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * 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() + ) + ); + } + + /** + * Skipped test. + * + * @param PHPUnit2_Framework_Test $test + * @param Exception $e + * @access public + * @since Method available since Release 3.0.0 + */ + public function addSkippedTest(PHPUnit2_Framework_Test $test, Exception $e) + { + $this->log->info( + sprintf( + 'Test "%s" skipped: %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/TAP.php b/Util/Log/TAP.php new file mode 100644 index 00000000000..bb2834d7619 --- /dev/null +++ b/Util/Log/TAP.php @@ -0,0 +1,253 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Util/Printer.php'; +require_once 'PHPUnit2/Util/Test.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * A TestListener that generates a logfile of the + * test execution using the Test Anything Protocol (TAP). + * + * @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 3.0.0 + */ +class PHPUnit2_Util_Log_TAP extends PHPUnit2_Util_Printer implements PHPUnit2_Framework_TestListener +{ + /** + * @var integer + * @access private + */ + private $testNumber = 0; + + /** + * @var boolean + * @access private + */ + private $testSuccessful = TRUE; + + /** + * Flush buffer and close output. + * + * @access public + */ + public function flush() + { + $this->write( + sprintf( + "1..%s\n", + + $this->testNumber + ) + ); + + parent::flush(); + } + + /** + * An error occurred. + * + * @param PHPUnit2_Framework_Test $test + * @param Exception $e + * @access public + */ + public function addError(PHPUnit2_Framework_Test $test, Exception $e) + { + $this->writeNotOk($test, 'Error'); + } + + /** + * 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->writeNotOk($test, 'Failure'); + } + + /** + * Incomplete test. + * + * @param PHPUnit2_Framework_Test $test + * @param Exception $e + * @access public + */ + public function addIncompleteTest(PHPUnit2_Framework_Test $test, Exception $e) + { + $this->writeNotOk($test, '', 'TODO Incomplete Test'); + } + + /** + * Skipped test. + * + * @param PHPUnit2_Framework_Test $test + * @param Exception $e + * @access public + * @since Method available since Release 3.0.0 + */ + public function addSkippedTest(PHPUnit2_Framework_Test $test, Exception $e) + { + $this->write( + sprintf( + "ok %s - # SKIP%s\n", + + $this->testNumber, + $e->getMessage() != '' ? ' ' . $e->getMessage() : '' + ) + ); + } + + /** + * A testsuite started. + * + * @param PHPUnit2_Framework_TestSuite $suite + * @access public + */ + public function startTestSuite(PHPUnit2_Framework_TestSuite $suite) + { + $this->write( + sprintf( + "# TestSuite \"%s\" started.\n", + + $suite->getName() + ) + ); + } + + /** + * A testsuite ended. + * + * @param PHPUnit2_Framework_TestSuite $suite + * @access public + */ + public function endTestSuite(PHPUnit2_Framework_TestSuite $suite) + { + $this->write( + sprintf( + "# TestSuite \"%s\" ended.\n", + + $suite->getName() + ) + ); + } + + /** + * A test started. + * + * @param PHPUnit2_Framework_Test $test + * @access public + */ + public function startTest(PHPUnit2_Framework_Test $test) + { + $this->testNumber++; + $this->testSuccessful = TRUE; + } + + /** + * A test ended. + * + * @param PHPUnit2_Framework_Test $test + * @access public + */ + public function endTest(PHPUnit2_Framework_Test $test) + { + if ($this->testSuccessful === TRUE) { + $this->write( + sprintf( + "ok %s - %s\n", + + $this->testNumber, + PHPUnit2_Util_Test::describe($test) + ) + ); + } + } + + /** + * @param PHPUnit2_Framework_Test $test + * @param string $prefix + * @param string $directive + * @access private + */ + private function writeNotOk(PHPUnit2_Framework_Test $test, $prefix = '', $directive = '') + { + $this->write( + sprintf( + "not ok %s - %s%s%s\n", + + $this->testNumber, + $prefix != '' ? $prefix . ': ' : '', + PHPUnit2_Util_Test::describe($test), + $directive != '' ? ' # ' . $directive : '' + ) + ); + + $this->testSuccessful = FALSE; + } +} + +/* + * 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..c8917c9ba9d --- /dev/null +++ b/Util/Log/XML.php @@ -0,0 +1,379 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Util/Printer.php'; +require_once 'PHPUnit2/Util/Timer.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * 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; + + /** + * 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); + + parent::__construct($out); + } + + /** + * Flush buffer and close output. + * + * @access public + */ + public function flush() + { + if ($this->writeDocument === TRUE) { + $this->write($this->getXML()); + } + + parent::flush(); + } + + /** + * 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, FALSE)); + $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, FALSE)); + $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, FALSE)); + $error->setAttribute('message', 'Incomplete Test'); + $error->setAttribute('type', get_class($e)); + + $this->currentTestCase->appendChild($error); + + $this->testSuiteErrors[$this->testSuiteLevel]++; + } + + /** + * Skipped test. + * + * @param PHPUnit2_Framework_Test $test + * @param Exception $e + * @access public + * @since Method available since Release 3.0.0 + */ + public function addSkippedTest(PHPUnit2_Framework_Test $test, Exception $e) + { + $error = $this->document->createElement('error', PHPUnit2_Util_Filter::getFilteredStacktrace($e, FALSE)); + $error->setAttribute('message', 'Skipped 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]++; + + PHPUnit2_Util_Timer::start(); + } + + /** + * A test ended. + * + * @param PHPUnit2_Framework_Test $test + * @access public + */ + public function endTest(PHPUnit2_Framework_Test $test) + { + $time = PHPUnit2_Util_Timer::stop(); + + $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 flush(). + * + * 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..117d2f606f1 --- /dev/null +++ b/Util/Printer.php @@ -0,0 +1,124 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * 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, 'wt'); + } else { + $this->out = $out; + } + } + } + + /** + * Flush buffer and close output. + * + * @access public + */ + public function flush() + { + 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/Report.php b/Util/Report.php new file mode 100644 index 00000000000..ec052c85df2 --- /dev/null +++ b/Util/Report.php @@ -0,0 +1,137 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Util/Report/Coverage/Factory.php'; +require_once 'PHPUnit2/Util/Report/Test/Factory.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, '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 3.0.0 + * @abstract + */ +abstract class PHPUnit2_Util_Report +{ + /** + * Renders the report. + * + * @param PHPUnit2_Framework_TestResult $result + * @param string $target + * @access public + * @static + */ + public static function render(PHPUnit2_Framework_TestResult $result, $target) + { + $tests = PHPUnit2_Util_Report_Test_Factory::create($result); + $coverage = PHPUnit2_Util_Report_Coverage_Factory::create($result, $tests); + + $coverage->render($target, $result->topTestSuite()->getName()); + $tests->render($target, $result->topTestSuite()->getName()); + + self::copyFiles($target); + } + + /** + * @param string $target + * @access protected + * @static + */ + protected static function copyFiles($target) + { + $files = array( + 'butter.png', + 'chameleon.png', + 'scarlet_red.png', + 'snow.png', + 'style.css', + ); + + $path = self::getTemplatePath(); + + foreach ($files as $file) { + copy($path . $file, $target . $file); + } + } + + /** + * @return string + * @access public + * @static + */ + public static function getTemplatePath() + { + return sprintf( + '%s%sReport%sTemplate%s', + + dirname(__FILE__), + DIRECTORY_SEPARATOR, + DIRECTORY_SEPARATOR, + DIRECTORY_SEPARATOR + ); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Util/Report/Coverage/Factory.php b/Util/Report/Coverage/Factory.php new file mode 100644 index 00000000000..bd29f747366 --- /dev/null +++ b/Util/Report/Coverage/Factory.php @@ -0,0 +1,358 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Util/Array.php'; +require_once 'PHPUnit2/Util/Report/Coverage/Node/Directory.php'; +require_once 'PHPUnit2/Util/Report/Coverage/Node/File.php'; +require_once 'PHPUnit2/Util/Report/Test/Node/TestSuite.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Factory for a code coverage information tree. + * + * @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 3.0.0 + */ +abstract class PHPUnit2_Util_Report_Coverage_Factory +{ + /** + * Creates a new Code Coverage information tree. + * + * @param PHPUnit2_Framework_TestResult $result + * @param PHPUnit2_Util_Report_Test_Node_TestSuite $testSuite + * @return PHPUnit2_Util_Report_Coverage_Node_Directory + * @access public + * @static + */ + public static function create(PHPUnit2_Framework_TestResult $result, PHPUnit2_Util_Report_Test_Node_TestSuite $testSuite) + { + $files = self::getSummary($result); + $commonPath = self::reducePaths($files); + $items = self::buildDirectoryStructure($files); + $root = new PHPUnit2_Util_Report_Coverage_Node_Directory($commonPath); + + self::addItems($root, $items, $testSuite, $files); + + return $root; + } + + /** + * @param PHPUnit2_Util_Report_Coverage_Node_Directory $root + * @param array $items + * @param PHPUnit2_Util_Report_Test_Node_TestSuite $testSuite + * @param array $files + * @access protected + * @static + */ + protected static function addItems(PHPUnit2_Util_Report_Coverage_Node_Directory $root, Array $items, PHPUnit2_Util_Report_Test_Node_TestSuite $testSuite, Array $files) + { + foreach ($items as $key => $value) { + if (substr($key, -2) == '/f') { + try { + $file = $root->addFile(substr($key, 0, -2), $value); + $file->setupCoveringTests($testSuite, $files); + } + + catch (RuntimeException $e) { + continue; + } + } else { + $child = $root->addDirectory($key); + self::addItems($child, $value, $testSuite, $files); + } + } + } + + /** + * Returns summarized Code Coverage data. + * + * Format of the result array: + * + * + * array( + * "/tested/code.php" => array( + * linenumber => number of tests that executed the line + * ) + * ) + * + * + * @param PHPUnit2_Framework_TestResult $result + * @return array + * @access protected + * @static + * @since Method available since Release 2.2.0 + */ + protected static function getSummary(PHPUnit2_Framework_TestResult $result) + { + $summary = array(); + + if (!defined('PHPUnit2_INSIDE_OWN_TESTSUITE')) { + $codeCoverageInformation = $result->getCodeCoverageInformation(); + } else { + $codeCoverageInformation = $result->getCodeCoverageInformation(TRUE, FALSE); + } + + foreach ($codeCoverageInformation as $test) { + foreach ($test['files'] as $file => $lines) { + if (strpos($file, 'eval()\'d code') || strpos($file, 'runtime-created function')) { + continue; + } + + foreach ($lines as $line => $flag) { + if (!isset($summary[$file][$line])) { + if ($flag < 0) { + $summary[$file][$line] = array(); + } else { + $summary[$file][$line] = array($test['test']); + } + } else { + if ($flag > 0) { + $summary[$file][$line][] = $test['test']; + } + } + } + } + } + + return $summary; + } + + /** + * Builds an array representation of the directory structure. + * + * For instance, + * + * + * Array + * ( + * [Money.php] => Array + * ( + * ... + * ) + * + * [MoneyBag.php] => Array + * ( + * ... + * ) + * ) + * + * + * is transformed into + * + * + * Array + * ( + * [.] => Array + * ( + * [Money.php] => Array + * ( + * ... + * ) + * + * [MoneyBag.php] => Array + * ( + * ... + * ) + * ) + * ) + * + * + * @param array $files + * @return array + * @access protected + * @static + */ + protected static function buildDirectoryStructure($files) + { + $result = array(); + + foreach ($files as $path => $file) { + $path = explode('/', $path); + $pointer = &$result; + $max = count($path); + + for ($i = 0; $i < $max; $i++) { + if ($i == ($max - 1)) { + $type = '/f'; + } else { + $type = ''; + } + + $pointer = &$pointer[$path[$i] . $type]; + } + + $pointer = $file; + } + + return $result; + } + + /** + * Reduces the paths by cutting the longest common start path. + * + * For instance, + * + * + * Array + * ( + * [/home/sb/PHPUnit2/Samples/Money/Money.php] => Array + * ( + * ... + * ) + * + * [/home/sb/PHPUnit2/Samples/Money/MoneyBag.php] => Array + * ( + * ... + * ) + * ) + * + * + * is reduced to + * + * + * Array + * ( + * [Money.php] => Array + * ( + * ... + * ) + * + * [MoneyBag.php] => Array + * ( + * ... + * ) + * ) + * + * + * @param array $files + * @return string + * @access protected + * @static + */ + protected static function reducePaths(&$files) + { + if (empty($files)) { + return '.'; + } + + $commonPath = ''; + $paths = array_keys($files); + + if (count($files) == 1) { + $commonPath = dirname($paths[0]); + $files[basename($paths[0])] = $files[$paths[0]]; + + unset($files[$paths[0]]); + + return $commonPath; + } + + $max = count($paths); + + for ($i = 0; $i < $max; $i++) { + $paths[$i] = explode(DIRECTORY_SEPARATOR, $paths[$i]); + + if (empty($paths[$i][0])) { + $paths[$i][0] = DIRECTORY_SEPARATOR; + } + } + + $done = FALSE; + + $max = count($paths); + + while (!$done) { + for ($i = 0; $i < $max - 1; $i++) { + if (!isset($paths[$i][0]) || + !isset($paths[$i+1][0]) || + $paths[$i][0] != $paths[$i+1][0]) { + $done = TRUE; + break; + } + } + + if (!$done) { + $commonPath .= $paths[0][0] . (($paths[0][0] != DIRECTORY_SEPARATOR) ? DIRECTORY_SEPARATOR : ''); + + for ($i = 0; $i < $max; $i++) { + array_shift($paths[$i]); + } + } + } + + $original = array_keys($files); + $max = count($original); + + for ($i = 0; $i < $max; $i++) { + $files[join('/', $paths[$i])] = $files[$original[$i]]; + unset($files[$original[$i]]); + } + + $files = PHPUnit2_Util_Array::sortRecursively($files); + + return $commonPath; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Util/Report/Coverage/Node.php b/Util/Report/Coverage/Node.php new file mode 100644 index 00000000000..2ca6e4d547b --- /dev/null +++ b/Util/Report/Coverage/Node.php @@ -0,0 +1,311 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Util/Filesystem.php'; +require_once 'PHPUnit2/Util/Test.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Base class for nodes in the code coverage information tree. + * + * @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 3.0.0 + */ +abstract class PHPUnit2_Util_Report_Coverage_Node +{ + /** + * @var array + * @access protected + */ + protected $cache = array(); + + /** + * @var string + * @access protected + */ + protected $name; + + /** + * @var PHPUnit2_Util_CodeCoverage_Node + * @access protected + */ + protected $parent; + + /** + * Constructor. + * + * @param string $name + * @param PHPUnit2_Util_CodeCoverage_Node $parent + * @access public + */ + public function __construct($name, PHPUnit2_Util_Report_Coverage_Node $parent = NULL) + { + $this->name = $name; + $this->parent = $parent; + } + + /** + * Returns the percentage of executed lines. + * + * @return integer + * @access public + */ + public function getExecutedPercent() + { + $numExecutableLines = $this->getNumExecutableLines(); + + if ($numExecutableLines > 0) { + $percent = ($this->getNumExecutedLines() / $numExecutableLines) * 100; + } else { + $percent = 100; + } + + return sprintf( + '%01.2f', + $percent + ); + } + + /** + * Returns this node's ID. + * + * @return string + * @access public + */ + public function getId() { + if (!isset($this->cache['id'])) { + if ($this->parent === NULL) { + $this->cache['id'] = 'index'; + } else { + $parentId = $this->parent->getId(); + + if ($parentId == 'index') { + $this->cache['id'] = $this->getName(); + } else { + $this->cache['id'] = $parentId . '_' . $this->getName(); + } + } + } + + return $this->cache['id']; + } + + /** + * Returns this node's name. + * + * @param boolean $includeParent + * @return string + * @access public + */ + public function getName($includeParent = FALSE, $includeCommonPath = FALSE) + { + if ($includeParent && $this->parent !== NULL) { + if (!isset($this->cache['nameIncludingParent'])) { + $parent = $this->parent->getName(TRUE); + $this->cache['nameIncludingParent'] = !empty($parent) ? $parent . '/' . $this->name : $this->name; + } + + return $this->cache['nameIncludingParent']; + } else { + if ($this->parent !== NULL) { + return $this->name; + } else { + return $includeCommonPath ? $this->name : ''; + } + } + } + + /** + * Returns the link to this node. + * + * @param boolean $details + * @param boolean $full + * @return string + * @access public + */ + public function getLink($details, $full) { + if (substr($this->name, -1) == DIRECTORY_SEPARATOR) { + $name = substr($this->name, 0, -1); + } else { + $name = $this->name; + } + + $cleanId = PHPUnit2_Util_Filesystem::getSafeFilename($this->getId()); + + if ($full) { + if ($this->parent !== NULL) { + $parent = $this->parent->getLink(FALSE, TRUE) . DIRECTORY_SEPARATOR; + } else { + $parent = ''; + } + + return sprintf( + '%s%s', + $parent, + $cleanId, + $details ? '-details' : '', + $name + ); + } else { + return sprintf( + '%s', + $cleanId, + $details ? '-details' : '', + $name + ); + } + } + + /** + * Returns this node's path. + * + * @return string + * @access public + */ + public function getPath() { + if (!isset($this->cache['path'])) { + if ($this->parent === NULL) { + $this->cache['path'] = $this->getName(FALSE, TRUE); + } else { + if (substr($this->parent->getPath(), -1) == DIRECTORY_SEPARATOR) { + $this->cache['path'] = $this->parent->getPath() . $this->getName(FALSE, TRUE); + } else { + $this->cache['path'] = $this->parent->getPath() . DIRECTORY_SEPARATOR . $this->getName(FALSE, TRUE); + } + } + } + + return $this->cache['path']; + } + + /** + * @param PHPUnit2_Util_Template $template + * @param string $title + * @access public + */ + protected function setTemplateVars(PHPUnit2_Util_Template $template, $title) + { + $template->setVar( + array( + 'title', + 'link', + 'executable_lines', + 'executed_lines', + 'executed_percent', + 'date', + 'phpunit_version', + 'xdebug_version', + ), + array( + $title, + $this->getLink(FALSE, TRUE), + $this->getNumExecutableLines(), + $this->getNumExecutedLines(), + $this->getExecutedPercent(), + date('D M j G:i:s T Y'), + PHPUnit2_Runner_Version::id(), + phpversion('xdebug') + ) + ); + } + + /** + * Returns the covering tests. + * + * @return array + * @access public + * @abstract + */ + abstract public function getCoveringTests(); + + /** + * Returns the number of executable lines. + * + * @return integer + * @access public + * @abstract + */ + abstract public function getNumExecutableLines(); + + /** + * Returns the number of executed lines. + * + * @return integer + * @access public + * @abstract + */ + abstract public function getNumExecutedLines(); + + /** + * Renders this node. + * + * @param string $target + * @param string $title + * @access public + * @abstract + */ + abstract public function render($target, $title); +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Util/Report/Coverage/Node/Directory.php b/Util/Report/Coverage/Node/Directory.php new file mode 100644 index 00000000000..54cc6e2123d --- /dev/null +++ b/Util/Report/Coverage/Node/Directory.php @@ -0,0 +1,432 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Util/Filesystem.php'; +require_once 'PHPUnit2/Util/Template.php'; +require_once 'PHPUnit2/Util/Report/Coverage/Node.php'; +require_once 'PHPUnit2/Util/Report/Coverage/Node/File.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Represents a directory in the code coverage information tree. + * + * @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 3.0.0 + */ +class PHPUnit2_Util_Report_Coverage_Node_Directory extends PHPUnit2_Util_Report_Coverage_Node +{ + /** + * @var PHPUnit2_Util_Report_Coverage_Node[] + * @access protected + */ + protected $children = array(); + + /** + * @var PHPUnit2_Util_Report_Coverage_Node_Directory[] + * @access protected + */ + protected $directories = array(); + + /** + * @var PHPUnit2_Util_Report_Coverage_Node_File[] + * @access protected + */ + protected $files = array(); + + /** + * @var integer + * @access protected + */ + protected $numExecutableLines = -1; + + /** + * @var integer + * @access protected + */ + protected $numExecutedLines = -1; + + /** + * Adds a new directory. + * + * @return PHPUnit2_Util_Report_Coverage_Node_Directory + * @access public + */ + public function addDirectory($name) + { + $directory = new PHPUnit2_Util_Report_Coverage_Node_Directory( + $name, + $this + ); + + $this->children[] = $directory; + $this->directories[] = &$this->children[count($this->children) - 1]; + + return $directory; + } + + /** + * Adds a new file. + * + * @param string $name + * @param array $lines + * @return PHPUnit2_Util_Report_Coverage_Node_File + * @throws RuntimeException + * @access public + */ + public function addFile($name, Array $lines) + { + $file = new PHPUnit2_Util_Report_Coverage_Node_File( + $name, + $this, + $lines + ); + + $this->children[] = $file; + $this->files[] = &$this->children[count($this->children) - 1]; + + $this->numExecutableLines = -1; + $this->numExecutedLines = -1; + + return $file; + } + + /** + * Returns the directories in this directory. + * + * @return + * @access public + */ + public function getDirectories() + { + return $this->directories; + } + + /** + * Returns the files in this directory. + * + * @return + * @access public + */ + public function getFiles() + { + return $this->files; + } + + /** + * Returns the tests covering this directory. + * + * @return array + * @access public + */ + public function getCoveringTests() + { + $coveringTests = array(); + + foreach ($this->children as $child) { + $coveringTests = array_merge($coveringTests, $child->getCoveringTests()); + } + + return $coveringTests; + } + + /** + * Returns the number of executable lines. + * + * @return integer + * @access public + */ + public function getNumExecutableLines() + { + if ($this->numExecutableLines == -1) { + $this->numExecutableLines = 0; + + foreach ($this->children as $child) { + $this->numExecutableLines += $child->getNumExecutableLines(); + } + } + + return $this->numExecutableLines; + } + + /** + * Returns the number of executed lines. + * + * @return integer + * @access public + */ + public function getNumExecutedLines() + { + if ($this->numExecutedLines == -1) { + $this->numExecutedLines = 0; + + foreach ($this->children as $child) { + $this->numExecutedLines += $child->getNumExecutedLines(); + } + } + + return $this->numExecutedLines; + } + + /** + * Renders this node. + * + * @param string $target + * @param string $title + * @access public + */ + public function render($target, $title) + { + $this->doRender($target, $title, TRUE); + $this->doRender($target, $title, FALSE); + + foreach ($this->children as $child) { + $child->render($target, $title); + } + } + + /** + * @param string $target + * @param boolean $includeDetails + * @access protected + */ + protected function doRender($target, $title, $includeDetails) + { + $cleanId = PHPUnit2_Util_Filesystem::getSafeFilename($this->getId()); + $file = $target . $cleanId; + + if ($includeDetails) { + $file .= '-details.htm'; + + $detailsLink = sprintf( + '(hide details)', + $cleanId + ); + } else { + $file .= '.htm'; + + $detailsLink = sprintf( + '(show details)', + $cleanId + ); + } + + $template = new PHPUnit2_Util_Template( + PHPUnit2_Util_Report::getTemplatePath() . + 'coverage_directory.htm' + ); + + $this->setTemplateVars($template, $title); + + $template->setVar( + array( + 'items', + 'details_link' + ), + array( + $this->renderItems($includeDetails), + $detailsLink + ) + ); + + $template->renderTo($file); + } + + /** + * @param boolean $includeDetails + * @return string + * @access protected + */ + protected function renderItems($includeDetails) + { + $items = $this->doRenderItems($this->directories, $includeDetails); + $items .= $this->doRenderItems($this->files, $includeDetails); + + return $items; + } + + /** + * @param array $items + * @param boolean $includeDetails + * @return string + * @access protected + */ + protected function doRenderItems(Array $items, $includeDetails) + { + $result = ''; + + foreach ($items as $item) { + $itemTemplate = new PHPUnit2_Util_Template( + PHPUnit2_Util_Report::getTemplatePath() . + 'coverage_item.htm' + ); + + $details = ''; + + if ($includeDetails) { + foreach ($item->getCoveringTests() as $suite => $tests) { + $detailsHeaderTemplate = new PHPUnit2_Util_Template( + PHPUnit2_Util_Report::getTemplatePath() . + 'coverage_item_details_header.htm' + ); + + $detailsHeaderTemplate->setVar( + 'link', + sprintf( + '%s', + + PHPUnit2_Util_Filesystem::getSafeFilename($suite), + $suite + ) + ); + + $details .= $detailsHeaderTemplate->render(); + + foreach ($tests as $test => $_test) { + $detailsTemplate = new PHPUnit2_Util_Template( + PHPUnit2_Util_Report::getTemplatePath() . + 'coverage_item_details.htm' + ); + + if ($_test['object']->getResult() !== PHPUnit2_Runner_BaseTestRunner::STATUS_PASSED) { + $failure = sprintf( + '
%s
', + + htmlspecialchars($_test['object']->getResult()->exceptionMessage()) + ); + } else { + $failure = ''; + } + + $detailsTemplate->setVar( + array( + 'item', + 'executed_percent', + 'executed_lines', + 'executable_lines' + ), + array( + $test . $failure, + sprintf( + '%01.2f', + ($_test['numLinesExecuted'] / $item->getNumExecutableLines()) * 100 + ), + $_test['numLinesExecuted'], + $item->getNumExecutableLines() + ) + ); + + $details .= $detailsTemplate->render(); + } + } + } + + $floorPercent = floor($item->getExecutedPercent()); + + if ($floorPercent < 15) { + $color = 'scarlet_red'; + $level = 'Lo'; + } + + else if ($floorPercent >= 15 && $floorPercent < 50) { + $color = 'butter'; + $level = 'Med'; + } + + else { + $color = 'chameleon'; + $level = 'Hi'; + } + + $itemTemplate->setVar( + array( + 'link', + 'color', + 'level', + 'executed_width', + 'executed_percent', + 'not_executed_width', + 'executable_lines', + 'executed_lines', + 'details' + ), + array( + $item->getLink(FALSE, FALSE), + $color, + $level, + floor($item->getExecutedPercent()), + $item->getExecutedPercent(), + 100 - floor($item->getExecutedPercent()), + $item->getNumExecutableLines(), + $item->getNumExecutedLines(), + $details + ) + ); + + $result .= $itemTemplate->render(); + } + + return $result; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Util/Report/Coverage/Node/File.php b/Util/Report/Coverage/Node/File.php new file mode 100644 index 00000000000..c7484f56299 --- /dev/null +++ b/Util/Report/Coverage/Node/File.php @@ -0,0 +1,376 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Util/Array.php'; +require_once 'PHPUnit2/Util/Filesystem.php'; +require_once 'PHPUnit2/Util/Template.php'; +require_once 'PHPUnit2/Util/Report/Coverage/Node.php'; +require_once 'PHPUnit2/Util/Report/Test/Node/TestSuite.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, '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 3.0.0 + */ +class PHPUnit2_Util_Report_Coverage_Node_File extends PHPUnit2_Util_Report_Coverage_Node +{ + /** + * @var array + * @access protected + */ + protected $codeLines; + + /** + * @var array + * @access protected + */ + protected $coveringTests = array(); + + /** + * @var array + * @access protected + */ + protected $executedLines; + + /** + * @var integer + * @access protected + */ + protected $numExecutedLines = -1; + + /** + * Constructor. + * + * @param string $name + * @param PHPUnit2_Util_CodeCoverage_Node $parent + * @param array $lines + * @throws RuntimeException + * @access public + */ + public function __construct($name, PHPUnit2_Util_Report_Coverage_Node $parent, Array $executedLines) + { + parent::__construct($name, $parent); + + $path = $this->getPath(); + + if (!file_exists($path)) { + throw new RuntimeException; + } + + $this->codeLines = file($path); + $this->executedLines = $executedLines; + + $this->cleanupExecutableLines(); + } + + /** + * @access protected + */ + protected function cleanupExecutableLines() + { + if (!function_exists('token_get_all')) { + return; + } + + $inComment = FALSE; + $i = 1; + + foreach ($this->codeLines as $line) { + $line = trim($line); + + switch ($line) { + case '{': + case '}': { + $this->executedLines[$i] = 1; + + $i++; + continue 2; + } + break; + + case '': { + if (isset($this->executedLines[$i])) { + unset($this->executedLines[$i]); + } + + $i++; + continue 2; + } + } + + if (strpos($line, '*/') === 0) { + $inComment = FALSE; + + if (isset($this->executedLines[$i])) { + unset($this->executedLines[$i]); + } + + $i++; + continue; + } + + if ($inComment || (strpos($line, '//') === 0)) { + if (isset($this->executedLines[$i])) { + unset($this->executedLines[$i]); + } + + $i++; + continue; + } + + if (strpos($line, '/*') === 0) { + $inComment = TRUE; + + if (isset($this->executedLines[$i])) { + unset($this->executedLines[$i]); + } + + $i++; + continue; + } + + $tokens = token_get_all(''); + + foreach ($tokens as $token) { + if (is_string($token)) { + $i++; + continue 2; + } + + switch ($token[0]) { + case T_PRIVATE: + case T_PUBLIC: + case T_PROTECTED: + case T_FUNCTION: + case T_CLASS: + case T_REQUIRE: + case T_REQUIRE_ONCE: + case T_INCLUDE: + case T_INCLUDE_ONCE: { + $this->executedLines[$i] = 1; + } + } + } + + $i++; + } + } + + /** + * @param PHPUnit2_Util_Report_Test_Node_TestSuite $testSuite + * @param array $files + * @access protected + * @static + */ + public function setupCoveringTests(PHPUnit2_Util_Report_Test_Node_TestSuite $testSuite, $files) + { + $testCase = array(); + $thisName = $this->getName(TRUE); + + foreach ($files as $file => $lines) { + if ($thisName == $file) { + foreach ($lines as $line => $tests) { + foreach ($tests as $test) { + $testId = $test->__testNode->testId; + + if (!isset($testCase[$testId])) { + $testCase[$testId] = array('numLinesExecuted' => 1, 'object' => $test); + } else { + $testCase[$testId]['numLinesExecuted']++; + } + } + } + } + } + + foreach ($testCase as $coveringTest) { + $test = $coveringTest['object']; + $test = $testSuite->lookupTest($test); + $name = $test->getName(TRUE); + + if (!isset($this->coveringTests[$name[0]])) { + $this->coveringTests[$name[0]] = array(); + } + + $found = FALSE; + + foreach ($this->coveringTests[$name[0]] as $_name => $coveringTest) { + if ($coveringTest['object'] === $test) { + $found = TRUE; + + break; + } + } + + if (!$found) { + $test->addCoveredFile($this); + + $this->coveringTests[$name[0]][$name[1]] = array( + 'numLinesExecuted' => $coveringTest['numLinesExecuted'], + 'object' => $test + ); + } else { + $this->coveringTests[$name[0]][$name[1]]['numLinesExecuted'] += $coveringTest['numLinesExecuted']; + } + } + + $this->coveringTests = PHPUnit2_Util_Array::sortRecursively($this->coveringTests); + } + + /** + * Returns the tests covering this file. + * + * @return array + * @access public + */ + public function getCoveringTests() + { + return $this->coveringTests; + } + + /** + * Returns the number of executable lines. + * + * @return integer + * @access public + */ + public function getNumExecutableLines() + { + return count($this->executedLines); + } + + /** + * Returns the number of executed lines. + * + * @return integer + * @access public + */ + public function getNumExecutedLines() + { + if ($this->numExecutedLines == -1) { + $this->numExecutedLines = 0; + + foreach ($this->executedLines as $line) { + if (count($line) > 0) { + $this->numExecutedLines++; + } + } + } + + return $this->numExecutedLines; + } + + /** + * Renders this node. + * + * @param string $target + * @param string $title + * @access public + */ + public function render($target, $title) + { + $template = new PHPUnit2_Util_Template( + PHPUnit2_Util_Report::getTemplatePath() . + 'coverage_file.htm' + ); + + $i = 1; + $lines = ''; + + foreach ($this->codeLines as $line) { + $css = ''; + + if (isset($this->executedLines[$i])) { + $css = sprintf( + ' %8d : ', + + count($this->executedLines[$i]) > 0 ? 'lineCov' : 'lineNoCov', + count($this->executedLines[$i]) + ); + } + + $lines .= sprintf( + '%8d %s%s%s' . "\n", + + $i, + !empty($css) ? $css : ' : ', + htmlspecialchars(rtrim($line)), + !empty($css) ? '' : '' + ); + + $i++; + } + + $this->setTemplateVars($template, $title); + $template->setVar('lines', $lines); + + $cleanId = PHPUnit2_Util_Filesystem::getSafeFilename($this->getId()); + $template->renderTo($target . $cleanId . '.htm'); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Util/Report/Template/butter.png b/Util/Report/Template/butter.png new file mode 100644 index 0000000000000000000000000000000000000000..3c7e36f2da2e0557f70191ceb58b58187fa46292 GIT binary patch literal 150 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx1SBVv2j2ryoCO|{#S9GG!XV7ZFl&wkP>{XE z)7O>#8Y?HeiPce~l`DWkvL&t&CC>S|xv6<249-QVi6yBi3gww4844j8sS56%z5(x3 pRP%rec|2VlLpZJ{|M+}Ko`F@8$+T(TnfpL-22WQ%mvv4FO#nkKCNls4 literal 0 HcmV?d00001 diff --git a/Util/Report/Template/chameleon.png b/Util/Report/Template/chameleon.png new file mode 100644 index 0000000000000000000000000000000000000000..68046070133a2c309839b9d340ced4c521fa9d3b GIT binary patch literal 150 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx1SBVv2j2ryoCO|{#S9GG!XV7ZFl&wkP>{XE z)7O>#8Y?HesrbxqN9F*9WJ_ElN}Tg^b5rw57@Uhz6H8K46v{J8G895GQWe}ieFNU7 psOA9`@_4#9hHzX@eo>Xe#K1g@abe4bR%xI(gQu&X%Q~loCID3dC3gS- literal 0 HcmV?d00001 diff --git a/Util/Report/Template/coverage_directory.htm b/Util/Report/Template/coverage_directory.htm new file mode 100644 index 00000000000..170d60ebf79 --- /dev/null +++ b/Util/Report/Template/coverage_directory.htm @@ -0,0 +1,83 @@ + + + + + + {title} + + + + + + + + + + + + + + +
{title}
+ + + + + + + + + + + + + + + + + + + + + + + +
Current view:{link}
Date:{date}Executable lines:{executable_lines}
Code covered:{executed_percent}%Executed lines:{executed_lines}
Legend: + + Low: 0% to 15% + + + Medium: 15% to 50% + + + High: 50% to 100% + +
+
+ +
+ + + + + + + + + + + +{items} +

Coverage {details_link}
+
+ +
+ + + + +
Generated by: PHPUnit {phpunit_version} and Xdebug {xdebug_version}.
+ +
+ + diff --git a/Util/Report/Template/coverage_file.htm b/Util/Report/Template/coverage_file.htm new file mode 100644 index 00000000000..490b089b197 --- /dev/null +++ b/Util/Report/Template/coverage_file.htm @@ -0,0 +1,75 @@ + + + + + + {title} + + + + + + + + + + + + + + + +
{title}
+ + + + + + + + + + + + + + + + + + + + + + + +
Current view:{link}
Date:{date}Executable lines:{executable_lines}
Code covered:{executed_percent}%Executed lines:{executed_lines}
Legend: + not executed + executed +
+
+ +
+ + + + + + + + +

+
+{lines}
+
+
+ + + + +
Generated by: PHPUnit {phpunit_version} and Xdebug {xdebug_version}.
+ +
+ + + diff --git a/Util/Report/Template/coverage_item.htm b/Util/Report/Template/coverage_item.htm new file mode 100644 index 00000000000..edfcc6068dc --- /dev/null +++ b/Util/Report/Template/coverage_item.htm @@ -0,0 +1,14 @@ + + {link} + + + + + +
{executed_percent} %{executed_percent}%
+ + + {executed_percent}% + {executed_lines} / {executable_lines} lines + +{details} diff --git a/Util/Report/Template/coverage_item_details.htm b/Util/Report/Template/coverage_item_details.htm new file mode 100644 index 00000000000..604a0d41ef8 --- /dev/null +++ b/Util/Report/Template/coverage_item_details.htm @@ -0,0 +1,5 @@ + + {item} + {executed_percent}% + {executed_lines} / {executable_lines} lines + diff --git a/Util/Report/Template/coverage_item_details_header.htm b/Util/Report/Template/coverage_item_details_header.htm new file mode 100644 index 00000000000..789ccb4d3d8 --- /dev/null +++ b/Util/Report/Template/coverage_item_details_header.htm @@ -0,0 +1,4 @@ + + {link} + Lines hit + diff --git a/Util/Report/Template/glass.png b/Util/Report/Template/glass.png new file mode 100644 index 0000000000000000000000000000000000000000..e1abc00680a3093c49fdb775ae6bdb6764c95af2 GIT binary patch literal 167 zcmeAS@N?(olHy`uVBq!ia0vp^j3CU&3?x-=hn)gaEa{HEjtmSN`?>!lvI6;R0X`wF z|Ns97GD8ntt^-nxB|(0{3=Yq3q=7g|-tI089jvk*Kn`btM`SSr1Gf+eGhVt|_XjA* zUgGKN%6^Gmn4d%Ph(nkFP>9RZ#WAE}PI3Z}&BVayv3^M*kj3EX>gTe~DWM4f=_Dpv literal 0 HcmV?d00001 diff --git a/Util/Report/Template/scarlet_red.png b/Util/Report/Template/scarlet_red.png new file mode 100644 index 0000000000000000000000000000000000000000..a879424d5a211cb33221e66174277791f59013eb GIT binary patch literal 150 zcmeAS@N?(olHy`uVBq!ia0vp^j3CUx1SBVv2j2ryoCO|{#S9GG!XV7ZFl&wkP>{XE z)7O>#8Y?HesoB-}R}KM%WJ_ElN}Tg^b5rw57@Uhz6H8K46v{J8G895GQWe}ieFNU7 psOA9`@_4#9hHzX@u2{d4lY!ZX(W(5B_f()bgQu&X%Q~loCIDbBC29Zw literal 0 HcmV?d00001 diff --git a/Util/Report/Template/snow.png b/Util/Report/Template/snow.png new file mode 100644 index 0000000000000000000000000000000000000000..2cdae107fceec6e7f02ac7acb4a34a82a540caa5 GIT binary patch literal 141 zcmeAS@N?(olHy`uVBq!ia0vp^j3CU&3?x-=hn)ga>?NMQuI!iC1^MM!lvI6;R0X`wF|Ns97GD8ntt^-nBo-U3d c6}OTTfNUlP#;5A{K>8RwUHx3vIVCg!071?oo&W#< literal 0 HcmV?d00001 diff --git a/Util/Report/Template/style.css b/Util/Report/Template/style.css new file mode 100644 index 00000000000..2a91807925f --- /dev/null +++ b/Util/Report/Template/style.css @@ -0,0 +1,354 @@ +/* All views: initial background and text color */ +body +{ + color: #000000; + background-color: #eeeeec; +} + +/* All views: standard link format*/ +a:link +{ + color: #000000; + text-decoration: underline; +} + +/* All views: standard link - visited format */ +a:visited +{ + color: #000000; + text-decoration: underline; +} + +/* All views: standard link - activated format */ +a:active +{ + color: #000000; + text-decoration: underline; +} + +/* All views: main title format */ +td.title +{ + text-align: center; + padding-bottom: 10px; + font-family: sans-serif; + font-style: italic; + font-weight: bold; +} + +/* All views: header item format */ +td.headerItem +{ + text-align: right; + padding-right: 6px; + font-family: sans-serif; + font-weight: bold; +} + +/* All views: header item value format */ +td.headerValue +{ + text-align: left; + font-family: sans-serif; + font-weight: bold; +} + +/* All views: header legend item format */ +td.legendItem +{ + text-align: right; + padding-right: 6px; + padding-top: 10px; + padding-bottom: 2px; + font-family: sans-serif; + font-weight: bold; +} + +/* All views: header legend item value format */ +td.legendValue +{ + text-align: left; + padding-top: 10px; + padding-bottom: 2px; + color: #000000; + font-family: sans-serif; + font-weight: bold; +} + +/* All views: color of horizontal ruler */ +td.ruler +{ + background-color: #3465a4; +} + +/* All views: version string format */ +td.versionInfo +{ + text-align: center; + padding-top: 2px; + font-family: sans-serif; + font-style: italic; +} + +/* Directory view/File view (all)/Test case descriptions: + table headline format */ +td.tableHead +{ + text-align: center; + color: #ffffff; + background-color: #3465a4; + font-family: sans-serif; + font-weight: bold; +} + +/* Directory view/File view (all): filename entry format */ +td.coverFile +{ + text-align: left; + padding-left: 10px; + padding-right: 20px; + background-color: #729fcf; + font-family: monospace; +} + +/* Directory view/File view (all): bar-graph entry format*/ +td.coverBar +{ + padding-left: 10px; + padding-right: 10px; + background-color: #729fcf; +} + +/* Directory view/File view (all): bar-graph outline color */ +td.coverBarOutline +{ + background-color: #000000; +} + +/* Directory view/File view (all): percentage entry for files with + high coverage rate */ +td.coverPerHi +{ + text-align: right; + padding-left: 10px; + padding-right: 10px; + background-color: #8ae234; + font-weight: bold; +} + +/* Directory view/File view (all): line count entry for files with + high coverage rate */ +td.coverNumHi +{ + text-align: right; + padding-left: 10px; + padding-right: 10px; + background-color: #8ae234; + white-space: nowrap; +} + +/* Directory view/File view (all): legend entry for high coverage + rate */ +span.coverLegendHi +{ + text-align: center; + padding-left: 10px; + padding-right: 10px; + background-color: #8ae234; +} + +/* Directory view/File view (all): percentage entry for files with + medium coverage rate */ +td.coverPerMed +{ + text-align: right; + padding-left: 10px; + padding-right: 10px; + background-color: #fce94f; + font-weight: bold; +} + +/* Directory view/File view (all): line count entry for files with + medium coverage rate */ +td.coverNumMed +{ + text-align: right; + padding-left: 10px; + padding-right: 10px; + background-color: #fce94f; + white-space: nowrap; +} + +/* Directory view/File view (all): legend entry for medium coverage + rate */ +span.coverLegendMed +{ + text-align: center; + padding-left: 10px; + padding-right: 10px; + margin-top: 5px; + margin-bottom: 5px; + margin-right: 2px; + background-color: #fce94f; +} + +/* Directory view/File view (all): percentage entry for files with + low coverage rate */ +td.coverPerLo +{ + text-align: right; + padding-left: 10px; + padding-right: 10px; + background-color: #ef2929; + font-weight: bold; +} + +/* Directory view/File view (all): line count entry for files with + low coverage rate */ +td.coverNumLo +{ + text-align: right; + padding-left: 10px; + padding-right: 10px; + background-color: #ef2929; + white-space: nowrap; +} + +/* Directory view/File view (all): legend entry for low coverage + rate */ +span.coverLegendLo +{ + text-align: center; + padding-left: 10px; + padding-right: 10px; + margin-right: 2px; + background-color: #ef2929; +} + +/* File view (all): "show/hide details" link format */ +a.detail:link +{ + color: #ffffff; +} + +/* File view (all): "show/hide details" link - visited format */ +a.detail:visited +{ + color: #ffffff; +} + +/* File view (all): "show/hide details" link - activated format */ +a.detail:active +{ + color: #ffffff; +} + +/* File view (detail): test name table headline format */ +td.testNameHead +{ + text-align: left; + padding-left: 10px; + background-color: #729fcf; + font-family: sans-serif; + font-weight: bold; +} + +/* File view (detail): test lines table headline format */ +td.testLinesHead +{ + text-align: center; + background-color: #729fcf; + font-family: sans-serif; + font-weight: bold; +} + +/* File view (detail): test name entry */ +td.testName +{ + text-align: left; + padding-left: 10px; + background-color: #729fcf; +} + +/* File view (detail): test percentage entry */ +td.testPer +{ + text-align: right; + vertical-align: top; + padding-left: 10px; + padding-right: 10px; + background-color: #729fcf; +} + +/* File view (detail): test lines count entry */ +td.testNum +{ + text-align: right; + vertical-align: top; + padding-left: 10px; + padding-right: 10px; + background-color: #729fcf; + white-space: nowrap; +} + +/* Test case descriptions: test name format*/ +dt +{ + font-family: sans-serif; + font-weight: bold; +} + +/* Test case descriptions: description table body */ +td.testDescription +{ + padding-top: 10px; + padding-left: 30px; + padding-bottom: 10px; + padding-right: 30px; + background-color: #729fcf; +} + +/* Source code view: source code format */ +pre.source +{ + font-family: monospace; + white-space: pre; +} + +/* Source code view: line number format */ +span.lineNum +{ + background-color: #e9b96e; +} + +/* Source code view: format for lines which were executed */ +span.lineCov +{ + background-color: #8ae234; +} + +/* Source code view: format for Cov legend */ +span.LegendCov +{ + text-align: center; + padding-left: 10px; + padding-right: 10px; + margin-right: 2px; + background-color: #8ae234; +} + +/* Source code view: format for lines which were not executed */ +span.lineNoCov +{ + background-color: #ef2929; +} + +/* Source code view: format for NoCov legend */ +span.LegendNoCov +{ + text-align: center; + padding-left: 10px; + padding-right: 10px; + margin-right: 2px; + background-color: #ef2929; +} diff --git a/Util/Report/Template/testsuite.htm b/Util/Report/Template/testsuite.htm new file mode 100644 index 00000000000..fb9719d392c --- /dev/null +++ b/Util/Report/Template/testsuite.htm @@ -0,0 +1,73 @@ + + + + + + {title} + + + + + + + + + + + + + + +
{title}
+ + + + + + + + + + + + + + + + + + + +
Current view:{link}
Date:{date}  
    
+
+ +
+
+ +
+ Graphical Test Hierarchy + {testmap} +
+ +
+ + + + + + + +{items} +
+
+ +
+ + + + +
Generated by: PHPUnit {phpunit_version} and Xdebug {xdebug_version}.
+ +
+ + diff --git a/Util/Report/Template/testsuite_item.htm b/Util/Report/Template/testsuite_item.htm new file mode 100644 index 00000000000..21ebb236434 --- /dev/null +++ b/Util/Report/Template/testsuite_item.htm @@ -0,0 +1,10 @@ + + + + + + +
{result}
+ + {name} + diff --git a/Util/Report/Test/Factory.php b/Util/Report/Test/Factory.php new file mode 100644 index 00000000000..0522db08c93 --- /dev/null +++ b/Util/Report/Test/Factory.php @@ -0,0 +1,155 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Util/Report/Test/Node/Test.php'; +require_once 'PHPUnit2/Util/Report/Test/Node/TestSuite.php'; +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Util/Array.php'; +require_once 'PHPUnit2/Util/Test.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Factory for a test information tree. + * + * @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 3.0.0 + */ +abstract class PHPUnit2_Util_Report_Test_Factory +{ + /** + * Creates a new test information tree. + * + * @param PHPUnit2_Framework_TestResult $result + * @return PHPUnit2_Util_Report_Test_Node_TestSuite + * @access public + * @static + */ + public static function create(PHPUnit2_Framework_TestResult $result) + { + $tests = self::getTests($result); + $keys = array_keys($tests); + $root = new PHPUnit2_Util_Report_Test_Node_TestSuite($keys[0]); + + self::addTests($tests[$keys[0]], $root); + + return $root; + } + + /** + * @param array $tests + * @param PHPUnit2_Util_Report_Test_Node_TestSuite $root + * @access protected + * @static + */ + protected static function addTests(Array $tests, PHPUnit2_Util_Report_Test_Node_TestSuite $root) + { + foreach ($tests as $key => $value) { + if (is_int($key)) { + $root->addTest($value['name'], $value['object'], $value['result']); + } else { + $child = $root->addTestSuite($key); + self::addTests($value, $child); + } + } + + return $root; + } + + /** + * @param PHPUnit2_Framework_TestResult $result + * @param PHPUnit2_Framework_TestSuite $testSuite + * @return array + * @access protected + * @since Method available since Release 3.0.0 + */ + protected static function getTests(PHPUnit2_Framework_TestResult $result, PHPUnit2_Framework_TestSuite $testSuite = NULL) + { + if ($testSuite === NULL) { + $testSuite = $result->topTestSuite(); + } + + $tests = array(); + + foreach ($testSuite->tests() as $test) { + if ($test instanceof PHPUnit2_Framework_TestSuite) { + $tests = array_merge( + $tests, + self::getTests($result, $test) + ); + } else { + $testName = PHPUnit2_Util_Test::describe($test, FALSE); + + $tests[] = array( + 'name' => $testName[1], + 'object' => $test, + 'result' => PHPUnit2_Util_Test::lookupResult($test, $result) + ); + } + } + + return array($testSuite->getName() => $tests); + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Util/Report/Test/Node.php b/Util/Report/Test/Node.php new file mode 100644 index 00000000000..cbc560de795 --- /dev/null +++ b/Util/Report/Test/Node.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Util/Filesystem.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Base class for nodes in the test information tree. + * + * @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 3.0.0 + */ +abstract class PHPUnit2_Util_Report_Test_Node +{ + /** + * @var string + * @access protected + */ + protected $name; + + /** + * @var PHPUnit2_Util_Test_Node + * @access protected + */ + protected $parent; + + /** + * @var array + * @access protected + */ + protected $cache = array(); + + /** + * Constructor. + * + * @param string $name + * @param PHPUnit2_Util_Test_Node $parent + * @access public + */ + public function __construct($name, PHPUnit2_Util_Report_Test_Node $parent = NULL) + { + $this->name = $name; + $this->parent = $parent; + } + + /** + * Returns this node's name. + * + * @param boolean $includeParent + * @return mixed + * @access public + */ + public function getName($includeParent = FALSE) + { + if ($includeParent && $this->parent !== NULL) { + if (!isset($this->cache['nameIncludingParent'])) { + $this->cache['nameIncludingParent'] = array( + $this->parent->getName(), + $this->name + ); + } + + return $this->cache['nameIncludingParent']; + } else { + return $this->name; + } + } + + /** + * Returns this node's link. + * + * @param boolean $full + * @return string + * @access public + */ + public function getLink($full = FALSE) + { + if ($full && $this->parent !== NULL) { + return sprintf( + '%s / %s', + + $this->parent->getLink(TRUE), + PHPUnit2_Util_Filesystem::getSafeFilename($this->getName()), + $this->getName() + ); + } else { + return sprintf( + '%s', + + PHPUnit2_Util_Filesystem::getSafeFilename($this->getName()), + $this->getName() + ); + } + } + + /** + * @param PHPUnit2_Util_Template $template + * @param string $title + * @access public + */ + protected function setTemplateVars(PHPUnit2_Util_Template $template, $title) + { + $template->setVar( + array( + 'title', + 'link', + 'date', + 'phpunit_version', + 'xdebug_version', + ), + array( + $title, + $this->getLink(TRUE), + date('D M j G:i:s T Y'), + PHPUnit2_Runner_Version::id(), + phpversion('xdebug') + ) + ); + } + + /** + * Renders this node. + * + * @param string $target + * @param string $title + * @access public + * @abstract + */ + abstract public function render($target, $title); +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Util/Report/Test/Node/Test.php b/Util/Report/Test/Node/Test.php new file mode 100644 index 00000000000..d18a73ce32f --- /dev/null +++ b/Util/Report/Test/Node/Test.php @@ -0,0 +1,163 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Util/Report/Coverage/Node/File.php'; +require_once 'PHPUnit2/Util/Report/Test/Node.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Represents a PHPUnit2_Framework_Test object in the test hierarchy. + * + * @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 3.0.0 + */ +class PHPUnit2_Util_Report_Test_Node_Test extends PHPUnit2_Util_Report_Test_Node +{ + /** + * @var array + * @access protected + */ + protected $coveredFiles; + + /** + * @var PHPUnit2_Framework_Test + * @access protected + */ + protected $object; + + /** + * @var mixed + * @access protected + */ + protected $result; + + /** + * Constructor. + * + * @param string $name + * @param PHPUnit2_Util_Test_Node $parent + * @param PHPUnit2_Framework_Test $object + * @param mixed $result + * @access public + */ + public function __construct($name, PHPUnit2_Util_Report_Test_Node $parent, PHPUnit2_Framework_Test $object, $result) + { + static $testId = 0; + + parent::__construct($name, $parent); + + $this->object = $object; + $this->result = $result; + $this->testId = $testId++; + + $this->object->__testNode = $this; + } + + /** + * Adds a file that is covered by the test that is represented by this node. + * + * @param PHPUnit2_Util_Report_Coverage_Node_File $file + * @access public + */ + public function addCoveredFile(PHPUnit2_Util_Report_Coverage_Node_File $file) + { + $this->coveredFiles[] = $file; + } + + /** + * Returns the PHPUnit2_Framework_Test object that is represented by this node. + * + * @return PHPUnit2_Framework_Test + * @access public + */ + public function getObject() + { + return $this->object; + } + + /** + * Returns the result of the PHPUnit2_Framework_Test object that is + * represented by this node. + * + * @return mixed + * @access public + */ + public function getResult() + { + return $this->result; + } + + /** + * Renders this node. + * + * @param string $target + * @param string $title + * @access public + */ + public function render($target, $title) + { + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Util/Report/Test/Node/TestSuite.php b/Util/Report/Test/Node/TestSuite.php new file mode 100644 index 00000000000..554d5084bc5 --- /dev/null +++ b/Util/Report/Test/Node/TestSuite.php @@ -0,0 +1,336 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +@include_once 'Image/GraphViz.php'; + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Runner/BaseTestRunner.php'; +require_once 'PHPUnit2/Util/Report/Test/Node.php'; +require_once 'PHPUnit2/Util/Report/Test/Node/Test.php'; +require_once 'PHPUnit2/Util/Filesystem.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Represents a PHPUnit2_Framework_TestSuite object in the test hierarchy. + * + * @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 3.0.0 + */ +class PHPUnit2_Util_Report_Test_Node_TestSuite extends PHPUnit2_Util_Report_Test_Node +{ + /** + * @var PHPUnit2_Util_Report_Test_Node[] + * @access protected + */ + protected $children = array(); + + /** + * @var PHPUnit2_Util_Report_Test_Node_TestSuite[] + * @access protected + */ + protected $suites = array(); + + /** + * @var PHPUnit2_Util_Report_Test_Node_Test[] + * @access protected + */ + protected $tests = array(); + + /** + * Adds a new test suite. + * + * @param string $name + * @return PHPUnit2_Util_Report_Test_Node_TestSuite + * @access public + */ + public function addTestSuite($name) + { + $suite = new PHPUnit2_Util_Report_Test_Node_TestSuite($name, $this); + + $this->children[] = $suite; + $this->suites[] = &$this->children[count($this->children)-1]; + + return $suite; + } + + /** + * Adds a new test. + * + * @param string $name + * @param PHPUnit2_Framework_Test $object + * @param mixed $result + * @access public + */ + public function addTest($name, PHPUnit2_Framework_Test $object, $result) + { + $test = new PHPUnit2_Util_Report_Test_Node_Test($name, $this, $object, $result); + + $this->children[] = $test; + $this->tests[] = &$this->children[count($this->children)-1]; + } + + /** + * Returns the corresponding PHPUnit2_Util_Report_Test_Node_Test object + * for a given PHPUnit2_Framework_Test object. + * + * @param PHPUnit2_Framework_Test $test + * @return PHPUnit2_Util_Report_Test_Node_Test + * @access public + */ + public function lookupTest(PHPUnit2_Framework_Test $test) + { + /* + foreach ($this->tests as $child) { + if ($test === $child->getObject()) { + return $child; + } + } + + foreach ($this->suites as $child) { + $result = $child->lookupTest($test); + + if ($result !== FALSE) { + return $result; + } + } + + return FALSE; + */ + + return $test->__testNode; + } + + /** + * Renders this node. + * + * @param string $target + * @param string $title + * @access public + */ + public function render($target, $title) + { + $this->doRender($target, $title); + + foreach ($this->children as $child) { + $child->render($target, $title); + } + } + + /** + * @param string $target + * @access protected + */ + protected function doRender($target, $title) + { + $file = $target . PHPUnit2_Util_Filesystem::getSafeFilename($this->getName()) . '-test.htm'; + + $template = new PHPUnit2_Util_Template( + PHPUnit2_Util_Report::getTemplatePath() . + 'testsuite.htm' + ); + + $this->setTemplateVars($template, $title); + $this->setGraphVizTemplateVars($template, $target); + + $template->setVar( + array( + 'items', + 'testmap_image', + 'testmap' + ), + array( + $this->renderItems(), + '', + '' + ) + ); + + $template->renderTo($file); + } + + /** + * @return string + * @access protected + */ + protected function renderItems() + { + $result = ''; + + foreach ($this->tests as $item) { + $itemTemplate = new PHPUnit2_Util_Template( + PHPUnit2_Util_Report::getTemplatePath() . + 'testsuite_item.htm' + ); + + $resultCode = $item->getResult(); + + if ($resultCode instanceof PHPUnit2_Framework_TestFailure) { + if ($resultCode->isFailure()) { + $testResult = 'Failure'; + } + + else if ($resultCode->thrownException() instanceof PHPUnit2_Framework_SkippedTest) { + $testResult = 'Skipped'; + } + + else if ($resultCode->thrownException() instanceof PHPUnit2_Framework_IncompleteTest) { + $testResult = 'Incomplete'; + } + + else { + $testResult = 'Error'; + } + } + + else if ($resultCode === PHPUnit2_Runner_BaseTestRunner::STATUS_PASSED) { + $testResult = 'Passed'; + } + + else { + $testResult = 'Error'; + } + + switch ($testResult) { + case 'Passed': + case 'Skipped': { + $color = 'chameleon'; + } + break; + + case 'Incomplete': { + $color = 'butter'; + } + break; + + case 'Error': + case 'Failure': + default: { + $color = 'scarlet_red'; + } + } + + $itemTemplate->setVar( + array( + 'color', + 'result', + 'name', + ), + array( + $color, + $testResult, + $item->getName(), + ) + ); + + $result .= $itemTemplate->render(); + } + + return $result; + } + + /** + * @param PHPUnit2_Util_Template $template + * @param string $target + * @access public + */ + protected function setGraphVizTemplateVars(PHPUnit2_Util_Template $template, $target) + { + $testmap = ''; + $testmap_image = 'snow.png'; + $safeName = PHPUnit2_Util_Filesystem::getSafeFilename($this->getName()); + $dotFile = $target . $safeName . '.dot'; + + if (file_exists($dotFile)) { + $pngFile = $target . $safeName . '.png'; + $mapFile = $target . $safeName . '.map'; + + $graphviz = new Image_GraphViz(TRUE); + + $success = $graphviz->renderDotFile($dotFile, $pngFile, 'png'); + + if ($success) { + $testmap_image = basename($pngFile); + } + + $success = $graphviz->renderDotFile($dotFile, $mapFile, 'cmapx'); + + if ($success) { + $testmap = file_get_contents($mapFile); + unlink($mapFile); + } + } + + $template->setVar( + array( + 'testmap', + 'testmap_image' + ), + array( + $testmap, + $testmap_image + ) + ); + } +} + +/* + * 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..5ec19e9909f --- /dev/null +++ b/Util/Skeleton.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.1.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Util/Template.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Generator for TestCase skeletons. + * + * @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 +{ + /** + * @var string + * @access protected + */ + protected $className; + + /** + * @var string + * @access protected + */ + protected $classSourceFile; + + /** + * @var string + * @access protected + */ + protected $testSourceFile; + + /** + * Constructor. + * + * @param string $className + * @param string $classSourceFile + * @throws RuntimeException + * @access public + */ + public function __construct($className, $classSourceFile = '') + { + if (file_exists($className . '.php')) { + $this->classSourceFile = $className . '.php'; + $this->testSourceFile = $className . 'Test.php'; + } + + else if (file_exists(str_replace('_', '/', $className) . '.php')) { + $this->classSourceFile = str_replace('_', '/', $className) . '.php'; + $this->testSourceFile = str_replace('_', '/', $className) . 'Test.php'; + } + + else { + throw new RuntimeException( + sprintf( + 'Could not open %s.', + + $classSourceFile + ) + ); + } + + @include_once $this->classSourceFile; + + if (class_exists($className)) { + $this->className = $className; + } else { + throw new RuntimeException( + sprintf( + 'Could not find class "%s" in %s.', + + $className, + $this->classSourceFile + ) + ); + } + } + + /** + * Generates the test class' source. + * + * @return string + * @access public + */ + public function generate() + { + $class = new ReflectionClass($this->className); + $methods = ''; + + foreach ($class->getMethods() as $method) { + if (!$method->isConstructor() && + !$method->isAbstract() && + $method->isUserDefined() && + $method->isPublic() && + $method->getDeclaringClass()->getName() == $this->className) { + $methodTemplate = new PHPUnit2_Util_Template( + sprintf( + '%s%sSkeleton%sTestMethod.php', + + dirname(__FILE__), + DIRECTORY_SEPARATOR, + DIRECTORY_SEPARATOR + ) + ); + + $methodTemplate->setVar( + 'methodName', + ucfirst($method->getName()) + ); + + $methods .= $methodTemplate->render(); + } + } + + $classTemplate = new PHPUnit2_Util_Template( + sprintf( + '%s%sSkeleton%sTestClass.php', + + dirname(__FILE__), + DIRECTORY_SEPARATOR, + DIRECTORY_SEPARATOR + ) + ); + + $classTemplate->setVar( + array( + 'className', + 'classFile', + 'methods', + 'date', + 'time' + ), + array( + $this->className, + $this->classSourceFile, + $methods, + date('Y-m-d'), + date('H:i:s') + ) + ); + + return $classTemplate->render(); + } + + /** + * Generates the test class and writes it to a source file. + * + * @param string $file + * @access public + */ + public function write($file = '') + { + if ($file == '') { + $file = $this->testSourceFile; + } + + if ($fp = @fopen($file, 'wt')) { + @fputs($fp, $this->generate()); + @fclose($fp); + } + } + + /** + * @return string + * @access public + * @since Method available since Release 3.0.0 + */ + public function getTestSourceFile() + { + return $this->testSourceFile; + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Util/Skeleton/TestClass.php b/Util/Skeleton/TestClass.php new file mode 100644 index 00000000000..16212704d08 --- /dev/null +++ b/Util/Skeleton/TestClass.php @@ -0,0 +1,53 @@ + diff --git a/Util/Skeleton/TestMethod.php b/Util/Skeleton/TestMethod.php new file mode 100644 index 00000000000..d60be16b9df --- /dev/null +++ b/Util/Skeleton/TestMethod.php @@ -0,0 +1,10 @@ + + /** + * @todo Implement test{methodName}(). + */ + public function test{methodName}() { + // Remove the following line when you implement this test. + $this->markTestIncomplete( + "This test has not been implemented yet." + ); + } diff --git a/Util/Template.php b/Util/Template.php new file mode 100644 index 00000000000..3c905df0dec --- /dev/null +++ b/Util/Template.php @@ -0,0 +1,166 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, '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 3.0.0 + */ +class PHPUnit2_Util_Template +{ + /** + * @var array + * @access private + */ + private $template = ''; + + /** + * @var array + * @access private + */ + private $keys = array(); + + /** + * @var array + * @access private + */ + private $values = array(); + + /** + * Constructor. + * + * @param string $file + * @throws InvalidArgumentException + * @access public + */ + public function __construct($file = '') { + $this->setFile($file); + } + + /** + * Sets the template file. + * + * @param string $file + * @throws InvalidArgumentException + * @access public + */ + public function setFile($file) { + if ($file != '' && file_exists($file)) { + $this->template = file_get_contents($file); + } else { + throw new InvalidArgumentException( + 'Template file could not be loaded.' + ); + } + } + + /** + * Sets one or more template variables. + * + * @param mixed $keys + * @param mixed $values + * @access public + */ + public function setVar($keys, $values) { + if (is_array($keys) && is_array($values) && count($keys) == count($values)) { + foreach ($keys as $key) { + $this->keys[] = '{' . $key . '}'; + } + + $this->values = array_merge($this->values, $values); + } else { + $this->keys[] = '{' . $keys . '}'; + $this->values[] = $values; + } + } + + /** + * Renders the template and returns the result. + * + * @return string + * @access public + */ + public function render() { + return str_replace($this->keys, $this->values, $this->template); + } + + /** + * Renders the template and writes the result to a file. + * + * @param string $target + * @access public + */ + public function renderTo($target) { + if ($fp = @fopen($target, 'wt')) { + fputs($fp, $this->render()); + fclose($fp); + } else { + throw new RuntimeException('Could not write to ' . $target . '.'); + } + } +} + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * c-hanging-comment-ender-p: nil + * End: + */ +?> diff --git a/Util/Test.php b/Util/Test.php new file mode 100644 index 00000000000..5baf9a2eadd --- /dev/null +++ b/Util/Test.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Test helpers. + * + * @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 3.0.0 + */ +class PHPUnit2_Util_Test +{ + /** + * @param PHPUnit2_Framework_Test $test + * @param boolean $asString + * @return mixed + * @access public + * @static + */ + public static function describe(PHPUnit2_Framework_Test $test, $asString = TRUE) + { + if ($asString) { + if ($test instanceof PHPUnit2_Framework_SelfDescribing) { + return $test->toString(); + } else { + return get_class($test); + } + } else { + if ($test instanceof PHPUnit2_Framework_TestCase) { + return array( + get_class($test), $test->getName() + ); + } + + else if ($test instanceof PHPUnit2_Framework_SelfDescribing) { + return array('', $test->toString()); + } + + else { + return array('', get_class($test)); + } + } + } + + /** + * @param PHPUnit2_Framework_Test $test + * @param PHPUnit2_Framework_TestResult $result + * @return mixed + * @access public + * @static + */ + public static function lookupResult(PHPUnit2_Framework_Test $test, PHPUnit2_Framework_TestResult $result) + { + $testName = self::describe($test); + + foreach ($result->errors() as $error) { + if ($testName == self::describe($error->failedTest())) { + return $error; + } + } + + foreach ($result->failures() as $failure) { + if ($testName == self::describe($failure->failedTest())) { + return $failure; + } + } + + foreach ($result->notImplemented() as $notImplemented) { + if ($testName == self::describe($notImplemented->failedTest())) { + return $notImplemented; + } + } + + foreach ($result->skipped() as $skipped) { + if ($testName == self::describe($skipped->failedTest())) { + return $skipped; + } + } + + return PHPUnit2_Runner_BaseTestRunner::STATUS_PASSED; + } +} + +/* + * 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..44c5e60cf53 --- /dev/null +++ b/Util/TestDox/NamePrettifier.php @@ -0,0 +1,176 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * 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); + $max = strlen($testMethodName); + + for ($i = 4; $i < $max; $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..81c155a9399 --- /dev/null +++ b/Util/TestDox/ResultPrinter.php @@ -0,0 +1,330 @@ +. + * 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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit2/Framework.php'; +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Util/TestDox/NamePrettifier.php'; +require_once 'PHPUnit2/Util/Printer.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * 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(); + } + + /** + * Flush buffer and close output. + * + * @access public + */ + public function flush() + { + $this->doEndClass(); + $this->endRun(); + + parent::flush(); + } + + /** + * Abstract Factory. + * + * @param string $type + * @param resource $out + * @throws RuntimeException + * @access public + * @static + */ + public static function factory($type, $out = NULL) + { + $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; + } + + /** + * Skipped test. + * + * @param PHPUnit2_Framework_Test $test + * @param Exception $e + * @access public + * @since Method available since Release 3.0.0 + */ + public function addSkippedTest(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() + { + } +} + +require_once 'PHPUnit2/Util/TestDox/ResultPrinter/HTML.php'; +require_once 'PHPUnit2/Util/TestDox/ResultPrinter/Text.php'; + +/* + * 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..0dcc66bcda2 --- /dev/null +++ b/Util/TestDox/ResultPrinter/HTML.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Util/TestDox/ResultPrinter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * 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..7a8f8ddd761 --- /dev/null +++ b/Util/TestDox/ResultPrinter/Text.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 2.3.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; +require_once 'PHPUnit2/Util/TestDox/ResultPrinter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * 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/Util/Timer.php b/Util/Timer.php new file mode 100644 index 00000000000..b6dfcd89614 --- /dev/null +++ b/Util/Timer.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 SVN: $Id$ + * @link http://pear.php.net/package/PHPUnit2 + * @since File available since Release 3.0.0 + */ + +require_once 'PHPUnit2/Util/Filter.php'; + +PHPUnit2_Util_Filter::addFileToFilter(__FILE__, 'PHPUNIT'); + +/** + * Utility class for timing. + * + * @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 3.0.0 + */ +class PHPUnit2_Util_Timer +{ + private static $startTimes = array(); + + public static function start() + { + array_push(self::$startTimes, microtime(TRUE)); + } + + public static function stop() + { + return microtime(TRUE) - array_pop(self::$startTimes); + } +} + +/* + * 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..13d7045b6a9 --- /dev/null +++ b/package.xml @@ -0,0 +1,744 @@ + + + + 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 + + + amos + Jan Borsodi + jb@ez.no + developer + + + BSD License + + 3.0.0alpha11 + alpha + 2006-06-13 + +" command-line option to the TextUI test runner to run the test(s) repeatedly. + +* PHPUnit2_Framework_Assert::assertContains() and PHPUnit2_Framework_Assert::assertNotContains() can now work on strings. + +* PHPUnit2_Framework_ComparisonFailure has been refactored into PHPUnit2_Framework_ComparisonFailure, PHPUnit2_Framework_ComparisonFailure_Array, PHPUnit2_Framework_ComparisonFailure_Object, PHPUnit2_Framework_ComparisonFailure_Scalar, PHPUnit2_Framework_ComparisonFailure_String, and PHPUnit2_Framework_ComparisonFailure_Type to improve discrepancy visualization, initially developed by Jan Borsodi and contributed by eZ systems AS. + +* Changed PHPUnit2_TextUI_ResultPrinter::printHeader() to sanely format the time elapsed as MM:SS. + +* PHPUnit2_Runner_IncludePathTestCollector can now utilize a FilterIterator. + +* PHPUnit2_Framework_TestResult no longer registers an error handler if the code under test already registered one. + +* The PHPUnit2_Framework_Test interface now extends and its implementors as well as the PHPUnit2_Framework_TestResult class now implement the Standard PHP Library (SPL)'s Countable interface. + +* PHPUnit2 now uses the Standard PHP Library (SPL)'s specialized exceptions InvalidArgumentException and RuntimeException instead of the generic Exception exception class. + +* Implemented RFE #5546: Make filtering and/or filtering on the current file optional. + +* Implemented RFE #5860: Missing parse errors after lint. + +* Fixed bug #5053: Problems with global variables. + +* Fixed bug #5933: PHPUnit2_Framework_TestSuite::addTestFile() and non-working directories. + +* Fixed bug #6613: AllTests.php have relative include paths that don't work. + +* Fixed bug #7106: phpunit --skeleton does not seem to handle PEARified names. + +* Fixed bug #7107: Platform-specific skeleton line endings. + +* Fixed bug #7373: Unexpected "syntax error" in safe mode. + +* Fixed bug #7770: TextUI/TestRunner::doSkeleton $skeleton not always an object. + +- Removed --coverage-data, --coverage-html, and --coverage-text options from the command-line test runner. + +- Removed PHPUnit2_Framework_Assert::setLooselyTyped(). + +- Removed dependency on the Benchmark_Timer, Console_Getopt, and PEAR_Config PEAR classes. + +! The countTestCases() method of the PHPUnit2_Framework_Test interface has been renamed to count(). + +! The runCount() method of the PHPUnit2_Framework_TestResult class has been renamed to count(). + +! A new method, addSkippedTest(), has been added to the PHPUnit2_Framework_TestListener interface. + +! The run() and doRun() methods of the PHPUnit2_TextUI_TestRunner class now accept an associative array for test run parameters. + +! PHP 5.1.4 (or greater) is now required. +]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + dom + pcre + reflection + spl + tokenizer + xdebug + Image_GraphViz + Log + + + diff --git a/pear-phpunit b/pear-phpunit new file mode 100644 index 00000000000..45a773ecf7f --- /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$ + */ + +require 'PHPUnit2/TextUI/TestRunner.php'; +?> diff --git a/pear-phpunit.bat b/pear-phpunit.bat new file mode 100755 index 00000000000..b32d536cb17 --- /dev/null +++ b/pear-phpunit.bat @@ -0,0 +1,40 @@ +@echo off +REM PHPUnit +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.7 2006/03/15 09:12:07 sebastian Exp $ +REM + +set PHPBIN=@php_bin@ +"@php_bin@" "@php_dir@/PHPUnit2/TextUI/TestRunner.php" %*