Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

Drupal 8 is replacing the testing framework Simpletest with PHPUnit which could be depreciated in Drupal 9.

I'm not upgrading yet to Drupal 8, but I was wondering how I can write existing tests in PHPUnit (to follow-up with the trend) for Drupal 7, instead in Simpletest?

Is there any method or module for integrating PHPUnit with Drupal 7?

There are few like phpunit or drunit, but they're not for Drupal 7.

share|improve this question
1  
Just want to throw Behat out there. It's great for doing real-world test scenarios (not really unit testing): drupal.org/project/drupalextension Once you get it setup, it makes testing Drupal functionality a breeze. We are running Behat in a CI environment and love it! –  donutdan4114 2 days ago

1 Answer 1

PHPUnit provides a nice API for building the objects whereas the Drupal's simpletest doesn't. There is one library available in gist for integrating PHPUnit with Drupal 7.
To execute those scripts you need to checkout this gist-repository. To execute Unit-Tests in the command-line simply go to a Drupal site (ie. <DRUPAL_ROOT>/sites/default) and use dphpunit.bash just as you would use the phpunit command.

The script consists of 3 files:

  1. dphpunit.bash - which simply invokes drun-dphpunit.php with a few extra parameters. It's needed because PHP is incapable of dealing with symlinks correctly.
  2. drun-dphpunit.php - which is basically the same as the upstream phpunit runner, except that it handles the extra parameter.
  3. bootstrap.inc.php - which makes a Drupal bootstrap very similar to drush.

For more information about it you may check this blog by the author of those script: http://devblog.more-onion.com/content/writing-unit-tests-drupal-7


There is one more library available for integration PHPUnit with Drupal 7: https://github.com/sebastianbergmann/phpunit

More information about this scripts can be checked here: http://thomaslattimore.com/blog/using-phpunit-with-drupal-7

share|improve this answer
    
@kenorb Does this worked for you??, or else if you have found and alternate better solution than please share. –  Ankit Agrawal 2 days ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.