8 Must Have PHP Quality Assurance Tools
For shipping quality code, we must have testing in mind while coding (if not doing TDD). However, with the wide range of PHP testing tools out there, it’s hard to make a choice! Exploring PHP is a fun adventure (premium course on that here!) but it’s hard to assemble a toolbelt that’s not too heavy to wear to work!
This popular article will highlight the most popular testing tools and has been updated to reflect the state of QA tools in 2017.
Untested code is broken code.
PHPUnit is the go to testing framework for PHP. It was created by Sebastian Bergmann in 2004 and current in version 6 that requires PHP 7.
We have plenty of tutorials coming up about it, but here are some you can already consume.
Cucumber is a framework for creating acceptance tests from specifications. It’s known for it descriptive generated texts that can be read as just plain English. The official PHP implementation for Cucumber is Behat.
We have a getting started tutorial about it here on SitePoint. The below example taken from the documentation is a good example on how expressive those expectations are.
Feature: Listing command In order to change the structure of the folder I am currently in As a UNIX user I need to be able see the currently available files and folders there Scenario: Listing two files in a directory Given I am in a directory "test" And I have a file named "foo" And I have a file named "bar" When I run "ls" Then I should get: """ bar foo """
Atoum is another unit testing framework for PHP. It’s a standalone package that you can install via GitHub, Composer or via a PHAR executable file.
Atoum tests are very readable with expressive method names and chaining.
$this->integer($classInstance->myMethod()) ->isEqualTo(10); $this->string($classInstance->myMethod()) ->contains("Something heppened");
You want to learn more about PHP unit testing with Atoum, you can follow this tutorial.
Selenium is a tool for automated browser testing (Integration and acceptance testing). It transforms the tests to browser API commands and it asserts the expected results. It supports most of the available browsers out there.
We can use Selenium with PHPUnit using an extension.
composer require --dev phpunit/phpunit composer require --dev phpunit/phpunit-selenium
Here’s a simple example:
Continue reading %8 Must Have PHP Quality Assurance Tools%