[PHPUnit] Manage timeout

PHPUnit : Manage timeout

Background : When I lanch a phpunit test, it displayed an error :

PHP_Invoker_TimeoutException: Execution aborted after 1 second

Solution :


1. Modify the time wanted in phpunit configuration file : phpunit.xml :

<phpunit
    timeoutForSmallTests="1"
    timeoutForMediumTests="5"
    timeoutForLargeTests="10">
 // other codes
</phpunit>

So here, in this code, the time for the different tests will be 1 second, 5 seconds and 10 seconds.

2. Modify the comment of test(like annotation in java)

For small test (by default):

/**
 * @small 
 */
public function testNameOfSmallTest() {
     // Your test code
}

For medium test :

/**
 * @medium
 */
public function testNameOfMediumTest() {
    // Your test code
}

For large test :

/**
 * @large
 */
public function testNameOfLargeTest() {
   // Your test code
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s