-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' into feature/pragma-dot-notation
- Loading branch information
Showing
8 changed files
with
144 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?php | ||
|
||
class InvertedSection extends Mustache { | ||
public $repo = array(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
{{#repo}}<b>{{name}}</b>{{/repo}} | ||
{{^repo}}No repos :({{/repo}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
No repos :( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php | ||
|
||
require_once '../Mustache.php'; | ||
require_once 'PHPUnit/Framework.php'; | ||
|
||
/** | ||
* A PHPUnit test case for Mustache.php. | ||
* | ||
* This is a very basic, very rudimentary unit test case. It's probably more important to have tests | ||
* than to have elegant tests, so let's bear with it for a bit. | ||
* | ||
* This class assumes an example directory exists at `../examples` with the following structure: | ||
* | ||
* @code | ||
* examples | ||
* foo | ||
* Foo.php | ||
* foo.mustache | ||
* foo.txt | ||
* bar | ||
* Bar.php | ||
* bar.mustache | ||
* bar.txt | ||
* @endcode | ||
* | ||
* To use this test: | ||
* | ||
* 1. {@link http://www.phpunit.de/manual/current/en/installation.html Install PHPUnit} | ||
* 2. run phpunit from the `test` directory: | ||
* `phpunit MustacheTest` | ||
* 3. Fix bugs. Lather, rinse, repeat. | ||
* | ||
* @extends PHPUnit_Framework_TestCase | ||
*/ | ||
class MustacheTest extends PHPUnit_Framework_TestCase { | ||
|
||
/** | ||
* Test everything in the `examples` directory. | ||
* | ||
* @dataProvider getExamples | ||
* @access public | ||
* @param mixed $class | ||
* @param mixed $template | ||
* @param mixed $output | ||
* @return void | ||
*/ | ||
public function testExamples($class, $template, $output) { | ||
$m = new $class; | ||
$this->assertEquals($output, $m->render($template)); | ||
} | ||
|
||
|
||
/** | ||
* 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; | ||
} | ||
} |