PHPUnit Incomplete and Skipped Tests

Sometimes it happens that you have not finished writing a test due to focus on other aspects of a project. In such a scenarion you can use the phpunit feature to mark the test as incomplete.

Example code incomplete test

use PHPUnit\Framework\TestCase;

class PhoneTest extends TestCase
{
    public function testValidPhoneNumbers()
    {
        $this->markTestIncomplete(
          'This test has not been implemented yet.'
        );
    }
}

Example code skipping test due to certain precondition

use PHPUnit\Framework\TestCase;

class PhoneTest extends TestCase
{
    /**
     * @requires PHP >= 5.3
     */
    public function testScenarioWithPhpVersion(): void
    {
    }

    /**
     * @requires PHPUnit < 8
     */
    public function testScenarioWithPhpUnitVersion(): void
    {
    }

    /**
     * @requires OS WIN32|WINNT
     */
    public function testScenarioWindowsServer(): void
    {
    }

    /**
     * @requires function imap_open
     */
    public function testScenarioImapOpen(): void
    {
    }
}

Complete list of precondition is available under https://phpunit.readthedocs.io/en/9.2/incomplete-and-skipped-tests.html#skipping-tests-using-requires

what clients say about us

Client testimonials

Our sites look great and run smoothly. Thanks for all your hard work and patience in getting us to where we are today.

contact us

Contact Us

If you have questions or want us to send you a quote for project please email us.

latest news

Articles

PHPUnit mock magic functions
Learn more about PHPUnit Partial Mock.