Skip to content

Commit

Permalink
Mark a test that tries to @cover invalid targets as skipped and provi…
Browse files Browse the repository at this point in the history
…de a more useful error message in that case.
  • Loading branch information
sebastianbergmann committed Nov 24, 2012
1 parent ba02390 commit c1660bf
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 0 deletions.
1 change: 1 addition & 0 deletions PHPUnit/Autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ function ($class)
'phpunit_framework_expectationfailedexception' => '/Framework/ExpectationFailedException.php',
'phpunit_framework_incompletetest' => '/Framework/IncompleteTest.php',
'phpunit_framework_incompletetesterror' => '/Framework/IncompleteTestError.php',
'phpunit_framework_invalidcoverstargeterror' => '/Framework/InvalidCoversTargetError.php',
'phpunit_framework_outputerror' => '/Framework/OutputError.php',
'phpunit_framework_selfdescribing' => '/Framework/SelfDescribing.php',
'phpunit_framework_skippedtest' => '/Framework/SkippedTest.php',
Expand Down
60 changes: 60 additions & 0 deletions PHPUnit/Framework/InvalidCoversTargetError.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* PHPUnit
*
* Copyright (c) 2001-2012, Sebastian Bergmann <sebastian@phpunit.de>.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* * Neither the name of Sebastian Bergmann nor the names of his
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 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 <sebastian@phpunit.de>
* @copyright 2001-2012 Sebastian Bergmann <sebastian@phpunit.de>
* @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 that is skipped because of an invalid @covers annotation.
*
* @package PHPUnit
* @subpackage Framework
* @author Sebastian Bergmann <sebastian@phpunit.de>
* @copyright 2001-2012 Sebastian Bergmann <sebastian@phpunit.de>
* @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_InvalidCoversTargetError extends PHPUnit_Framework_AssertionFailedError implements PHPUnit_Framework_SkippedTest
{
}
10 changes: 10 additions & 0 deletions PHPUnit/Framework/TestResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,16 @@ public function run(PHPUnit_Framework_Test $test)
);
}

catch (PHP_CodeCoverage_Exception_InvalidCoversTarget $e) {
$this->addFailure(
$test,
new PHPUnit_Framework_InvalidCoversTargetError(
$e->getMessage()
),
$time
);
}

catch (PHP_CodeCoverage_Exception $cce) {
$error = TRUE;

Expand Down
1 change: 1 addition & 0 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
<file baseinstalldir="/" name="ExpectationFailedException.php" role="php" />
<file baseinstalldir="/" name="IncompleteTestError.php" role="php" />
<file baseinstalldir="/" name="IncompleteTest.php" role="php" />
<file baseinstalldir="/" name="InvalidCoversTargetError.php" role="php" />
<file baseinstalldir="/" name="OutputError.php" role="php" />
<file baseinstalldir="/" name="SelfDescribing.php" role="php" />
<file baseinstalldir="/" name="SkippedTestError.php" role="php" />
Expand Down

0 comments on commit c1660bf

Please sign in to comment.