PHPUnit

Last updated
PHPUnit
Developer(s) Sebastian Bergmann
Initial release27 November 2001;21 years ago (2001-11-27) [1]
Stable release
10 / 3 February 2023;3 days ago (2023-02-03) [2]
Repository
Written in PHP
Operating system Cross-platform
Type Unit testing framework
License BSD 3 Clause
Website phpunit.de

PHPUnit is a unit testing framework for the PHP programming language. It is an instance of the xUnit architecture for unit testing frameworks that originated with SUnit and became popular with JUnit. PHPUnit was created by Sebastian Bergmann and its development is hosted on GitHub.

Contents

Purpose

PHPUnit is based on the idea that developers should be able to find mistakes in their newly committed code quickly and assert that no code regression has occurred in other parts of the code base. Much like other unit testing frameworks, PHPUnit uses assertions to verify that the behavior of the specific component - or "unit" - being tested behaves as expected. [3]

Benefits

The goal of unit testing is to isolate each part of the program and show that the individual parts are correct. A unit test provides a strict, written contract that the piece of code must satisfy. As a result, unit tests find problems early in the development cycle.

PHPUnit can output test results in a number of different formats, including JUnit XML and TestDox.

Vulnerabilities

A vulnerability that allowed attackers to execute remote code via PHPUnit was discovered in late 2017. By sending a payload of PHP code to a file that is part of PHPUnit, an attacker could execute PHP code on the webserver. [4]

Related Research Articles

JUnit is a unit testing framework for the Java programming language. JUnit has been important in the development of test-driven development, and is one of a family of unit testing frameworks which is collectively known as xUnit that originated with SUnit.

In computer programming, unit testing is a software testing method by which individual units of source code—sets of one or more computer program modules together with associated control data, usage procedures, and operating procedures—are tested to determine whether they are fit for use.

xUnit is the collective name for several unit testing frameworks that derive their structure and functionality from Smalltalk's SUnit. SUnit, designed by Kent Beck in 1998, was written in a highly structured object-oriented style, which lent easily to contemporary languages such as Java and C#. Following its introduction in Smalltalk the framework was ported to Java by Kent Beck and Erich Gamma and gained wide popularity, eventually gaining ground in the majority of programming languages in current use. The names of many of these frameworks are a variation on "SUnit", usually replacing the "S" with the first letter in the name of their intended language. These frameworks and their common architecture are collectively known as "xUnit".

<span class="mw-page-title-main">NUnit</span>

NUnit is an open-source unit testing framework for the .NET Framework and Mono. It serves the same purpose as JUnit does in the Java world, and is one of many programs in the xUnit family.

Zend Studio is a commercial, proprietary integrated development environment (IDE) for PHP developed by Zend Technologies, based on the PHP Development Tools (PDT) plugin for the Eclipse platform.

QuickCheck is a software library, specifically a combinator library, originally written in the programming language Haskell, designed to assist in software testing by generating test cases for test suites – an approach known as property testing.

Data-driven testing (DDT), also known as table-driven testing or parameterized testing, is a software testing methodology that is used in the testing of computer software to describe testing done using a table of conditions directly as test inputs and verifiable outputs as well as the process where test environment settings and control are not hard-coded. In the simplest form the tester supplies the inputs from a row in the table and expects the outputs which occur in the same row. The table typically contains values which correspond to boundary or partition input spaces. In the control methodology, test configuration is "read" from a database.

lime is a unit testing and functional testing framework built specifically for the Symfony web application framework based on the Test::More Perl library. The framework is designed to have readable output from tests, including color formatting, by following the Test Anything Protocol which also allows for easy integration with other tools. lime tests are run in a sandbox environment to minimize test executions from influencing each other. Though the lime testing framework is built for testing within Symfony, lime is contained within a single PHP file and has no dependency on Symfony or any other library.

Hamcrest is a framework that assists writing software tests in the Java programming language. It supports creating customized assertion matchers, allowing match rules to be defined declaratively. These matchers have uses in unit testing frameworks such as JUnit and jMock. Hamcrest has been included in JUnit 4 since 2012, but was omitted from JUnit 5 in 2017.

Mockito is an open source testing framework for Java released under the MIT License. The framework allows the creation of test double objects in automated unit tests for the purpose of test-driven development (TDD) or behavior-driven development (BDD).

Debug code is computer code introduced to a computer program to test for errors or to help determine the cause of an error. It can be as simple as an echo command to print the value of a variable at certain points of a program. Modern integrated development environments sometimes render this unnecessary by allowing the placement of stop points at specific places in the program, and providing the ability to view the value of variables through the IDE rather than program output.

TestDox is a documentation generator for Java to create an overview of test case methods written for the JUnit unit testing framework presented as full sentences. Created by Chris Stevenson in 2003, to date versions exist for .net, PHP and Ruby. The term testdox format refers to the naming convention used for the test methods.

<span class="mw-page-title-main">Jenkins (software)</span> Open source automation server

Jenkins is an open source automation server. It helps automate the parts of software development related to building, testing, and deploying, facilitating continuous integration and continuous delivery. It is a server-based system that runs in servlet containers such as Apache Tomcat. It supports version control tools, including AccuRev, CVS, Subversion, Git, Mercurial, Perforce, ClearCase and RTC, and can execute Apache Ant, Apache Maven and sbt based projects as well as arbitrary shell scripts and Windows batch commands.

Concordion is a specification by example framework originally developed by David Peterson, and now maintained by a team of contributors, led by Nigel Charman.

<span class="mw-page-title-main">FuelPHP</span>

FuelPHP is an open-source web application framework written in PHP which implements the HMVC pattern.

xUnit.net Software testing framework for .NET software framework

xUnit.net is a free and open-source unit testing tool for the .NET Framework, written by the original author of NUnit. The software can also be used with .NET Core and Mono.

<span class="mw-page-title-main">Behat (computer science)</span>

Behat is a test framework for behavior-driven development written in the PHP programming language. Behat was created by Konstantin Kudryashov and its development is hosted on GitHub.

<span class="mw-page-title-main">PhantomJS</span> Headless browser

PhantomJS is a discontinued headless browser used for automating web page interaction. PhantomJS provides a JavaScript API enabling automated navigation, screenshots, user behavior and assertions making it a common tool used to run browser-based unit tests in a headless system like a continuous integration environment. PhantomJS is based on WebKit making it a similar browsing environment to Safari and Google Chrome. It is open-source software released under the BSD License.

EasyMock is an open-source testing framework for Java released under the Apache License. The framework allows the creation of test double objects for the purpose of Test-driven Development (TDD) or Behavior Driven Development (BDD).

References

  1. "PHP: Revision 63330". svn.php.net.
  2. "Releases · sebastianbergmann/phpunit". GitHub.
  3. Assertion (computing)
  4. Bergmann, Sebastian. "PHPUnit: A Security Risk?". The PHP Consulting Company. The PHP Consulting Company. Retrieved 20 October 2020.