2 min read · January 30, 2018
Testing code is an important part of development and should not be avoided. It adds extra time to development but it also improves code quality and saves you more time when you're adding new features, or refactoring your code without breaking something.
You're testing your code already between the development itself without maybe realizing. When you add some part of code, you either check for the correct output or response in browser, database etc. However this way not all cases are considered and it is not repeatable and automated. Soon you need something more reliable and organized.
In PHP there are available many testing tools and frameworks. Testing can be categorized based on the approach.
TDD is a software development process in which you repeat very short development cycles in which you write code that passes or intentionally fails.
Probably the most used tool and de-facto standard for unit testing in PHP is the PHPUnit testing framework. It has an awesome manual so do read it and start using TDD.
By using tools you create automated tests, where application is actually used instead of just checking certain parts of code.
Behavior driven development is a software development process that evolved from TDD. It makes unit tests more natural by making English sentences that express certain behavior. Read more about PHP focused BDD in the dedicated chapter.
What is spaghetti code?
Spaghetti code is a term for complex unstructured code, which also has lots of goto statements, exceptions, threads and other unstructured branching constructs.
What is Macaroni code?
Languages all mixed up like mac and cheese. For example, SQL and PHP together.