Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

phpunit exists unexpectedly when finds @covers tag for non-existing method #1791

Closed
Gamesh opened this issue Jul 14, 2015 · 8 comments
Closed

Comments

@Gamesh
Copy link
Contributor

Gamesh commented Jul 14, 2015

/**
 * @coversDefaultClass FooBar
 */
class FooBarTest extends PHPUnit_Framework_TestCase
{

    protected $object;

    public function setUp()
    {
        $this->object = new FooBar;
    }
    /**
     * @covers ::get
     */
    public function testSetProperty()
    {
        $this->assertNull($this->object->get());
    }

    /**
     * @covers ::nonExistingMethod
     */
    public function testSomeMethod()
    {
        $this->assertEquals(0, 0);
    }
    /**
     * @covers ::set
     * @covers ::get
     */
    public function testSomeOtherTest()
    {
        $this->object->set('test');
        $this->assertEquals('test', $this->object->get());
    }

}

class FooBar
{

    private $value = null;

    public function get()
    {
        return $this->value;
    }

    public function set($value)
    {
        $this->value = $value;
    }

}

Expected output:
.E.

Actual ouptut:

PHPUnit 4.7.7 by Sebastian Bergmann and contributors.
Warning:        No whitelist configured for code coverage

.Trying to @cover or @use not existing method "FooBar::nonExistingMethod".

ouptut with --debug:

PHPUnit 4.7.7 by Sebastian Bergmann and contributors.
Warning:        No whitelist configured for code coverage


Starting test 'FooBarTest::testSetProperty'.
.
Starting test 'FooBarTest::testSomeMethod'.
Trying to @cover or @use not existing method "FooBar::nonExistingMethod".

so the testSomeOtherTest() is not even executed.

@Gamesh
Copy link
Contributor Author

Gamesh commented Jul 14, 2015

Tested on latest phpunit v4.7.7, and on v4.6.10 result is the same
PHP 5.5.25 (cli) (built: May 14 2015 10:02:12)
Copyright (c) 1997-2015 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2015 Zend Technologies
with Zend OPcache v7.0.4-dev, Copyright (c) 1999-2015, by Zend Technologies
with Xdebug v2.3.2, Copyright (c) 2002-2015, by Derick Rethans
with blackfire v0.25.1, https://blackfire.io/, by SensioLabs

@sebastianbergmann
Copy link
Owner

This is expected behavior. See #1760 for more details.

@Gamesh
Copy link
Contributor Author

Gamesh commented Jul 14, 2015

in PHPUnit 3.7 it did just printout an error, which we could fix in PHPUnit 4.7 it just dies.
At least consider adding some information like it used to have, on what test the invalid @covers annotation was found, cause now it looks like the unit test encountered a fatal error and just exited in the middle of something.

@Gamesh
Copy link
Contributor Author

Gamesh commented Jul 14, 2015

this was taken from before the upgrade, v3.7 printed:

............................................................... 882 / 882 (100%)


Time: 10.01 minutes, Memory: 175.25Mb

There was 1 error:

1) SynchroModelTest::testProcessNewTasksInStatusReadyToSendWS
PHP_CodeCoverage_Exception: Trying to @cover not existing method "SynchroModel::getSynchroItemPriority".

now this i understand, and i see what the problem is and i can fix it. The current v4.7 output is unacceptable as it does not provide required information to fix the problem.

@oradwell
Copy link

@Gamesh That problem has been very annoying for me. I once had to manually check all the @covers tags for 1300 tests. Here's a CLI tool I made for this purpose: ockcyp/covers-validator

@paolomainardi
Copy link

thanks a lot @oradwell, this is super useful!

@sebastianbergmann
Copy link
Owner

@oradwell Haven't looked at your tool yet but https://github.com/dunkelfrosch/phpcoverfish by @dunkelfrosch also exists.

@Gamesh
Copy link
Contributor Author

Gamesh commented Jan 28, 2016

all the tools are really great, i just wish PHPUnit would at least have the courtesy to print out the Class name of the test where it found the @covers tag of non existing method. Because if somebody forgot to add @coversDefaultClass and you have lots of classes with the same method names you are screwed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants