What do you need to know about unit testing in PHP?

What do you need to know about unit testing in PHP?

There are a few rules you’ll need to worry about when writing your cases so that they’ll work with PHPUnit: Most often, you’ll want to have your test class extend the PHPUnit_Framework_TestCase class. This gives you access to built-in functionality like the setUp () and tearDown () methods for your tests.

How to write a test case with PHPUnit?

With PHPUnit, the most basic thing you’ll write is a test case. A test case is just a term for a class with several different tests all related to the same functionality. There are a few rules you’ll need to worry about when writing your cases so that they’ll work with PHPUnit:

Can you have private test methods in PHPUnit?

The methods need to be public. You can have private methods in your tests, but they won’t be run as tests by PHPUnit. The test methods will never receive any parameters. When you write your tests, you need to make them as self-contained as possible, pulling in what they need themselves.

Which is the best way to install PHPUnit?

If you’re yet to install PHPUnit, the simplest way to grab it is from its PEAR channel. If all goes well, you’ll have all the tools you need installed. The PEAR installer will grab any dependencies you might need for it to run. If you want to install it manually, there are instructions in the PHPUnit manual.

Why is validation important in a PHP form?

These pages will show how to process PHP forms with security in mind. Proper validation of form data is important to protect your form from hackers and spammers! The HTML form we will be working at in these chapters, contains various input fields: required and optional text fields, radio buttons, and a submit button:

What should the name of the test class be in PHP?

Most often, you’ll want to have your test class extend the PHPUnit_Framework_TestCase class. This gives you access to built-in functionality like the setUp () and tearDown () methods for your tests. The name of the test class needs to mimic the name of the class you’re testing.