Miscellaneous SimpleTest Tips

SimpleTest is a unit testing framework for PHP, commonly used in Drupal development. Here are some useful tips and tricks for working with SimpleTest in Drupal:

1. Simulate External API Calls

Some modules interact with external APIs, and it can be useful to avoid using them during testing. A mock module can impersonate an external API by being enabled on the test setup stage.

For example, the Twitter module includes a twitter_mock submodule within its tests directory. This submodule changes the host that the module calls from api.twitter.com to the local website domain, effectively mocking the API response.

2. Debugging with Xdebug

Debugging can be challenging when working with SimpleTest due to the nature of the cURL requests made by the tests. Here are some strategies to help with debugging:

  • Using Cookies: If you are using cookies to trigger xdebug connections, ensure that they propagate to the cURL session. Tools like the Xdebug Bookmarklet or plugins like “easy Xdebug” or “xdebug helper” for Firefox and Chrome can help.
  • VirtualHost Configuration: For Drupal 7 or sessions without cookies, you can set up a VirtualHost on your Apache server with the necessary xdebug configuration. This allows all pages on this domain to trigger the debugger.
  • PHPStorm Configuration: If you are using PHPStorm, ensure that the “Max. simultaneous connections” is set to at least 4. Avoid using the “PHP Web Application” Run Configuration to start a debug session from your IDE, as it can block the cURL PHP-xdebug processes.

3. Simulate External API Calls

Some modules interact with external APIs, and it can be useful to avoid using them during testing. A mock module can impersonate an external API by being enabled on the test setup stage.

For example, the Twitter module includes a twitter_mock submodule within its tests directory. This submodule changes the host that the module calls from api.twitter.com to the local website domain, effectively mocking the API response.

4. Debugging with Xdebug

Debugging can be challenging when working with SimpleTest due to the nature of the cURL requests made by the tests. Here are some strategies to help with debugging:

  • Using Cookies: If you are using cookies to trigger xdebug connections, ensure that they propagate to the cURL session. Tools like the Xdebug Bookmarklet or plugins like “easy Xdebug” or “xdebug helper” for Firefox and Chrome can help.
  • VirtualHost Configuration: For Drupal 7 or sessions without cookies, you can set up a VirtualHost on your Apache server with the necessary xdebug configuration. This allows all pages on this domain to trigger the debugger.
  • PHPStorm Configuration: If you are using PHPStorm, ensure that the “Max. simultaneous connections” is set to at least 4. Avoid using the “PHP Web Application” Run Configuration to start a debug session from your IDE, as it can block the cURL PHP-xdebug processes.

5. Debugging with Xdebug

Debugging can be challenging when working with SimpleTest due to the nature of the cURL requests made by the tests. Here are some strategies to help with debugging:

  • Using Cookies: If you are using cookies to trigger xdebug connections, ensure that they propagate to the cURL session. Tools like the Xdebug Bookmarklet or plugins like “easy Xdebug” or “xdebug helper” for Firefox and Chrome can help.
  • VirtualHost Configuration: For Drupal 7 or sessions without cookies, you can set up a VirtualHost on your Apache server with the necessary xdebug configuration. This allows all pages on this domain to trigger the debugger.
  • PHPStorm Configuration: If you are using PHPStorm, ensure that the “Max. simultaneous connections” is set to at least 4. Avoid using the “PHP Web Application” Run Configuration to start a debug session from your IDE, as it can block the cURL PHP-xdebug processes.

Conclusion

SimpleTest is a powerful tool for testing Drupal applications, and these tips should help you work more efficiently and effectively. Remember to always keep your tests up-to-date and maintainable as your application evolves.