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 show warnings in PHPUnit?
- How to mock a method with different arguments in PHPUnit?
- How to run all PHPUnit tests?
- How to install PHPUnit with a PHAR file?
- How to run tests in parallel with PHPUnit?
- How to order tests with PHPUnit?
- How to use the PHPUnit Framework TestCase?
- How to mock a static method with PHPUnit?
- How to use a listener with PHPUnit?
See more codes...