1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Vectorface\SnappyRouterTests\Task; |
4
|
|
|
|
5
|
|
|
use \PHPUnit_Framework_TestCase; |
6
|
|
|
use Vectorface\SnappyRouter\Config\Config; |
7
|
|
|
use Vectorface\SnappyRouter\Handler\CliTaskHandler; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Tests the CliTaskHandler. |
11
|
|
|
* @copyright Copyright (c) 2014, VectorFace, Inc. |
12
|
|
|
* @author Dan Bruce <[email protected]> |
13
|
|
|
*/ |
14
|
|
|
class CliTaskHandlerTest extends PHPUnit_Framework_TestCase |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* An overview of how to use the CliTaskHandler class. |
18
|
|
|
* @test |
19
|
|
|
*/ |
20
|
|
|
public function synopsis() |
21
|
|
|
{ |
22
|
|
|
$options = array( |
23
|
|
|
Config::KEY_TASKS => array( |
24
|
|
|
'TestTask' => 'Vectorface\SnappyRouterTests\Task\DummyTestTask' |
25
|
|
|
) |
26
|
|
|
); |
27
|
|
|
$handler = new CliTaskHandler($options); |
28
|
|
|
$components = array( |
29
|
|
|
'dummyScript.php', |
30
|
|
|
'--task', |
31
|
|
|
'TestTask', |
32
|
|
|
'--action', |
33
|
|
|
'testAction' |
34
|
|
|
); |
35
|
|
|
|
36
|
|
|
// the components needs to be at least 5 elements with --task and --action |
37
|
|
|
$this->assertTrue($handler->isAppropriate($components)); |
38
|
|
|
|
39
|
|
|
// assert the handler is not appropriate if we only have 4 elements |
40
|
|
|
$this->assertFalse($handler->isAppropriate(array_slice($components, 0, 4))); |
41
|
|
|
|
42
|
|
|
// assert the handler is not appropriate if --task and --action are missing |
43
|
|
|
$badComponents = $components; |
44
|
|
|
$badComponents[1] = '--service'; |
45
|
|
|
$this->assertFalse($handler->isAppropriate($badComponents)); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* A test that asserts an exception is thrown if we call an action missing |
50
|
|
|
* from a registered task. |
51
|
|
|
* @expectedException Vectorface\SnappyRouter\Exception\ResourceNotFoundException |
52
|
|
|
* @expectedExceptionMessage TestTask task does not have action missingAction. |
53
|
|
|
*/ |
54
|
|
|
public function testMissingActionOnTask() |
55
|
|
|
{ |
56
|
|
|
$options = array( |
57
|
|
|
Config::KEY_TASKS => array( |
58
|
|
|
'TestTask' => 'Vectorface\SnappyRouterTests\Task\DummyTestTask' |
59
|
|
|
) |
60
|
|
|
); |
61
|
|
|
$handler = new CliTaskHandler($options); |
62
|
|
|
$components = array( |
63
|
|
|
'dummyScript.php', |
64
|
|
|
'--task', |
65
|
|
|
'TestTask', |
66
|
|
|
'--action', |
67
|
|
|
'missingAction' |
68
|
|
|
); |
69
|
|
|
$this->assertTrue($handler->isAppropriate($components)); |
70
|
|
|
$handler->performRoute(); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|