- PHP 7.1 (https://php.net/downloads.php)
- Composer (https://getcomposer.org/)
- PHPUnit 7.1 (https://phpunit.de/)
For command line use, please setup properly for global environment.
Install phpunit for project
composer install
Project/
|-- src/ (php source code)
|-- tests/ (Testing files)
|-- composer.json (Composer configuration file)
|-- phpunit.xml (PHPUnit configuration file)
Run all testing files in tests/
folder
vendor/bin/phpunit tests
Run testing settings in phpunit.xml configuration
vendor/bin/phpunit
- Class with
Test
for naming convention. - Test Class MUST extends
PHPUnit\Framework\TestCase
- Method name starts with
test
or with annotation/** @test */
- Name file with suffix
Test.php
.
Example: ExampleTest.php
<?php
use PHPUnit\Framework\TestCase;
class ExampleTest extends TestCase
{
/** @test */
public function test_feature()
{
// arrange
// act
// assert
}
}
- PHPUnit Assertions (https://phpunit.de/manual/current/en/appendixes.assertions.html)
- PHPUnit Configration (http://phpunit.readthedocs.io/en/7.1/configuration.html)
- Visit PHPUnit Manual for more information.