{"action":"created","issue":{"url":"https://api.github.com/repos/sebastianbergmann/phpunit/issues/2117","repository_url":"https://api.github.com/repos/sebastianbergmann/phpunit","labels_url":"https://api.github.com/repos/sebastianbergmann/phpunit/issues/2117/labels{/name}","comments_url":"https://api.github.com/repos/sebastianbergmann/phpunit/issues/2117/comments","events_url":"https://api.github.com/repos/sebastianbergmann/phpunit/issues/2117/events","html_url":"https://github.com/sebastianbergmann/phpunit/issues/2117","id":140730060,"number":2117,"title":"Using @codeCoverageIgnore annotations within the *Test class","user":{"login":"twifty","id":11319780,"avatar_url":"https://avatars.githubusercontent.com/u/11319780?v=3","gravatar_id":"","url":"https://api.github.com/users/twifty","html_url":"https://github.com/twifty","followers_url":"https://api.github.com/users/twifty/followers","following_url":"https://api.github.com/users/twifty/following{/other_user}","gists_url":"https://api.github.com/users/twifty/gists{/gist_id}","starred_url":"https://api.github.com/users/twifty/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/twifty/subscriptions","organizations_url":"https://api.github.com/users/twifty/orgs","repos_url":"https://api.github.com/users/twifty/repos","events_url":"https://api.github.com/users/twifty/events{/privacy}","received_events_url":"https://api.github.com/users/twifty/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-03-14T16:46:40Z","updated_at":"2016-04-14T06:31:29Z","closed_at":"2016-04-14T06:31:29Z","body":"This is a feature request, and although it is for the code coverage component I feel it better placed here since this is where the test classes are parsed.\r\n\r\nThe `@codeCoverageIgnore` annotations are useful for excluding those lines which would otherwise hinder a 100% goal, for a single test. The biggest problem is that they litter the code being tested. In the real world, just because it may be impossible for one test to hit a line of code, it doesn't mean another test (which internally calls into the same code) also has that restriction.\r\n\r\nLet me better explain with an example:\r\n````php\r\nclass BeingTested {\r\n    function __construct(CacheManagerInterface $cache = null)\r\n    {\r\n        $this->cache = $cache ?: new CacheManager();\r\n    }\r\n\r\n    private function someMethod()\r\n    {\r\n        if (!$this->cache->load($file)) {\r\n            throw new \\Exception(); // @codeCoverageIgnore\r\n        }\r\n    }\r\n}\r\n````\r\nThe `BeingTested` class has the option of being constructed with a custom `CacheManager`. But loading from the cache is just one line code. The tests being run will use an instance with a default `CacheManager` (which has also been tested) implying that the exception will never and can never be thrown within the context of this one test.\r\n\r\nHowever, another class being tested may create an instance of `BeingTested` with a non default cache. Now, that exception may be thrown. So the line becomes eligible for coverage.\r\n\r\nHaving the annotations embedded in the source being tested, messes up the coverage reports for different tests/groups/suites.\r\n\r\nA better method would be to define within the test class, what needs to be ignored. Very similar to the existing `@covers` annotation. How about something like:\r\n````php\r\n/**\r\n* @codeCoverageIgnore namespace\\BeingTested 23-28\r\n*/\r\nclass ExampleTest extends \\PHPUnit_Framework_TestCase\r\n{\r\n}\r\n````\r\nWhere `23-28` would be the line number(s) to ignore?"},"comment":{"url":"https://api.github.com/repos/sebastianbergmann/phpunit/issues/comments/209780456","html_url":"https://github.com/sebastianbergmann/phpunit/issues/2117#issuecomment-209780456","issue_url":"https://api.github.com/repos/sebastianbergmann/phpunit/issues/2117","id":209780456,"user":{"login":"sebastianbergmann","id":25218,"avatar_url":"https://avatars.githubusercontent.com/u/25218?v=3","gravatar_id":"","url":"https://api.github.com/users/sebastianbergmann","html_url":"https://github.com/sebastianbergmann","followers_url":"https://api.github.com/users/sebastianbergmann/followers","following_url":"https://api.github.com/users/sebastianbergmann/following{/other_user}","gists_url":"https://api.github.com/users/sebastianbergmann/gists{/gist_id}","starred_url":"https://api.github.com/users/sebastianbergmann/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sebastianbergmann/subscriptions","organizations_url":"https://api.github.com/users/sebastianbergmann/orgs","repos_url":"https://api.github.com/users/sebastianbergmann/repos","events_url":"https://api.github.com/users/sebastianbergmann/events{/privacy}","received_events_url":"https://api.github.com/users/sebastianbergmann/received_events","type":"User","site_admin":false},"created_at":"2016-04-14T06:31:29Z","updated_at":"2016-04-14T06:31:29Z","body":"I do not think this to be useful, sorry."}}