|
| 1 | +--- |
| 2 | +isChild: true |
| 3 | +--- |
| 4 | + |
| 5 | +## Test Driven Development |
| 6 | + |
| 7 | +Unit Testing is a programatical approach to ensure functions, classes and methods are working as |
| 8 | +expected, from the point you build them all the way through to the development cycle. By checking |
| 9 | +values going in and out of various functions and methods, you can make sure the internal logic is |
| 10 | +working correctly. By using Dependecy Injection and building "mock" classes you can check internal |
| 11 | +parameter values for even better test coverage. |
| 12 | + |
| 13 | +When you create a class or function you should create a unit test for it. At a very basic level you should |
| 14 | +make sure it errors if you send it bad arguments and make sure it works if you send it valid arguments. |
| 15 | +This will help ensure that when you make changes to this class or function later on in the development |
| 16 | +cycle that the old functionality continues to work as expected. The only alternative to this would be |
| 17 | +var_dump() in a test.php, which is no way to build an application - large or small. |
| 18 | + |
| 19 | +The other use for unit tests is contributing to open source. If you can write a test that shows broken |
| 20 | +functionality, then fix it, and show the test working, patches are much more likely to be accepted. If |
| 21 | +you run a project who accepts pull requests, you should suggest this as a requirement for pull requests. |
| 22 | + |
| 23 | +PHPUnit is the most popular and has become a de facto standard with its popular adoption amongst [PHP |
| 24 | +frameworks][phpfws] and [Composer][composer] component developers, but there are a few alternatives around. |
| 25 | + |
| 26 | +* [PHPUnit](http://phpunit.de/) |
| 27 | +* [Enhance PHP](http://www.enhance-php.com/) |
| 28 | +* [PUnit](http://punit.smf.me.uk/) |
| 29 | + |
| 30 | +[phpfws]: /#libraries_and_frameworks |
| 31 | +[composer]: /#composer_and_packagist |
0 commit comments