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
<?php
/**
 * PhpUnderControl_PhalApiHelperTracer_Test
 *
 * 针对 ../PhalApi/Helper/Tracer.php PhalApi_Helper_Tracer 类的PHPUnit单元测试
 *
 * @author: dogstar 20170415
 */
 
require_once dirname(__FILE__) . '/../test_env.php';
 
if (!class_exists('PhalApi_Helper_Tracer')) {
    require dirname(__FILE__) . '/../PhalApi/Helper/Tracer.php';
}
 
class PhpUnderControl_PhalApiHelperTracer_Test extends PHPUnit_Framework_TestCase
{
    public $phalApiHelperTracer;
 
    protected function setUp()
    {
        parent::setUp();
 
        $this->phalApiHelperTracer = new PhalApi_Helper_Tracer();
    }
 
    protected function tearDown()
    {
        DI()->debug = true;
    }
 
 
    /**
     * @group testMark
     */ 
    public function testMark()
    {
        $tag = '';
 
        $this->phalApiHelperTracer->mark($tag);
        $this->phalApiHelperTracer->mark('aHa~');
    }
 
    /**
     * @group testGetReport
     */ 
    public function testGetReport()
    {
        $rs = $this->phalApiHelperTracer->getStack();
 
        $this->assertTrue(is_array($rs));
    }
 
    public function testMixed()
    {
        $this->phalApiHelperTracer->mark('aHa~');
        $this->phalApiHelperTracer->mark('BIU~');
        $this->phalApiHelperTracer->mark('BlaBla~');
 
        doSthForTrace($this->phalApiHelperTracer);
 
        $report = $this->phalApiHelperTracer->getStack();
        //var_dump($report);
        $this->assertCount(4, $report);
    }
 
    public function testNoDebug()
    {
        DI()->debug = false;
 
        $tracer = new PhalApi_Helper_Tracer();
        $tracer->mark('aHa~');
 
        $report = $tracer->getStack();
        $this->assertCount(0, $report);
    }
 
    public function testSql()
    {
        $this->phalApiHelperTracer->sql('SELECT');
        $this->phalApiHelperTracer->sql('DELETE');
 
        $this->assertCount(2, $this->phalApiHelperTracer->getSqls());
    }
}
 
function doSthForTrace($tracer) {
    $tracer->mark('IN_FUNCTION');
}