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 skip a PHPUnit test?
- How to run tests in parallel with PHPUnit?
- How to use hooks in PHPUnit?
- What are PHPUnit required extensions
- How to use the PHPUnit Framework TestCase?
- How to run PHPUnit in quiet mode?
- How to show warnings in PHPUnit?
- How to load fixtures with PHPUnit?
- How to use a listener with PHPUnit?
- How to stop PHPUnit on failure?
See more codes...