Skip to content
This repository was archived by the owner on Aug 29, 2023. It is now read-only.

issue.private_method

edsonmedina edited this page Dec 18, 2014 · 6 revisions

#Private methods

class foo
{
    private function bar ()
    {
        // ...
    }
}

##Why is this a testing issue?

Private classes are a source of headaches when it comes to testing.

You can't test them directly.

While you can test them using Reflection, this technique doesn't work if you're trying to test a private method of an abstract class.

Also, you can't mock a private method when you're testing methods that depend on it.

##Possible refactorings

####Consider 'protected' instead

Protected methods can be mocked.

####Refactor

Sometimes the need for a private method is just an indication that something's wrong with your design.

Clone this wiki locally