colly
2017-08-07 78981c784ebe0fda3d1ff20cabe4e21bed2e6549
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
<?php
/**
 * PhpUnderControl_PhalApiRequestFormatterCallable_Test
 *
 * 针对 ../../../PhalApi/Request/Formatter/Callable.php PhalApi_Request_Formatter_Callable 类的PHPUnit单元测试
 *
 * @author: dogstar 20151107
 */
 
require_once dirname(__FILE__) . '/../../test_env.php';
 
if (!class_exists('PhalApi_Request_Formatter_Callable')) {
    require dirname(__FILE__) . '/../../../PhalApi/Request/Formatter/Callable.php';
}
 
class PhpUnderControl_PhalApiRequestFormatterCallable_Test extends PHPUnit_Framework_TestCase
{
    public $phalApiRequestFormatterCallable;
 
    protected function setUp()
    {
        parent::setUp();
 
        $this->phalApiRequestFormatterCallable = new PhalApi_Request_Formatter_Callable();
 
        DI()->loader->addDirs('Request/Formatter/Classes');
    }
 
    protected function tearDown()
    {
    }
 
 
    /**
     * @group testParse
     */ 
    public function testParse()
    {
        $value = '1';
        $rule = array('callback' => 'callbackForFormatterTest', 'params' => '11.11', 'name' => 'aKey');
 
        $rs = $this->phalApiRequestFormatterCallable->parse($value, $rule);
        $this->assertEquals('1_fun', $rs);
    }
 
    public function testParseStaticClassCallType2()
    {
        $value = '1';
        $rule = array('callback' => array('FormatterCallbackMyClass2', 'handle'), 'name' => 'rs');
 
        $rs = $this->phalApiRequestFormatterCallable->parse($value, $rule);
        $this->assertEquals('1_handle2', $rs);
    }
 
    public function testParseStaticClassCallType4()
    {
        $value = '1';
        $rule = array('callable' => 'FormatterCallbackMyClass::handle', 'name' => 'rs');
 
        $rs = $this->phalApiRequestFormatterCallable->parse($value, $rule);
        $this->assertEquals('1_handle', $rs);
    }
 
    public function testParseInstanceClassCall()
    {
        $value = '1';
        $rule = array('callable' => array(new FormatterCallbackMyClass(), 'handle'), 'name' => 'rs');
 
        $rs = $this->phalApiRequestFormatterCallable->parse($value, $rule);
        $this->assertEquals('1_handle', $rs);
    }
 
    public function testParseWithClouser()
    {
        $value = '1';
        $aCallback = function ($value, $rule) { 
            return $value . '_clouser';
        };
        $rule = array('callback' => $aCallback, 'name' => 'rs');
 
        $rs = $this->phalApiRequestFormatterCallable->parse($value, $rule);
        $this->assertEquals('1_clouser', $rs);
    }
}
 
function callbackForFormatterTest($value, $rule, $params) {
    //echo "got you!";
    //var_dump($value, $rule, $params);
    return $value . '_fun';
}