phpunitPHPUnit usage example
PHPUnit is a unit testing framework for the PHP language. It is used to test the functionality of individual units of code.
Example
<?php
class MyTest extends PHPUnit_Framework_TestCase
{
public function testAdd()
{
$this->assertEquals(4, 2 + 2);
}
}
Output example
OK (1 test, 1 assertion)
Code explanation
-
class MyTest extends PHPUnit_Framework_TestCase
- This line declares a class called MyTest which extends the PHPUnit_Framework_TestCase class. -
public function testAdd()
- This line declares a public function called testAdd. -
$this->assertEquals(4, 2 + 2)
- This line uses the assertEquals method to check if the result of 2 + 2 is equal to 4.
Helpful links
More of Phpunit
- How to show warnings in PHPUnit?
- How to skip a PHPUnit test?
- How to increase memory limit in PHPUnit?
- How to set environment variables for PHPUnit?
- How to use the PHPUnit Framework TestCase?
- How to use filters with PHPUnit?
- How to stop PHPUnit on failure?
- How to disable color output in PHPUnit?
- How to mock with PHPUnit?
- How to install PHPUnit with a PHAR file?
See more codes...