Is there a best practice for calling language-native functions when writing testable code?I have experimented a little with php code and have come up with two methodologies:create a wrapper class for all native functions and mocking this wrapper when writing testsusing namespace magic: calling all native functions without  specifying the global namespace (aFunction in stead of \aFunction) and then writing a method stub in the given namespace during testing, which will result in the code to be tested using the stub instead of the native functionIs there a more commonly used approach? What are the benefits and shortcomings of the most commonly used methodologies to test language-native function calls?
Unit tests and language-native function calls
unit testing
You don't unit-test language native functions. You test your code. You rely on the language you're using as well as on any third party library.Library / Language CodeIf you want the external code to be tested, that's ok, but not within your project. Fork the third party software, and do the tests there, be it PHP or a mailer class or whatever. Many projects come with unit tests nowadays, so likely there already is something for you to build on.The reason is simple. As soon as you fix something in a third party software, you immediately loose the ability to update, and thus the greatest benefit from using that software. Forking into your own (sub) projects works like a proxy, where you can change the software, but still are able to update (e.g. using git rebase), and, as an extra, you can easily contribute back to the projects, you rely on.ResourcesIf you - like you stated in your comment - want to make FTP (or MySQL or whatever) testable, i.e., get independend from PHP resources, encapsulate them in their own classes. If you use an FTP class likeclass FTP{    ...    public function connect($server, $user, $pass)    {        ...    }    public function put($bytes)    {        ...    }    ...}in combination with Dependency Injection, you can easily mock it. The class itself is usually not unit-tested - it is subject of an integration test within a controlled environment.