I have a question about using PHPUnit to mock a private method inside a class. Let me introduce with an example: How can I stub the result of the private method to test the some more code part of the public function. Solved partially reading here Answer Usually you just don’t test or mock the private & protected methods directy.
Tag: phpunit
How to detect version of PHPUnit
I’m writing unit tests using an older version of PHPUnit (3.4) and thus can’t use all supported assertions listed in manual of 3.5 and 3.6. Though I could reengineer tests for instant support in my environment here, I’d like to make my tests dependent on current version of PHPUnit, so that it’s using assertsInstanceOf() as soon as my or any
Calling php code from php code on different server
The situation is following. I have a local (development) PHP server (Win + IIS) on my computer and I would like to call a function on a remote server because there is an executable file on the remote …
PHP and unit testing assertions with decimals
I have a method that returns a float like 1.234567890.I want to test that it really does so. However, it seems that this returned float has different precision on different platforms so how do I …
PHPUnit: Verifying that array has a key with given value
Given the following class: And this testcase: How do I verify that $params (which is an array) and is passed to $Other->post() contains a key named ‘key1’ that has a value of ‘Value 1’? I do not want to verify all of the array – this is just a sample code, in actual code the passed array has a lot
Best practices to test protected methods with PHPUnit
I found the discussion on Do you test private method informative. I have decided, that in some classes, I want to have protected methods, but test them. Some of these methods are static and short. Because most of the public methods make use of them, I will probably be able to safely remove the tests later. But for starting with