generate_test_classes.php 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. <?php
  2. /**
  3. * This script is used to generate test classes automatically from the phpunit
  4. * documentation in PHPDoc blocks
  5. */
  6. /**
  7. * Initialization
  8. */
  9. $codedir = dirname(__FILE__).'/../../main/';
  10. require $codedir.'inc/global.inc.php';
  11. $libdir = $codedir.'inc/lib/';
  12. $listfiles = scandir($libdir);
  13. $declared = get_declared_classes();
  14. // List of exclusions for classes not yet used
  15. $excludes = array('entity_repository.class.php','course_entity_repository.class.php');
  16. foreach ($listfiles as $file) {
  17. // we don't want folders for now
  18. if (is_dir($libdir.$file) || substr($file,0,1)=='.') { continue; }
  19. // we only want files ending in '.class.php'
  20. if (substr($file,-9) != 'class.php') { continue; }
  21. // excluding special cases
  22. if (in_array($file,$excludes)) { continue; }
  23. // all good, now proceeding with valid classes
  24. echo "Including ".$libdir.$file." unless it has already been included...\n";
  25. include_once $libdir.$file;
  26. $newdeclared = get_declared_classes();
  27. $newclasses = array_diff($newdeclared, $declared);
  28. foreach ($newclasses as $newclass) {
  29. $declared[] = $newclass;
  30. // Generate the call to phpunit-skelgen
  31. system('phpunit-skelgen --test -- '.$newclass.' '.$libdir.$file.' '.$newclass.'Test '.$codedir.'/../tests/phpunit/classes/'.$newclass.'Test.class.php');
  32. }
  33. }