By W. Jason Gilmore
on July 28, 2015
- 1 of
-
10 Productive PHP Tools for Testing and Debugging
There’s more to testing than just unit testing. Here are 10 wide-ranging testing and debugging utilities that can make the PHP developer’s life much -
Cucumber
I recently attended a local Ruby usergroup meeting, and was treated to an introduction to the Cucumber behavior-driven development tool. Cucumber allows you to write tests in “plain English” (or any of 30 other spoken languages) and then execute them in conjunction with a third-party tool such as Watir, Selenium, or Mechanize to execute the tests within a browser.
Although originally written for testing Ruby on Rails applications, Cucumber can be used with many mainstream programming languages, including Java, Python and PHP. Learn more about how to configure Cucumber to test your PHP-driven websites here. -
PHPUnit
Test-driven development (TDD) is all the rage these days, and for good reason. By elevating the role of testing — insomuch that tests are developed alongside the application code rather than after much of the application code has already been written — developers are constantly encouraged to think about the different ways in which errors or unexpected outcomes can occur. As a result, they accordingly write tests to ensure their application doesn’t succumb to those errors.
The PHPUnit testing framework offers PHP developers a fantastic solution for doing TDD, offering a rigorous solution for writing, organizing and automating tests. Incorporating such a tool into your daily development routine can result in enormous productivity increases by saving you the hassle of having to test features such as the user login process manually.
This test will confirm that the account controller’s login action can accept a valid email address and password, authenticate the account, redirect the user to the site’s homepage, and finally confirm that a valid user session exists.
To learn more about PHPUnit, check out the official website, and read the PHPBuilder article, Use PHPUnit to Implement Unit Testing in Your PHP Development -
SimpleTest
SimpleTest is another great automated testing solution, which like PHPUnit allows developers to write unit tests using familiar PHP syntax. Additionally, SimpleTest offers several features not natively available to PHPUnit (although these features can be used with PHPUnit in conjunction with third-party tools) such as Web interface testing, including the ability to test authentication and Web forms.
Although not as well known as PHPUnit, SimpleTest’s user-friendly approach to testing continues to earn the framework accolades among many members of the PHP community. For this reason, if you’re a relative novice to programming and feel particularly intimidated by the various testing frameworks, SimpleTest may be well worth a look. -
XDebug
Much of the time you spend testing and debugging will involve grunt work that requires you to inspect the state of your application at various stages of execution. Typically accomplished using native PHP statements such asecho
andvar_dump
, reviewing the contents of an object can quickly become a messy affair due to the lack of coherent formatting when the object contents are output to the browser.
The XDebug PHP extension can greatly enhance the readability of this data by changing how array and object contents are output to the browser.
Installed in mere minutes, XDebug is one of those tools that quickly will make you wonder how you ever got along without it. For more information about XDebug, be sure to visit the official website and read the article A Sanity-saving Debugging Solution for Your PHP Development. -
Firebug
These days, creating great websites isn’t simply a function of understanding a server-side language, with even the simplest of websites are driven by a symphony of HTML, CSS, JavaScript and a language such as PHP. Therefore, your ability to test and debug all facets of the website effectively is going to weigh heavily on your productivity. And for such purposes, there are few tools more capable than Firebug, a Firefox extension that you can use to inspect and manipulate every conceivable characteristic of a Web page.
Whether you want to see what your website looks like with all images disabled, experiment with CSS-driven font sizes, or easily measure the dimensions of a DIV using a built-in ruler, Firebug contains a seemingly endless array of useful features capable of answering any question you may have regarding your website’s operation.
For more information about Firebug, see the official home page, and be sure to check out the Developer.com article Firebug: Add Browser-based Debugging to Your Ajax Development. -
FirePHP
FirePHP extends the aforementioned Firebug’s capabilities to the server side, allowing you to easily log messages and other data hailing from a PHP script. This can be tremendously useful when debugging Ajax-driven features, or when you simply want to inspect the contents of an object or array without having to repeatedly insert and delete echo or var_dump statements.
Like Firebug, FirePHP is also a Firefox extension. However you’ll also need to install a simple PHP library on the server running your PHP-driven website. This script serves as the bridge for communications between the server and Firebug/FirePHP. Learn more at thethe official website, and be sure to check out the Developer.com article Firebug: Add Browser-based Debugging to Your Ajax Development. -
Watir
As its name implies, Watir (“Web Application Testing in Ruby”) has its roots in the Ruby community, but it can be used in conjunction with a wide variety of programming languages, PHP included. The toolkit allows you to write scripts that automate browser-based tasks in order to determine whether both your Web interface and server-side application are performing as expected.
Although originally natively capable of testing only Internet Explorer, numerous extensions allow you to automate testing within all of the major browsers, including Firefox, Safari, and Google Chrome. Further, you can automate the execution of your Watir tests just as you can with PHPUnit using Ruby’s Test::Unit framework. -
Selenium
Like Watir, Selenium is a testing solution that allows you to verify the proper operation of your website from the user’s perspective. In addition to providing developers with the ability to write scripted tests, an impressive Firefox extension known as Selenium IDE allows test developers to record tests directly from within Firefox simply by interacting with the website. These actions will then be converted into the scripts that Selenium will use to execute the tests. Scripting capabilities are supported for all of the other major browsers.
To learn more about Selenium, check out the official website. -
UserTesting.com
Most small businesses or open source projects lack the funding necessary to hire a full- or even part-time quality assurance team. Yet those of you in search of feedback from your fellow humans aren’t out of luck, because quite a few online usability testing services can offer extremely detailed and frank feedback at a surprisingly low cost.
One such service is UserTesting.com, which for just $39 will provide you with both video and written summaries of their testing panel’s experience interacting with your website. UserTesting.com’s services are so popular that globally recognized companies such as Amazon.com, Staples and Cisco have relied upon the service for unbiased third-party feedback. -
Bugzilla
With all of these great testing and debugging utilities at your disposal, you’re going to need some effective way to keep track of the problems you uncover, not to mention assign them to various team members. One of the most popular issue tracking solutions is BugZilla, an open source project used to manage issues within not only high-profile project initiatives such as the Mozilla Foundation and the Apache Software Foundation but also organizations such as NASA, Facebook and The New York Times.
Bugzilla supports all of the features you might expect in a high-quality issue tracking solution, including the ability to track the status of reported bugs, assign and change the status of bugs, and create useful reports analyzing metrics such as bug reporting frequency. Although not written in PHP, it’s a Perl-based project meaning you’ll be able to run it on any server capable of supporting PHP.
Learn more about Bugzilla by heading over to its official website, where you can also experiment with a Bugzilla test installation.
I’ve been perched atop the testing and debugging soapbox lately, having written several tutorials introducing great utilities such as PHPUnit and FirePHP. Perhaps more accurately, I’ve been focusing on productivity enhancement, because the true measure of productivity is based not on the amount of code written in any given day, but rather on the amount of code written that we know will function as expected. Tools such as PHPUnit and FirePHP can go a very long way towards helping you make this determination.
Yet despite the general notion that programming is a profession steeped in discipline and rigor, members of the programming community tend to be rather finicky folks who can be very particular when it comes to tooling. Thankfully PHP developers have a great deal to choose from when it comes to testing and debugging tools, and in this article I’ll highlight 10 of my favorites.
Comment and Contribute
Your comment has been submitted and is pending approval.
W. Jason Gilmore