Completed
Pull Request — 5.1 (#1327)
by
unknown
05:23
created

debugTest::testDump()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 4
eloc 12
nc 4
nop 0
dl 0
loc 16
rs 9.8666
c 0
b 0
f 0
1
<?php
2
// +----------------------------------------------------------------------
1 ignored issue
show
Coding Style introduced by
You must use "/**" style comments for a file comment
Loading history...
3
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
4
// +----------------------------------------------------------------------
5
// | Copyright (c) 2006~2016 http://thinkphp.cn All rights reserved.
6
// +----------------------------------------------------------------------
7
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
8
// +----------------------------------------------------------------------
9
// | Author: liu21st <[email protected]>
10
// +----------------------------------------------------------------------
11
12
/**
13
 * Debug测试
14
 * @author    大漠 <[email protected]>
1 ignored issue
show
Coding Style introduced by
Tag value indented incorrectly; expected 1 spaces but found 4
Loading history...
15
 */
16
17
namespace tests\thinkphp\library\think;
18
19
use tests\thinkphp\library\think\config\ConfigInitTrait;
20
use think\Config;
0 ignored issues
show
Bug introduced by
The type think\Config was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
use think\Debug;
0 ignored issues
show
Bug introduced by
The type think\Debug was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
use think\Response;
0 ignored issues
show
Bug introduced by
The type think\Response was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
use think\response\Redirect;
0 ignored issues
show
Bug introduced by
The type think\response\Redirect was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
25
class debugTest extends \PHPUnit_Framework_TestCase
1 ignored issue
show
Bug introduced by
The type PHPUnit_Framework_TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Coding Style introduced by
Missing class doc comment
Loading history...
Coding Style introduced by
Class name must begin with a capital letter
Loading history...
26
{
27
    use ConfigInitTrait;
28
29
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
30
     *
31
     * @var Debug
32
     */
33
    protected $object;
34
35
    /**
36
     * Sets up the fixture, for example, opens a network connection.
37
     * This method is called before a test is executed.
38
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
39
    protected function setUp()
40
    {
41
        $this->object = new Debug();
42
    }
43
44
    /**
45
     * Tears down the fixture, for example, closes a network connection.
46
     * This method is called after a test is executed.
47
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
48
    protected function tearDown()
49
    {}
0 ignored issues
show
Coding Style introduced by
Closing brace must be on a line by itself
Loading history...
50
51
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
52
     * @covers \think\Debug::remark
53
     * @todo Implement testRemark().
54
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
55
    public function testRemark()
56
    {
57
        $name = "testremarkkey";
58
        Debug::remark($name);
59
    }
60
61
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
62
     * @covers \think\Debug::getRangeTime
63
     * @todo Implement testGetRangeTime().
64
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
65
    public function testGetRangeTime()
66
    {
67
        $start = "testGetRangeTimeStart";
68
        $end   = "testGetRangeTimeEnd";
69
        Debug::remark($start);
70
        usleep(20000);
71
        // \think\Debug::remark($end);
72
73
        $time = Debug::getRangeTime($start, $end);
74
        $this->assertLessThan(0.03, $time);
75
        //$this->assertEquals(0.03, ceil($time));
76
    }
77
78
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
79
     * @covers \think\Debug::getUseTime
80
     * @todo Implement testGetUseTime().
81
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
82
    public function testGetUseTime()
83
    {
84
        $time = Debug::getUseTime();
85
        $this->assertLessThan(30, $time);
86
    }
87
88
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
89
     * @covers \think\Debug::getThroughputRate
90
     * @todo Implement testGetThroughputRate().
91
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
92
    public function testGetThroughputRate()
93
    {
94
        usleep(100000);
95
        $throughputRate = Debug::getThroughputRate();
96
        $this->assertLessThan(10, $throughputRate);
97
    }
98
99
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
100
     * @covers \think\Debug::getRangeMem
101
     * @todo Implement testGetRangeMem().
102
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
103
    public function testGetRangeMem()
104
    {
105
        $start = "testGetRangeMemStart";
106
        $end   = "testGetRangeMemEnd";
107
        Debug::remark($start);
108
        $str = "";
109
        for ($i = 0; $i < 10000; $i++) {
110
            $str .= "mem";
111
        }
112
113
        $rangeMem = Debug::getRangeMem($start, $end);
114
115
        $this->assertLessThan(33, explode(" ", $rangeMem)[0]);
116
    }
117
118
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
119
     * @covers \think\Debug::getUseMem
120
     * @todo Implement testGetUseMem().
121
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
122
    public function testGetUseMem()
123
    {
124
        $useMem = Debug::getUseMem();
125
126
        $this->assertLessThan(35, explode(" ", $useMem)[0]);
127
    }
128
129
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
130
     * @covers \think\Debug::getMemPeak
131
     * @todo Implement testGetMemPeak().
132
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
133
    public function testGetMemPeak()
134
    {
135
        $start = "testGetMemPeakStart";
136
        $end   = "testGetMemPeakEnd";
137
        Debug::remark($start);
138
        $str = "";
139
        for ($i = 0; $i < 100000; $i++) {
140
            $str .= "mem";
141
        }
142
        $memPeak = Debug::getMemPeak($start, $end);
143
        $this->assertLessThan(500, explode(" ", $memPeak)[0]);
144
    }
145
146
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
147
     * @covers \think\Debug::getFile
148
     * @todo Implement testGetFile().
149
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
150
    public function testGetFile()
151
    {
152
        $count = Debug::getFile();
153
154
        $this->assertEquals(count(get_included_files()), $count);
155
156
        $info = Debug::getFile(true);
157
        $this->assertEquals(count(get_included_files()), count($info));
158
159
        $this->assertContains("KB", $info[0]);
160
    }
161
162
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
163
     * @covers \think\Debug::dump
164
     * @todo Implement testDump().
165
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
166
    public function testDump()
167
    {
168
        if (strstr(PHP_VERSION, 'hhvm')) {
169
            return;
170
        }
171
172
        $var        = [];
173
        $var["key"] = "val";
174
        $output     = Debug::dump($var, false, $label = "label");
175
        $array      = explode("array", json_encode($output));
176
        if (IS_WIN) {
0 ignored issues
show
Bug introduced by
The constant tests\thinkphp\library\think\IS_WIN was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
177
            $this->assertEquals("(1) {\\n  [\\\"key\\\"] => string(3) \\\"val\\\"\\n}\\n\\r\\n\"", end($array));
178
        } elseif (strstr(PHP_OS, 'Darwin')) {
179
            $this->assertEquals("(1) {\\n  [\\\"key\\\"] => string(3) \\\"val\\\"\\n}\\n\\n\"", end($array));
180
        } else {
181
            $this->assertEquals("(1) {\\n  'key' =>\\n  string(3) \\\"val\\\"\\n}\\n\\n\"", end($array));
182
        }
183
    }
184
185
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
186
     * @expectedException \think\exception\ClassNotFoundException
187
     */
0 ignored issues
show
Coding Style introduced by
Missing @return tag in function comment
Loading history...
188
    public function testInjectWithErrorType()
189
    {
190
        Config::set('trace', ['type' => 'NullDebug']);
191
192
        $response = new Response();
193
        $context  = 'TestWithErrorType';
194
195
        Debug::inject($response, $context);
196
    }
197
198
    public function testInject()
0 ignored issues
show
Coding Style introduced by
Missing function doc comment
Loading history...
199
    {
200
        Config::set('trace', ['type' => 'Console']);
201
202
        $response = new Response();
203
        $context  = 'TestWithoutBodyTag';
204
        Debug::inject($response, $context);
205
        $this->assertNotEquals('TestWithoutBodyTag', $context);
206
        $this->assertStringStartsWith('TestWithoutBodyTag', $context);
207
208
        $response = new Response();
209
        $context  = '<body></body>';
210
        Debug::inject($response, $context);
211
        $this->assertNotEquals('<body></body>', $context);
212
        $this->assertStringStartsWith('<body>', $context);
213
        $this->assertStringEndsWith('</body>', $context);
214
215
        $response = new Redirect();
216
        $context  = '<body></body>';
217
        Debug::inject($response, $context);
218
        $this->assertEquals('<body></body>', $context);
219
    }
220
}
221