1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Axstrad library. |
4
|
|
|
* |
5
|
|
|
* (c) Dan Kempster <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
* |
10
|
|
|
* @copyright 2014-2015 Dan Kempster <[email protected]> |
11
|
|
|
*/ |
12
|
|
|
namespace Axstrad\Common\Tests\Util; |
13
|
|
|
|
14
|
|
|
use Axstrad\Common\Util\Debug; |
15
|
|
|
use Doctrine\Common\Util\Debug as DoctrineDebug; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Axstrad\Common\Tests\Util\DebugUtilTest |
20
|
|
|
*/ |
21
|
|
|
class DebugUtilTest extends \PHPUnit_Framework_TestCase |
22
|
|
|
{ |
23
|
|
|
public function testSummariseUsesDoctrineDebugWhenVarIsObject() |
24
|
|
|
{ |
25
|
|
|
$obj = new self; |
26
|
|
|
$this->assertEquals( |
27
|
|
|
DoctrineDebug::toString($obj), |
28
|
|
|
Debug::summarise($obj) |
29
|
|
|
); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function testSummariseReturnsIntergersAsSrings() |
33
|
|
|
{ |
34
|
|
|
$this->assertSame( |
35
|
|
|
'100', |
36
|
|
|
Debug::summarise(100) |
37
|
|
|
); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function testSummariseReturnsFloatsAsSrings() |
41
|
|
|
{ |
42
|
|
|
$this->assertSame( |
43
|
|
|
'10.1', |
44
|
|
|
Debug::summarise(10.1) |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
public function testSummariseReturnsBooleansAsStrings() |
49
|
|
|
{ |
50
|
|
|
$this->assertEquals( |
51
|
|
|
'True', |
52
|
|
|
Debug::summarise(true) |
53
|
|
|
); |
54
|
|
|
$this->assertEquals( |
55
|
|
|
'False', |
56
|
|
|
Debug::summarise(false) |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testSummariseTruncatsStringsWithAnEllipse() |
61
|
|
|
{ |
62
|
|
|
Debug::$options['varDump']['string']['max'] = 10; |
63
|
|
|
|
64
|
|
|
$this->assertEquals( |
65
|
|
|
'"Hello Worl..."', |
66
|
|
|
Debug::summarise('Hello World') |
67
|
|
|
); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function testSummarisReturnsEmptyArrayAsString() |
71
|
|
|
{ |
72
|
|
|
$this->assertEquals( |
73
|
|
|
"Array(0){}", |
74
|
|
|
Debug::summarise(array()) |
75
|
|
|
); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function testSummarisReturnsArrayAsStringWithFirstValue() |
79
|
|
|
{ |
80
|
|
|
$this->assertEquals( |
81
|
|
|
"Array(1){100}", |
82
|
|
|
Debug::summarise(array(100)) |
83
|
|
|
); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function testSummarisReturnsArrayAsStringWithFirstHashAndValue() |
87
|
|
|
{ |
88
|
|
|
$this->assertEquals( |
89
|
|
|
"Array(1){foo: 100}", |
90
|
|
|
Debug::summarise(array('foo' => 100)) |
91
|
|
|
); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
public function testSummarisReturnsMultidimentionalArrayAsStringWithFirstValue() |
95
|
|
|
{ |
96
|
|
|
$this->assertEquals( |
97
|
|
|
"Array(1){Array(2)}", |
98
|
|
|
Debug::summarise(array(array('foo', 'bar'))) |
99
|
|
|
); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
public function testSummarisReturnsNullAsString() |
103
|
|
|
{ |
104
|
|
|
$this->assertEquals( |
105
|
|
|
"Null", |
106
|
|
|
Debug::summarise(null) |
107
|
|
|
); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function testDumpResetsXdebugVarDisplayMaxDepthSettingToOriginal() |
111
|
|
|
{ |
112
|
|
|
if (!extension_loaded('xdebug')) { |
113
|
|
|
$this->markTestSkipped('XDebug extension is not loaded/installed'); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
$original = ini_set('xdebug.var_display_max_depth', 5); |
117
|
|
|
ob_start(); |
118
|
|
|
Debug::dump(new self, 2); |
119
|
|
|
ob_end_clean(); |
120
|
|
|
$this->assertEquals( |
121
|
|
|
5, |
122
|
|
|
ini_set('xdebug.var_display_max_depth', $original) |
123
|
|
|
); |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
|