Issue
Is it possible to replace some class instantiation with the mock one so that when I call new SomeClass()
the mock one is created with specified mocked behavior?
Solution
It is highly not recommended but possible, take a look at links bellow
https://github.com/php-test-helpers/php-test-helpers
https://github.com/krakjoe/uopz
It's better to use Dependency Injection (simply, it means injecting instances as arguments to function instead of creating them inside the function). As a result you will be able easily to mock that argument while testing. You can google about other pros of DI, but here a few links for you: answer on SO, DI and phpunit
Answered By - Oleks
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.