Permalink
Browse files

Refactored listener tests

- Moved scaffolding into a test helper
  • Loading branch information...
1 parent 6441d35 commit 2aef599558f142efa7f7a62d8432d9b47eb93a2f @weierophinney weierophinney committed Apr 12, 2012
@@ -2,43 +2,14 @@
namespace PhlyBlog\Compiler\Listener;
use PHPUnit_Framework_TestCase as TestCase;
-use PhlyBlog\Compiler;
-use PhlyBlog\CompilerOptions;
-use PhlyBlog\Compiler\TestAsset;
-use Zend\Mvc\Router\Http\TreeRouteStack;
-use Zend\View\View;
-use Zend\View\Renderer;
-use Zend\View\Resolver;
class EntriesTest extends TestCase
{
public function setUp()
{
- $options = include __DIR__ . '/../../../../config/module.config.php';
-
- $router = TreeRouteStack::factory($options['di']['instance']['Zend\Mvc\Router\RouteStack']['parameters']);
-
- $resolver = new Resolver\TemplatePathStack();
- $resolver->addPath(__DIR__ . '/../../../../view');
- $renderer = new Renderer\PhpRenderer();
- $renderer->setResolver($resolver);
- $renderer->plugin('url')->setRouter($router);
-
- $this->view = new View;
- $this->view->addRenderingStrategy(function($e) use ($renderer) {
- return $renderer;
- });
-
- $this->options = new CompilerOptions($options['blog']['options']);
- $this->file = new Compiler\ResponseFile();
+ TestHelper::injectScaffolds($this);
$this->entries = new Entries($this->view, $this->file, $this->options);
-
- $this->writer = new TestAsset\MockWriter;
- $this->strategy = new Compiler\ResponseStrategy($this->writer, $this->file, $this->view);
- $this->compiler = new Compiler(new Compiler\PhpFileFilter(__DIR__ . '/../../_posts'));
$this->compiler->events()->attach($this->entries);
- $json = file_get_contents(__DIR__ . '/../../_posts/metadata.json');
- $this->metadata = json_decode($json, true);
}
public function testCreatesNoFilesPriorToCompilation()
@@ -2,42 +2,12 @@
namespace PhlyBlog\Compiler\Listener;
use PHPUnit_Framework_TestCase as TestCase;
-use PhlyBlog\Compiler;
-use PhlyBlog\CompilerOptions;
-use PhlyBlog\Compiler\TestAsset;
-use Zend\Mvc\Router\Http\TreeRouteStack;
-use Zend\View\View;
-use Zend\View\Renderer;
-use Zend\View\Resolver;
class TagsTest extends TestCase
{
public function setUp()
{
- $options = include __DIR__ . '/../../../../config/module.config.php';
-
- $router = TreeRouteStack::factory($options['di']['instance']['Zend\Mvc\Router\RouteStack']['parameters']);
-
- $resolver = new Resolver\TemplatePathStack();
- $resolver->addPath(__DIR__ . '/../../../../view');
- $renderer = new Renderer\PhpRenderer();
- $renderer->setResolver($resolver);
- $renderer->plugin('url')->setRouter($router);
-
- $this->view = new View;
- $this->view->addRenderingStrategy(function($e) use ($renderer) {
- return $renderer;
- });
-
- $this->options = new CompilerOptions($options['blog']['options']);
- $this->file = new Compiler\ResponseFile();
- $this->writer = new TestAsset\MockWriter;
- $this->strategy = new Compiler\ResponseStrategy($this->writer, $this->file, $this->view);
- $this->compiler = new Compiler(new Compiler\PhpFileFilter(__DIR__ . '/../../_posts'));
- $json = file_get_contents(__DIR__ . '/../../_posts/metadata.json');
- $this->metadata = json_decode($json, true);
- $this->expected = include(__DIR__ . '/../../_posts/metadata.php');
-
+ TestHelper::injectScaffolds($this);
$this->tags = new Tags($this->view, $this->writer, $this->file, $this->options);
$this->compiler->events()->attach($this->tags);
}
@@ -0,0 +1,41 @@
+<?php
+namespace PhlyBlog\Compiler\Listener;
+
+use PHPUnit_Framework_TestCase as TestCase;
+use PhlyBlog\Compiler;
+use PhlyBlog\CompilerOptions;
+use PhlyBlog\Compiler\TestAsset;
+use Zend\Mvc\Router\Http\TreeRouteStack;
+use Zend\View\View;
+use Zend\View\Renderer;
+use Zend\View\Resolver;
+
+class TestHelper
+{
+ public static function injectScaffolds(TestCase $testCase)
+ {
+ $options = include __DIR__ . '/../../../../config/module.config.php';
+
+ $router = TreeRouteStack::factory($options['di']['instance']['Zend\Mvc\Router\RouteStack']['parameters']);
+
+ $resolver = new Resolver\TemplatePathStack();
+ $resolver->addPath(__DIR__ . '/../../../../view');
+ $renderer = new Renderer\PhpRenderer();
+ $renderer->setResolver($resolver);
+ $renderer->plugin('url')->setRouter($router);
+
+ $testCase->view = new View;
+ $testCase->view->addRenderingStrategy(function($e) use ($renderer) {
+ return $renderer;
+ });
+
+ $testCase->options = new CompilerOptions($options['blog']['options']);
+ $testCase->file = new Compiler\ResponseFile();
+ $testCase->writer = new TestAsset\MockWriter;
+ $testCase->strategy = new Compiler\ResponseStrategy($testCase->writer, $testCase->file, $testCase->view);
+ $testCase->compiler = new Compiler(new Compiler\PhpFileFilter(__DIR__ . '/../../_posts'));
+ $json = file_get_contents(__DIR__ . '/../../_posts/metadata.json');
+ $testCase->metadata = json_decode($json, true);
+ $testCase->expected = include(__DIR__ . '/../../_posts/metadata.php');
+ }
+}

0 comments on commit 2aef599

Please sign in to comment.