From 6e508d5b482819ec33eb2f67a31c991a60f85d68 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Sun, 25 Apr 2010 17:53:51 -0400 Subject: [PATCH 1/2] Rudimentary unit test script. --- test/MustacheTest.php | 110 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 110 insertions(+) create mode 100644 test/MustacheTest.php diff --git a/test/MustacheTest.php b/test/MustacheTest.php new file mode 100644 index 0000000..ac02ada --- /dev/null +++ b/test/MustacheTest.php @@ -0,0 +1,110 @@ +assertEquals($m->render($template), $output); + } + + + /** + * Data provider for testExamples method. + * + * Assumes that an `examples` directory exists inside parent directory. + * This examples directory should contain any number of subdirectories, each of which contains + * three files: one Mustache class (.php), one Mustache template (.mustache), and one output file + * (.txt). + * + * This whole mess will be refined later to be more intuitive and less prescriptive, but it'll + * do for now. Especially since it means we can have unit tests :) + * + * @access public + * @return array + */ + public function getExamples() { + $basedir = dirname(__FILE__) . '/../examples/'; + + $ret = array(); + + $files = new RecursiveDirectoryIterator($basedir); + while ($files->valid()) { + + if ($files->hasChildren() && $children = $files->getChildren()) { + $example = $files->getSubPathname(); + $class = null; + $template = null; + $output = null; + + foreach ($children as $file) { + if (!$file->isFile()) continue; + + $filename = $file->getPathInfo(); + $info = pathinfo($filename); + + switch($info['extension']) { + case 'php': + $class = $info['filename']; + include_once($filename); + break; + + case 'mustache': + $template = file_get_contents($filename); + break; + + case 'txt': + $output = file_get_contents($filename); + break; + } + } + + $ret[$example] = array($class, $template, $output); + } + + $files->next(); + } + return $ret; + } +} \ No newline at end of file From 3108aff56d3fae25c098cb64efa5f440bd75c3d8 Mon Sep 17 00:00:00 2001 From: Justin Hileman Date: Sun, 25 Apr 2010 17:55:43 -0400 Subject: [PATCH 2/2] fixing documentation for unit tests --- test/MustacheTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/MustacheTest.php b/test/MustacheTest.php index ac02ada..3cff074 100644 --- a/test/MustacheTest.php +++ b/test/MustacheTest.php @@ -27,7 +27,7 @@ require_once 'PHPUnit/Framework.php'; * * 1. {@link http://www.phpunit.de/manual/current/en/installation.html Install PHPUnit} * 2. run phpunit from the `test` directory: - * `phpunit MustacheTest` or just `phpunit` + * `phpunit MustacheTest` * 3. Fix bugs. Lather, rinse, repeat. * * @extends PHPUnit_Framework_TestCase