Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Calling static method on a mock object results in a warning without message #327

Closed
digilist opened this issue Sep 6, 2016 · 0 comments
Closed

Comments

@digilist
Copy link

digilist commented Sep 6, 2016

When I call a static method on a mock object I get a warning from PHPUnit which does not tell me why.

screenshot from 2016-09-06 12 21 06

Consider the following example:

class FooTest extends \PHPUnit_Framework_TestCase
{
    public function testFoo()
    {
        $example = $this->createMock(ExampleClass::class);
        $example->staticMethod();

        $this->assertTrue(false);
    }
}

class ExampleClass
{
    public static function staticMethod()
    {
    }
}

The test results in a warning when the static method is called. The assertion afterwards is not executed, because the static method call produced an Exception.

I know, that PHPUnit does not mock static methods, but a reasonable error (or warning) message would be good. It took me some time to figure out the reason why my test triggered the warning (because the static call was not made directly in the test case but somewhere deep in the code).

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

No branches or pull requests

1 participant