diff --git a/ChangeLog.md b/ChangeLog.md index 9ef8baef0c0..a65078c0d4e 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -6,6 +6,7 @@ This is the list of changes for the PHPUnit 3.8 release series. PHPUnit 3.8.0 ------------- -* PHPUnit 3.8 is only supported on PHP 5.4.7 (or later). +* A test will now fail in strict mode when it uses the `@covers` annotation and code that is not expected to be covered is executed. +* Implemented #711: `coverage-text` now has an XML `showOnlySummary` option. * Fixed: `phpt` test cases now use the correct php binary when executed through wrapper scripts. -* Implemented #711: `coverage-text` now has a xml `showOnlySummary` option. +* PHPUnit 3.8 is only supported on PHP 5.4.7 (or later). diff --git a/PHPUnit/Autoload.php b/PHPUnit/Autoload.php index 7bd4395dbd0..2cef11fc84b 100644 --- a/PHPUnit/Autoload.php +++ b/PHPUnit/Autoload.php @@ -138,6 +138,7 @@ function ($class) 'phpunit_framework_testresult' => '/Framework/TestResult.php', 'phpunit_framework_testsuite' => '/Framework/TestSuite.php', 'phpunit_framework_testsuite_dataprovider' => '/Framework/TestSuite/DataProvider.php', + 'phpunit_framework_unintentionallycoveredcodeerror' => '/Framework/UnintentionallyCoveredCodeError.php', 'phpunit_framework_warning' => '/Framework/Warning.php', 'phpunit_runner_basetestrunner' => '/Runner/BaseTestRunner.php', 'phpunit_runner_standardtestsuiteloader' => '/Runner/StandardTestSuiteLoader.php', diff --git a/PHPUnit/Framework/TestResult.php b/PHPUnit/Framework/TestResult.php index 0f08f9b59ca..c738583abdd 100644 --- a/PHPUnit/Framework/TestResult.php +++ b/PHPUnit/Framework/TestResult.php @@ -675,6 +675,16 @@ public function run(PHPUnit_Framework_Test $test) $this->codeCoverage->stop(!$incomplete && !$skipped); } + catch (PHP_CodeCoverage_Exception_UnintentionallyCoveredCode $e) { + $this->addFailure( + $test, + new PHPUnit_Framework_UnintentionallyCoveredCodeError( + 'This test executed code that is not listed as code to be covered' + ), + $time + ); + } + catch (PHP_CodeCoverage_Exception $cce) { $error = TRUE; diff --git a/PHPUnit/Framework/UnintentionallyCoveredCodeError.php b/PHPUnit/Framework/UnintentionallyCoveredCodeError.php new file mode 100644 index 00000000000..403ea63072e --- /dev/null +++ b/PHPUnit/Framework/UnintentionallyCoveredCodeError.php @@ -0,0 +1,60 @@ +. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * * Neither the name of Sebastian Bergmann nor the names of his + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + * + * @package PHPUnit + * @subpackage Framework + * @author Sebastian Bergmann + * @copyright 2001-2012 Sebastian Bergmann + * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License + * @link http://www.phpunit.de/ + * @since File available since Release 3.8.0 + */ + +/** + * Extension to PHPUnit_Framework_AssertionFailedError to mark the special + * case of a test test that unintentionally covers code. + * + * @package PHPUnit + * @subpackage Framework + * @author Sebastian Bergmann + * @copyright 2001-2012 Sebastian Bergmann + * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License + * @link http://www.phpunit.de/ + * @since Class available since Release 3.8.0 + */ +class PHPUnit_Framework_UnintentionallyCoveredCodeError extends PHPUnit_Framework_AssertionFailedError +{ +} diff --git a/PHPUnit/TextUI/TestRunner.php b/PHPUnit/TextUI/TestRunner.php index 163da6aaef4..955ed698088 100644 --- a/PHPUnit/TextUI/TestRunner.php +++ b/PHPUnit/TextUI/TestRunner.php @@ -276,6 +276,10 @@ public function doRun(PHPUnit_Framework_Test $suite, array $arguments = array()) $arguments['addUncoveredFilesFromWhitelist'] ); + $codeCoverage->setCheckForUnintentionallyCoveredCode( + $arguments['strict'] + ); + $codeCoverage->setProcessUncoveredFilesFromWhitelist( $arguments['processUncoveredFilesFromWhitelist'] ); diff --git a/package.xml b/package.xml index 2a1033ba8a9..c020fe76200 100644 --- a/package.xml +++ b/package.xml @@ -134,6 +134,7 @@ +