1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Vectorface\SnappyRouterTests\Handler; |
4
|
|
|
|
5
|
|
|
use PHPUnit\Framework\TestCase; |
6
|
|
|
use Vectorface\SnappyRouter\Handler\DirectScriptHandler; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Tests the DirectScriptHandler class. |
10
|
|
|
* @copyright Copyright (c) 2014, VectorFace, Inc. |
11
|
|
|
* @author Dan Bruce <[email protected]> |
12
|
|
|
*/ |
13
|
|
|
class DirectScriptHandlerTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* An overview of how to use the class. |
17
|
|
|
* @test |
18
|
|
|
*/ |
19
|
|
|
public function synopsis() |
20
|
|
|
{ |
21
|
|
|
// the configuration maps a path like /cgi-bin to this folder |
22
|
|
|
$config = array( |
23
|
|
|
DirectScriptHandler::KEY_PATH_MAP => array( |
24
|
|
|
'/cgi-bin' => __DIR__ |
25
|
|
|
) |
26
|
|
|
); |
27
|
|
|
$handler = new DirectScriptHandler($config); |
28
|
|
|
$path = '/cgi-bin/test_script.php'; |
29
|
|
|
// the file itself exists so we should get back true |
30
|
|
|
$this->assertTrue( |
31
|
|
|
$handler->isAppropriate($path, array(), array(), 'GET') |
32
|
|
|
); |
33
|
|
|
// the test script simply has `echo "Hello world!"` |
34
|
|
|
$expected = 'Hello world!'; |
35
|
|
|
$this->assertEquals($expected, $handler->performRoute()); |
36
|
|
|
|
37
|
|
|
// the script is not found so the handler should not be marked as |
38
|
|
|
// appropriate |
39
|
|
|
$path = '/cgi-bin/script_not_found.php'; |
40
|
|
|
$this->assertFalse( |
41
|
|
|
$handler->isAppropriate($path, array(), array(), 'GET') |
42
|
|
|
); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Tests that the getRequest() method returns null. |
47
|
|
|
*/ |
48
|
|
View Code Duplication |
public function testGetRequest() |
|
|
|
|
49
|
|
|
{ |
50
|
|
|
$config = array( |
51
|
|
|
DirectScriptHandler::KEY_PATH_MAP => array( |
52
|
|
|
'/cgi-bin' => __DIR__ |
53
|
|
|
) |
54
|
|
|
); |
55
|
|
|
$handler = new DirectScriptHandler($config); |
56
|
|
|
$this->assertTrue($handler->isAppropriate('/cgi-bin/test_script.php', array(), array(), 'GET')); |
57
|
|
|
$this->assertNull($handler->getRequest()); |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.