function executeDir($directory) { $iterator = new DirectoryIterator($directory); while ($iterator->valid()) { $entry = $iterator->getFilename(); $path = $directory . '/' . $entry; $iterator->next(); if ($entry[0] == '.') { continue; } if (is_file($path)) { if (substr($entry, -4) != '.php') { continue; } if (ctype_upper($entry[0])) { $test = new DocTest($path); if ($test->failed()) { echo $test->toString(); $this->fail('Doc test failed.'); } else { if ($test->numOfPassed()) { echo ','; } else { echo ' '; } } } } elseif (is_dir($path)) { $this->executeDir($path); } } }
<?php // This file is example.php /** * Adds two numbers. * Usage example: * <code> * echo add(20, 22); /// 42 * </code> */ function add($a, $b) { return $a + $b; } if (__FILE__ == realpath($_SERVER['SCRIPT_FILENAME'])) { require_once 'DocTest.php'; $test = new DocTest(__FILE__); echo $test->toString(); }