Also: many languages prevent all access to private members in derived classes. This is by design: private is private.
If you need derives classes-only to have access, you should typically use the “protected”-modifier.
Doesn’t php have that?
It does.
So the PHP sadness in this case refers to lacking PHP knowledge of the person who wrote this blog?
The problem stems from people believing that unit in unit testing means a class's method.
Re:PHP Sadness
by giancarlostoro on Thursday November 29, 2018 @06:12AM
(#18559414)
Yeah you shouldnt override any existing code when doing unit testing, only updating properties if anything... Otherwise you are taking the code beyond its scope, if you need output from a method to be something specific... Just set the variable you are storing that methods return value into to what you need that output to be.
This is nice in theory, but you need to design everything to work dependency injection style (or really have a setter for everything) to achieve this. Using a random number? Store the generator. Opening a file? Use a "FooOpener". ...
Sometimes it's easier just to stub what you want.
Yeah- Sometimes I've gotten lazy and returned an object that has all the private stuff attached. Once I've verified that it works, I quit returning that object, keeping the methods private for normal use. It gives me a clear logical delineation yet allows me to test while developing.
If you can't put the thing you're testing (method, class, application) in the state you want to test using only public methods you are not testing something useful. If you're doing to get 100% coverage be happy: that's dead code you can remove.
Counterexample: Testing something that uses your language's Array.shuffle equivalent which doesn't expose the randomness provider. You can't put it in the right state without just stubbing the call and making it return the order you want.
You may not be testing the right things if you have to override your methods just for your tests.