Turn your manual testers into automation experts Request a DemoStart testRigor Free

PHP Testing

PHP Testing

PHP is the most commonly used server-side scripting language to create dynamic websites. Danish programmer Rasmus Lerdorf developed PHP in 1993. Originally, PHP stood for Personal Home Page, but now it’s known as Hypertext Preprocessor. The latest stable version currently available on the market is PHP 7.4. Many content management sites, like WordPress, Drupal, etc., use PHP. As per W3Tech reports, as of October 2022, PHP has been used by 80% of websites across the globe. PHP scripts are executed on the server side, then the server builds the output, and next, the HTML result is sent to the browser for rendering. Developers can directly embed PHP code into the HTML pages.

PHP has been one of the most favorable languages for developing dynamic websites for over a decade. But currently, the websites are getting very complex, and developers have also started using other components such as CMS. So for developing a new web application, creating the codebase from scratch requires a lot of effort and time; it's monotonous and repetitive. This is where PHP frameworks come into the picture. These frameworks provide built-in libraries and components to improve the workflow and streamline the process. The main advantages of using the frameworks are faster development, better performance, less code, common libraries, better maintainability, etc. Let's take a look at a list of the most widely used PHP frameworks:
  • Laravel
  • Symfony
  • CodeIgniter
  • Zend Framework / Laminas Project
  • Phalcon
  • CakePHP
  • Yii (Framework)
  • Slim
  • FuelPHP
  • Fat-Free Framework
So when we consider developing a web application, testing plays a crucial role in it. We can test a PHP website using different methods or tools. According to test automation pyramid, a robust testing strategy should include at least 3 layers:
  • Unit testing
  • Integration testing
  • System or end-to-end testing

Unit and Integration Testing

As you know, unit testing is responsible for testing individual chunks of code, vs. integration testing aims to test integration between modules. Any solid testing strategy ought to include both of these testing types.

When it comes to frameworks, below are the most commonly used ones:
  • PHPUnit
  • Codeception
  • Atoum
  • Guzzle


PHPUnit is an open-source testing framework widely used for unit testing of PHP applications. Based on xUnit architecture for the unit testing framework, it's a straightforward tool generally executed from the command line. Testing is primarily performed based on the assertions we add to the code. PHPUnit provides a robust framework for unit testing, where developers can test various controllers. However, it's not an ideal choice when it comes to API unit testing.

Below is a test code example:
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;

final class EmailTest extends TestCase
  public function testCanBeCreatedFromValidEmailAddress(): void

  public function testCannotBeCreatedFromInvalidEmailAddress(): void


  public function testCanBeUsedAsString(): void


Codeception is a solid wrapper on top of PHPUnit. Codeception is a testing framework mainly used for testing integration scenarios (although you can also use it for unit testing). We need to have a composer for installing Codeception. It's based on the BDD framework, which makes the code easy to read and debug. It provides various integration modules for different types of testing like database testing or API testing. It has inbuilt plugins to integrate with Jenkins. Since it supports different integrations and testing types, it's also called a full-stack testing framework.

Here's how your unit test might look like:
namespace Tests\Unit;

use \Tests\Support\UnitTester;

class UserTest extends \Codeception\Test\Unit
  public function testValidation()
    $user = new \App\User();





Atoum is another unit testing framework that provides a lot of inbuilt execution engines, such as the inline engine, isolation engine, and concurrent engines. Atoum delivers a high level of security for test execution as it isolates test methods from its process. We can execute test cases either in parallel or sequential. It also helps in mocking native PHP functions. Developers can easily integrate Atoum into the development project without any hassle.


Guzzle is an HTTP client framework for API testing between two PHP modules and can be used together with PHPUnit. Guzzle has a simple interface for building query strings, POST requests, streaming large uploads, etc. Guzzle uses a handler and middleware system to send HTTP requests. Users can set a proxy in Guzzle to hide the IP, modify request-response on the proxy side, and gather statistics.

End-to-End Testing

End-to-End testing or system testing mainly focuses on testing the entire user flow. These tests typically take a longer time to run; however, they are most accurate when built correctly. E2E tests cover the whole flow, not just its individual components. This type of testing can be performed either manually or through an automated tool.

Manual Testing

Manual testing is the easiest and fastest way to catch many ad-hoc issues. Testers can execute scenarios based on a test case or perform exploratory testing to capture a lot of edge cases. Manual execution of test cases is time-consuming, however, and if the development model is Agile, the QA team gets less time for testing the new features and the regression test cases. Another limitation is the visual regression testing which is impossible to perform manually. It is common nowadays to depend on automated testing to overcome these obstacles and ensure a more robust process.

Automated Testing

Automated testing helps to execute a vast volume of test cases within a short timeframe. With the support of automation, the development and QA teams will be able to meet the deadlines for project releases. There are a lot of tools and frameworks in the market for PHP websites. Let's look into the main options when it comes to end-to-end and system testing.

Here are the most popular and widely used tools:
  • Storyplayer
  • Kahlan
  • Selenium
  • testRigor


Storyplayer is an open-source testing framework for end-to-end testing. Storyplayer, we can test both web and API scenarios or create scenarios involving both web and API. In Storyplayer, all tests are written in PHP. There is no domain-specific language used. A composer is required to install Storyplayer. For developing scenarios, a good understanding of PHP is required.


Kahlan is a framework for end-to-end testing based on BDD (Behavior Driven Development). It uses Mocha capabilities, i.e., test cases are written in "describe-it" format. Kahlan supports code coverage testing and also has its own built-in reports and exporters. Users can develop scripts using Python and Ruby languages.

Selenium WebDriver

Selenium is one of the legacy automation frameworks currently available in the market. Selenium is mainly intended for web browser automation, and many third-party plugins are available in the market for generating reports and reading test data.

Here's an example of a test created with Selenium for a login function:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.Assert;
import org.testng.annotations.Test;
public class LoginAutomation {
  public void login() {
    System.setProperty("webdriver.chrome.driver", "path of driver");
    WebDriver driver=new ChromeDriver();
    WebElement username=driver.findElement(By.id("user_email_Login"));
    WebElement password=driver.findElement(By.id("user_password"));
    WebElement login=driver.findElement(By.name("commit"));
    String actualUrl="https://mywebsite.com/dashboard";
    String expectedUrl= driver.getCurrentUrl();


testRigor is an AI-integrated no-code automation tool that excels specifically with end-to-end testing. testRigor helps the QA team write test scripts in plain English; even manual QA can write robust test scripts with nearly zero test maintenance.

Let's mention a few important advantages of testRigor over other end-to-end testing tools discussed here:
  • Tests are extremely easy and fast to write, allowing companies to scale test coverage quickly.
  • There is no dependency on the HTML page structure. Typically, if any changes are made to the DOM, the test will fail, leading to false negative scenarios. testRigor uses integrated AI to capture all element locators and survives subsequent modifications.
  • The test maintenance issue is solved for good. Updating tests is as easy as using find and replace functionality.
Here's how an example for a login aboe looks like in testRigor:
click "Sign in"
enter "abc@gmail.com" into "Email"
enter "your_password" into "Password"
click “Login”

You can read more about the features of testRigor here.

Join the next wave of functional testing now.
A testRigor specialist will walk you through our platform with a custom demo.