Basic Example 1:
declare(strict_types=1); final class FunctionsTest extends WP_UnitTestCase { public function testPushAndPop() { $stack = []; $this->assertSame(0, count($stack)); array_push($stack, 'foo'); $this->assertSame('foo', $stack[count($stack)-1]); $this->assertSame(1, count($stack)); $this->assertSame('foo', array_pop($stack)); $this->assertSame(0, count($stack)); } }
Basic Example 2:
with setUp() & tearDown().
use PHPUNIT_Framework_TestCase as TestCase; // sometimes it can be // use PHPUnit\Framework\TestCase as TestCase; class MathTest extends TestCase { public $fixtures; protected function setUp() { $this->fixtures = []; } protected function tearDown() { $this->fixtures = NULL; } public function testEmpty() { $this->assertTrue($this->fixtures == []); } }
For more info:
https://riptutorial.com/phpunit