Newer
Older
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
require_once 'handlers.php';
class MyHandler extends webbasics\BaseHandler {
function get(array $args=array()) {
return 'get ' . implode('-', $args);
}
function getFoo() {
return 'getFoo';
}
function getBar(array $args) {
return 'getBar ' . implode('-', $args);
}
function post(array $args=array()) {
return 'post ' . implode('-', $args);
}
function postFoo() {
return 'postFoo';
}
function postBar(array $args) {
return 'postBar ' . implode('-', $args);
}
}
class HandlersTest extends PHPUnit_Framework_TestCase {
private $myhandler;
function setUp() {
$this->myhandler = new MyHandler;
}
function testBaseHandlerGetNoMethodNoArgs() {
$this->assertHandlesGet('get ', $this->myhandler, array());
}
function testBaseHandlerGetNoMethodArgs() {
$this->assertHandlesGet('get baz', $this->myhandler, array('baz'));
}
function testBaseHandlerGetMethodNoArgs() {
$this->assertHandlesGet('getFoo', $this->myhandler, array('foo'));
}
function testBaseHandlerGetMethodArgs() {
$this->assertHandlesGet('getBar foo-baz', $this->myhandler, array('bar', 'foo', 'baz'));
}
function testBaseHandlerPostNoMethodNoArgs() {
$this->assertHandlesPost('post ', $this->myhandler, array());
}
function testBaseHandlerPostNoMethodArgs() {
$this->assertHandlesPost('post baz', $this->myhandler, array('baz'));
}
function testBaseHandlerPostMethodNoArgs() {
$this->assertHandlesPost('postFoo', $this->myhandler, array('foo'));
}
function testBaseHandlerPostMethodArgs() {
$this->assertHandlesPost('postBar foo-baz', $this->myhandler, array('bar', 'foo', 'baz'));
}
function assertHandlesGet($result, $handler, array $args=array()) {
$this->assertHandlesMethod($result, $handler, $args, 'GET');
}
function assertHandlesPost($result, $handler, array $args=array()) {
$this->assertHandlesMethod($result, $handler, $args, 'POST');
}
function assertHandlesMethod($result, $handler, array $args, $request_method) {
$_SERVER['REQUEST_METHOD'] = $request_method;
$this->assertEquals($result, $handler->handleRequest($args));
}
}
?>