test

PHP Logo

Debugging And Testing PHP With assert()

8th August 2021 - 16 minutes read time

PHP has a built in debugging and testing tool called assertions, which is essentially the assert() function and a few configuration options.

With this feature you can add additional checks to your application whilst you are developing it so that when you deploy to production you can be sure that things will run correctly. It is simple to run and allows you to embed testing code within your production code without having an adverse effect on performance.

I've seen the use of assert() in a couple of open source PHP projects, but had not really dug into how it works or what it does. As it turns out, assert() is actually very useful and can also be found in other languages like C/C++, Python and JavaScript.

Phing Logo

Integrating Phing With PHPUnit

16th January 2009 - 2 minutes read time

PHPUnit is a unit testing framework, written in PHP, and which is used to test PHP code. You can integrate the testing that PHPUnit does into Phing. You might want to use Phing to create a nightly build that contains the latest version of your program. The last thing you want is Phing to create a nightly build that is riddled with errors.

The way around this is to use PHPUnit to test our code whilst we are running Phing. If any tests fail then Phing will not finish the build.

Create a target at the top of your build.xml file and make sure it is run first. Then add the following code to the target, This will use PHPUnit to test your code.

Apache HTTP Logo

Apache Bench Tool

25th February 2008 - 4 minutes read time

The Apache Bench tool can be found in the bin directory of any standard instillation of the Apache HTTP server. It can be used to test the response times of any web server you want and can be useful if you want to stress test a mission critical server before it goes live.

To use the tool open a command prompt (or terminal), navigate the Apache bin folder and find the program ab, this is the Apache Bench tool. The simplest form of running the tool is to use a single URL. However, you must enter a full file name or the tool will give you an invalid URL error.

ab http://www.google.com/index.html

This gives the following output.