summaryrefslogtreecommitdiffstats
path: root/tests/Router/RunnerFactoryTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Router/RunnerFactoryTest.php')
-rw-r--r--tests/Router/RunnerFactoryTest.php58
1 files changed, 58 insertions, 0 deletions
diff --git a/tests/Router/RunnerFactoryTest.php b/tests/Router/RunnerFactoryTest.php
new file mode 100644
index 0000000..a9fbe92
--- /dev/null
+++ b/tests/Router/RunnerFactoryTest.php
@@ -0,0 +1,58 @@
+<?php
+
+namespace Jasny\Router;
+
+use Jasny\Router\RunnerFactory;
+use Jasny\Router\Route;
+use Jasny\Router\Runner;
+
+class RunnerFactoryTest extends \PHPUnit_Framework_TestCase
+{
+ /**
+ * Provide data fpr testing 'create' method
+ */
+ public function createProvider()
+ {
+ $routeController = $this->createMock(Route::class);
+ $routeController->controller = 'foo-bar';
+
+ $routeCallback = $this->createMock(Route::class);
+ $routeCallback->fn = function() {};
+
+ $routePhpScript = $this->createMock(Route::class);
+ $routePhpScript->file = 'some_file.php';
+
+ return [
+ [$routeController, Runner\Controller::class],
+ [$routeCallback, Runner\Callback::class],
+ [$routePhpScript, Runner\PhpScript::class],
+ ];
+ }
+
+ /**
+ * Test creating Runner object using factory
+ * @dataProvider createProvider
+ *
+ * @param Route $route
+ * @param string $class Runner class to use
+ */
+ public function testCreate($route, $class)
+ {
+ $factory = new RunnerFactory();
+ $runner = $factory($route);
+
+ $this->assertInstanceOf($class, $runner, "Runner object has invalid class");
+ }
+
+ /**
+ * @expectedException InvalidArgumentException
+ * @expectedExceptionMessage Route has neither 'controller', 'fn' or 'file' defined
+ */
+ public function testCreatWithInvalideRoute()
+ {
+ $route = $this->createMock(Route::class);
+
+ $factory = new RunnerFactory();
+ $factory($route);
+ }
+}