diff --git a/test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php b/test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php index 004ec21..446aa49 100644 --- a/test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php +++ b/test/Mustache/Test/FiveThree/Functional/MustacheSpecTest.php @@ -15,15 +15,8 @@ * @group mustache-spec * @group functional */ -class Mustache_Test_FiveThree_Functional_MustacheSpecTest extends PHPUnit_Framework_TestCase +class Mustache_Test_FiveThree_Functional_MustacheSpecTest extends Mustache_Test_SpecTestCase { - private static $mustache; - - public static function setUpBeforeClass() - { - self::$mustache = new Mustache_Engine; - } - /** * For some reason data providers can't mark tests skipped, so this test exists * simply to provide a 'skipped' test if the `spec` submodule isn't initialized. @@ -72,51 +65,4 @@ class Mustache_Test_FiveThree_Functional_MustacheSpecTest extends PHPUnit_Framew return $data; } - - /** - * Data provider for the mustache spec test. - * - * Loads YAML files from the spec and converts them to PHPisms. - * - * @param string $name - * - * @return array - */ - private function loadSpec($name) - { - $filename = dirname(__FILE__) . '/../../../../../vendor/spec/specs/' . $name . '.yml'; - if (!file_exists($filename)) { - return array(); - } - - $data = array(); - $yaml = new sfYamlParser; - $file = file_get_contents($filename); - - // @hack: pre-process the 'lambdas' spec so the Symfony YAML parser doesn't complain. - if ($name === '~lambdas') { - $file = str_replace(" !code\n", "\n", $file); - } - - $spec = $yaml->parse($file); - - foreach ($spec['tests'] as $test) { - $data[] = array( - $test['name'] . ': ' . $test['desc'], - $test['template'], - isset($test['partials']) ? $test['partials'] : array(), - $test['data'], - $test['expected'], - ); - } - - return $data; - } - - private static function loadTemplate($source, $partials) - { - self::$mustache->setPartials($partials); - - return self::$mustache->loadTemplate($source); - } } diff --git a/test/Mustache/Test/Functional/MustacheSpecTest.php b/test/Mustache/Test/Functional/MustacheSpecTest.php index e21efba..96fcf40 100644 --- a/test/Mustache/Test/Functional/MustacheSpecTest.php +++ b/test/Mustache/Test/Functional/MustacheSpecTest.php @@ -15,16 +15,8 @@ * @group mustache-spec * @group functional */ -class Mustache_Test_Functional_MustacheSpecTest extends PHPUnit_Framework_TestCase +class Mustache_Test_Functional_MustacheSpecTest extends Mustache_Test_SpecTestCase { - - private static $mustache; - - public static function setUpBeforeClass() - { - self::$mustache = new Mustache_Engine; - } - /** * For some reason data providers can't mark tests skipped, so this test exists * simply to provide a 'skipped' test if the `spec` submodule isn't initialized. @@ -126,51 +118,4 @@ class Mustache_Test_Functional_MustacheSpecTest extends PHPUnit_Framework_TestCa { return $this->loadSpec('sections'); } - - /** - * Data provider for the mustache spec test. - * - * Loads YAML files from the spec and converts them to PHPisms. - * - * @param string $name - * - * @return array - */ - private function loadSpec($name) - { - $filename = dirname(__FILE__) . '/../../../../vendor/spec/specs/' . $name . '.yml'; - if (!file_exists($filename)) { - return array(); - } - - $data = array(); - $yaml = new sfYamlParser; - $file = file_get_contents($filename); - - // @hack: pre-process the 'lambdas' spec so the Symfony YAML parser doesn't complain. - if ($name === '~lambdas') { - $file = str_replace(" !code\n", "\n", $file); - } - - $spec = $yaml->parse($file); - - foreach ($spec['tests'] as $test) { - $data[] = array( - $test['name'] . ': ' . $test['desc'], - $test['template'], - isset($test['partials']) ? $test['partials'] : array(), - $test['data'], - $test['expected'], - ); - } - - return $data; - } - - private static function loadTemplate($source, $partials) - { - self::$mustache->setPartials($partials); - - return self::$mustache->loadTemplate($source); - } } diff --git a/test/Mustache/Test/SpecTestCase.php b/test/Mustache/Test/SpecTestCase.php new file mode 100644 index 0000000..d4dc2c9 --- /dev/null +++ b/test/Mustache/Test/SpecTestCase.php @@ -0,0 +1,67 @@ +setPartials($partials); + + return self::$mustache->loadTemplate($source); + } + + /** + * Data provider for the mustache spec test. + * + * Loads YAML files from the spec and converts them to PHPisms. + * + * @param string $name + * + * @return array + */ + protected function loadSpec($name) + { + $filename = dirname(__FILE__) . '/../../../vendor/spec/specs/' . $name . '.yml'; + if (!file_exists($filename)) { + return array(); + } + + $data = array(); + $yaml = new sfYamlParser; + $file = file_get_contents($filename); + + // @hack: pre-process the 'lambdas' spec so the Symfony YAML parser doesn't complain. + if ($name === '~lambdas') { + $file = str_replace(" !code\n", "\n", $file); + } + + $spec = $yaml->parse($file); + + foreach ($spec['tests'] as $test) { + $data[] = array( + $test['name'] . ': ' . $test['desc'], + $test['template'], + isset($test['partials']) ? $test['partials'] : array(), + $test['data'], + $test['expected'], + ); + } + + return $data; + } +}