forked from phalapi/phalapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhalApi_Response_Test.php
103 lines (81 loc) · 2.21 KB
/
PhalApi_Response_Test.php
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
/**
* PhpUnderControl_PhalApiResponse_Test
*
* 针对 ../PhalApi/Response.php PhalApi_Response 类的PHPUnit单元测试
*
* @author: dogstar 20141004
*/
require_once dirname(__FILE__) . '/test_env.php';
if (!class_exists('PhalApi_Response')) {
require dirname(__FILE__) . '/../PhalApi/Response.php';
}
class PhpUnderControl_PhalApiResponse_Test extends PHPUnit_Framework_TestCase
{
public $phalApiResponse;
protected function setUp()
{
parent::setUp();
$this->phalApiResponse = new PhalApi_Response_Json_Mock();
}
protected function tearDown()
{
}
/**
* @group testSetRet
*/
public function testSetRet()
{
$ret = '0';
$rs = $this->phalApiResponse->setRet($ret);
}
/**
* @group testSetData
*/
public function testSetData()
{
$data = array('sth' => 'hi~');
$rs = $this->phalApiResponse->setData($data);
}
/**
* @group testSetMsg
*/
public function testSetMsg()
{
$msg = 'this will shoul as a wrong msg';
$rs = $this->phalApiResponse->setMsg($msg);
}
public function testSetDebug()
{
$this->phalApiResponse->setDebug('stack', array('Fight~'));
$this->phalApiResponse->setDebug('sqls', array('SELECT', 'DELETE'));
}
/**
* @group testAddHeaders
*/
public function testAddHeaders()
{
$key = 'Content-Type';
$content = 'text/html;charset=utf-8';
$rs = $this->phalApiResponse->addHeaders($key, $content);
}
public function testGetHeaders()
{
$key = 'Version';
$content = '1.1.2';
$rs = $this->phalApiResponse->addHeaders($key, $content);
$this->assertEquals($content, $this->phalApiResponse->getHeaders($key));
$this->assertTrue(is_array($this->phalApiResponse->getHeaders()));
}
/**
* @group testOutput
*/
public function testOutput()
{
$this->phalApiResponse->setRet(404);
$this->phalApiResponse->setMsg('not found');
$this->phalApiResponse->setData(array('name' => 'PhalApi'));
$rs = $this->phalApiResponse->output();
$this->expectOutputRegex('/"ret":404/');
}
}