colly_wyx
2018-05-03 b8a82d561917a4336214225f65f4488d977c5fb1
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
/**
 * PhpUnderControl_ApiUser_Test
 *
 * 针对 ../../Demo/Api/User.php Api_User 类的PHPUnit单元测试
 *
 * @author: dogstar 20150128
 */
 
require_once dirname(__FILE__) . '/../test_env.php';
 
if (!class_exists('Api_User')) {
    require dirname(__FILE__) . '/../../Demo/Api/User.php';
}
 
class PhpUnderControl_ApiUser_Test extends PHPUnit_Framework_TestCase
{
    public $apiUser;
 
    protected function setUp()
    {
        parent::setUp();
 
        $this->apiUser = new Api_User();
    }
 
    protected function tearDown()
    {
    }
 
 
    /**
     * @group testGetRules
     */ 
    public function testGetRules()
    {
        $rs = $this->apiUser->getRules();
    }
 
    /**
     * @group testGetBaseInfo
     */ 
    public function testGetBaseInfo()
    {
        //Step 1. 构建请求URL
        $url = 'service=User.GetBaseInfo&user_id=1';
 
        //Step 2. 执行请求    
        $rs = PhalApi_Helper_TestRunner::go($url);
 
        //Step 3. 验证
        $this->assertNotEmpty($rs);
        $this->assertArrayHasKey('code', $rs);
        $this->assertArrayHasKey('msg', $rs);
        $this->assertArrayHasKey('info', $rs);
 
        $this->assertEquals(0, $rs['code']);
 
        $this->assertEquals('dogstar', $rs['info']['name']);
        $this->assertEquals('oschina', $rs['info']['note']);
    }
 
    public function testGetMultiBaseInfo()
    {
        //Step 1. 构建请求URL
        $url = 'service=User.GetMultiBaseInfo&user_ids=1,2,3';
 
        //Step 2. 执行请求    
        $rs = PhalApi_Helper_TestRunner::go($url);
 
        //Step 3. 验证
        $this->assertNotEmpty($rs);
        $this->assertArrayHasKey('code', $rs);
        $this->assertArrayHasKey('msg', $rs);
        $this->assertArrayHasKey('list', $rs);
 
        foreach ($rs['list'] as $item) {
            $this->assertArrayHasKey('id', $item);
            $this->assertArrayHasKey('name', $item);
            $this->assertArrayHasKey('note', $item);
        }
    }
 
}