mockingphpunitcode-coveragephp-code-coverage

PHPUnit Mocked classes methods not shown as covered in code coverage reports?


I am working on a php project in magento2. I am using mock objects for writing unit test cases. I came to know that when i generate code coverage report, Mocked classes and methods do not show as covered in code coverage reports, Is there any way we can show these ?

I looked into official repo and it's mentioned as default behaviour.

Reference: https://github.com/sebastianbergmann/phpunit-mock-objects/issues/123

Any help much appreciated!

Thanks


Solution

  • Mocked methods are not shown as covered because their code was not executed (they were stubbed and only a predefined value was returned and the original code never called).

    There are few things you can do: