SpecTestCase.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. /*
  3. * This file is part of Mustache.php.
  4. *
  5. * (c) 2010-2014 Justin Hileman
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. abstract class Mustache_Test_SpecTestCase extends PHPUnit_Framework_TestCase
  11. {
  12. protected static $mustache;
  13. public static function setUpBeforeClass()
  14. {
  15. self::$mustache = new Mustache_Engine();
  16. }
  17. protected static function loadTemplate($source, $partials)
  18. {
  19. self::$mustache->setPartials($partials);
  20. return self::$mustache->loadTemplate($source);
  21. }
  22. /**
  23. * Data provider for the mustache spec test.
  24. *
  25. * Loads YAML files from the spec and converts them to PHPisms.
  26. *
  27. * @param string $name
  28. *
  29. * @return array
  30. */
  31. protected function loadSpec($name)
  32. {
  33. $filename = dirname(__FILE__) . '/../../../vendor/spec/specs/' . $name . '.yml';
  34. if (!file_exists($filename)) {
  35. return array();
  36. }
  37. $data = array();
  38. $yaml = new sfYamlParser();
  39. $file = file_get_contents($filename);
  40. // @hack: pre-process the 'lambdas' spec so the Symfony YAML parser doesn't complain.
  41. if ($name === '~lambdas') {
  42. $file = str_replace(" !code\n", "\n", $file);
  43. }
  44. $spec = $yaml->parse($file);
  45. foreach ($spec['tests'] as $test) {
  46. $data[] = array(
  47. $test['name'] . ': ' . $test['desc'],
  48. $test['template'],
  49. isset($test['partials']) ? $test['partials'] : array(),
  50. $test['data'],
  51. $test['expected'],
  52. );
  53. }
  54. return $data;
  55. }
  56. }