| name | write unittest |
| description | Write PHP UnitTest for WordPress Plugin. |
Rules
- Unit test directory —
test/Unit
- Test File name should add suffix -
Test.php
Sample Example
Use this template as sample when creating new test files. It shows all conventions applied together:
<?php
declare( strict_types=1 );
use StorePress\AdminUtils\Traits\HelperMethodsTrait;
use StorePress\AdminUtils\Traits\SingletonTrait;
class HelperMethodsTest extends WP_UnitTestCase {
use SingletonTrait;
use HelperMethodsTrait;
private HelperMethodsTest $test_instance;
public function set_up(): void {
parent::set_up();
$this->test_instance = self::instance();
}
public function tear_down(): void {
parent::tear_down();
$_GET = array();
$_POST = array();
$_REQUEST = array();
}
public function test_get_var_returns_value_when_set(): void {
$variable = 'test_value';
$this->assertSame( 'test_value', $this->test_instance->get_var( $variable ) );
}
public function test_get_var_returns_default_when_not_set(): void {
$variable = null;
unset( $variable );
$this->assertSame( 'default', $this->test_instance->get_var( $variable, 'default' ) );
}
public function test_get_var_returns_null_when_no_default(): void {
$variable = null;
unset( $variable );
$this->assertNull( $this->test_instance->get_var( $variable ) );
}
}