colly_wyx
2018-05-18 50a53f7db63c5729b0ddbc93367117cf35ccf03c
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
104
<?php
/**
 * PhpUnderControl_PhalApiApi_Test
 *
 * 针对 ../PhalApi/Api.php PhalApi_Api 类的PHPUnit单元测试
 *
 * @author: dogstar 20141004
 */
 
require_once dirname(__FILE__) . '/test_env.php';
 
if (!class_exists('PhalApi_Api')) {
    require dirname(__FILE__) . '/../PhalApi/Api.php';
}
 
class PhpUnderControl_PhalApiApi_Test extends PHPUnit_Framework_TestCase
{
    public $coreApi;
 
    protected function setUp()
    {
        parent::setUp();
 
        $this->coreApi = new PhalApi_Api();
    }
 
    protected function tearDown()
    {
        DI()->filter = NULL;
    }
 
    /**
     * @group testInitialize
     */ 
    public function testInitialize()
    {
        DI()->request = new PhalApi_Request(array('service' => 'Default.Index'));
        $rs = $this->coreApi->init();
    }
 
 
    public function testInitializeWithWrongSign()
    {
        $data = array();
        $data['service'] = 'Default.Index';
 
        DI()->request = new PhalApi_Request($data);
        $rs = $this->coreApi->init();
    }
 
    public function testInitializeWithRightSign()
    {
        $data = array();
        $data['service'] = 'Default.Index';
 
        DI()->request = new PhalApi_Request($data);
        $rs = $this->coreApi->init();
 
    }
 
    public function testSetterAndGetter()
    {
        $this->coreApi->username = 'phalapi';
        $this->assertEquals('phalapi', $this->coreApi->username);
    }
 
    /**
     * @expectedException PhalApi_Exception_InternalServerError
     */
    public function testGetUndefinedProperty()
    {
        $this->coreApi->name = 'PhalApi';
        $rs = $this->coreApi->noThisKey;
    }
 
    public function testApiImpl()
    {
        $data = array();
        $data['service'] = 'Impl.Add';
        $data['version'] = '1.1.0';
        $data['left'] = '6';
        $data['right'] = '1';
 
        DI()->request = new PhalApi_Request($data);
        DI()->filter = 'PhalApi_Filter_Impl';
 
        $impl = new PhalApi_Api_Impl();
        $impl->init();
 
        $rs = $impl->add();
        $this->assertEquals(7, $rs);
    }
 
    /**
     * @expectedException PhalApi_Exception_InternalServerError
     */
    public function testIllegalFilter()
    {
        DI()->filter = 'PhalApi_Filter_Impl_NotFound';
 
        $impl = new PhalApi_Api_Impl();
        $impl->init();
    }
}