This package contains an example to test php core methods.
- most of the time there is no need to change php-core-method-response
- sometimes it is enough to work with a facade-class which returns the method-results and the class could be mocked
- if there are many system checks in your code and you would like to test each scenario its getting tricky
- many solutions using I found use override_function or other magic methods where you manipulate the method at all
- this dont work, if you need to return different responses on different calls
- there is nothing wrong with the other ways I found, but they dont fit to my usecase
- advantages:
- you can test every path in your code
- you can produce every situation without creating complex environments
- you have the full handle above every built-in method
- no need to change production code
- you can override built-in functions in your current namespace
- since PHP5.3 with namespaces
- if you are using a leading backslash PHP is going to take the global built-in function.
example:
\date('Y-m-d')
./vendor/bin/phpunit.phar -c ./phpunit.xml --testdox