{"action":"opened","issue":{"url":"https://api.github.com/repos/Brain-WP/BrainMonkey/issues/41","repository_url":"https://api.github.com/repos/Brain-WP/BrainMonkey","labels_url":"https://api.github.com/repos/Brain-WP/BrainMonkey/issues/41/labels{/name}","comments_url":"https://api.github.com/repos/Brain-WP/BrainMonkey/issues/41/comments","events_url":"https://api.github.com/repos/Brain-WP/BrainMonkey/issues/41/events","html_url":"https://github.com/Brain-WP/BrainMonkey/issues/41","id":352419064,"node_id":"MDU6SXNzdWUzNTI0MTkwNjQ=","number":41,"title":"Remove filter test example?","user":{"login":"dingo-d","id":8638515,"node_id":"MDQ6VXNlcjg2Mzg1MTU=","avatar_url":"https://avatars3.githubusercontent.com/u/8638515?v=4","gravatar_id":"","url":"https://api.github.com/users/dingo-d","html_url":"https://github.com/dingo-d","followers_url":"https://api.github.com/users/dingo-d/followers","following_url":"https://api.github.com/users/dingo-d/following{/other_user}","gists_url":"https://api.github.com/users/dingo-d/gists{/gist_id}","starred_url":"https://api.github.com/users/dingo-d/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dingo-d/subscriptions","organizations_url":"https://api.github.com/users/dingo-d/orgs","repos_url":"https://api.github.com/users/dingo-d/repos","events_url":"https://api.github.com/users/dingo-d/events{/privacy}","received_events_url":"https://api.github.com/users/dingo-d/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-08-21T07:35:14Z","updated_at":"2018-08-21T07:35:14Z","closed_at":null,"author_association":"NONE","body":"I'm going through the documentation, and I can see examples for tests that use `add_filter` and `add_action`, but I don't see any mention of testing `remove_filter/action`.\r\n\r\nSo am I right in assuming this is the right way to test for `remove_filter` in a method?\r\n\r\n```php\r\nclass My_Class {\r\n  public function set_allowed_rest_headers() : void {\r\n    remove_filter( 'rest_pre_serve_request', 'rest_send_cors_headers' );\r\n\r\n    add_filter( 'rest_pre_serve_request', function( $value ) {\r\n      header( 'Access-Control-Allow-Methods: OPTIONS, GET, POST, PUT, DELETE, PATCH', false );\r\n    }\r\n  }\r\n}\r\n```\r\n\r\nTest:\r\n\r\n```php\r\nclass Rest_Tests extends InitTestCase {\r\n  public function setUp() {\r\n    parent::setUp();\r\n    $this->test_class = new My_Class();\r\n  }\r\n\r\n  public function test_allowed_rest_headers() {\r\n    $this->portal_functionality->set_allowed_rest_headers();\r\n\r\n    self::assertFalse( has_filter( 'rest_pre_serve_request', 'rest_send_cors_headers' ) );\r\n  }\r\n}\r\n```\r\n\r\nThe `InitTestCase` looks like this\r\n\r\n```php\r\nuse PHPUnit\\Framework\\TestCase;\r\nuse Brain\\Monkey;\r\n\r\nclass InitTestCase extends TestCase {\r\n  /**\r\n   * Setup method necessary for Brain Monkey to function\r\n   */\r\n  protected function setUp() {\r\n    parent::setUp();\r\n    Monkey\\setUp();\r\n  }\r\n\r\n  /**\r\n   * Teardown method necessary for Brain Monkey to function\r\n   */\r\n  protected function tearDown() {\r\n    Monkey\\tearDown();\r\n    parent::tearDown();\r\n  }\r\n}\r\n```\r\n\r\nThe test passes, so I guess this is ok? Also I'm testing the added filter by adding\r\n\r\n```php\r\nself::assertTrue( has_filter( 'rest_pre_serve_request', 'function( $value )' ) );\r\n```\r\n\r\nand this also passes, but I don't see a green bar over that line in my code coverage report."}}
{"actor":{"display_login":"dingo-d"}}