blob: a9fbe92a8e882cc5cffcccfcbb242c716bb8bb0c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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);
}
}
|