1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* A basic sanity test for Kint. |
4
|
|
|
* |
5
|
|
|
* This bears the dual responsibility of ensuring Kint (at least |
6
|
|
|
* superficially) works on PHP versions too low to support PHPunit/composer, |
7
|
|
|
* and ensuring that Kint works when init is included manually, as opposed |
8
|
|
|
* to autoloaded through composer. |
9
|
|
|
*/ |
10
|
|
|
error_reporting(E_ALL | E_STRICT); |
11
|
|
|
ini_set('display_errors', true); |
12
|
|
|
|
13
|
|
|
$error = false; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* Exits as a failure for any error. |
17
|
|
|
*/ |
18
|
|
|
function error() |
|
|
|
|
19
|
|
|
{ |
20
|
|
|
global $error; |
21
|
|
|
$error = true; |
22
|
|
|
|
23
|
|
|
return false; |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
set_error_handler('error'); |
27
|
|
|
|
28
|
|
|
require dirname(__FILE__).'/../'.getenv('KINT_FILE'); |
29
|
|
|
require dirname(__FILE__).'/../'.getenv('KINT_FILE'); // Double to test include guard |
30
|
|
|
|
31
|
|
|
$testdata = array( |
32
|
|
|
1234, |
33
|
|
|
(object) array('abc' => 'def'), |
34
|
|
|
1234.5678, |
35
|
|
|
'Good news everyone! I\'ve got some bad news!', |
36
|
|
|
null, |
37
|
|
|
); |
38
|
|
|
|
39
|
|
|
$testdata[] = &$testdata; |
40
|
|
|
|
41
|
|
|
$expected = '0.+?integer.+?1234.+?1.+?stdClass.+?1.+?public.+?abc.+?string.+?3.+?def.+?2.+?double.+?1234\\.5678.+?3.+?string.+?43.+?Good news everyone! I\'ve got some bad news!.+?4.+?null.+?5.+?(&|&)array'; |
42
|
|
|
$expected = '/'.$expected.'.+?6.+?'.$expected.'.+RECURSION/si'; |
43
|
|
|
|
44
|
|
|
Kint::$return = true; |
45
|
|
|
|
46
|
|
|
echo 'CLI'.PHP_EOL; |
47
|
|
|
preg_match($expected, d($testdata)) || exit(1); |
48
|
|
|
|
49
|
|
|
Kint::$cli_detection = false; |
50
|
|
|
|
51
|
|
|
echo 'RICH'.PHP_EOL; |
52
|
|
|
$out = array(0 => Kint::dump($testdata)); |
53
|
|
|
preg_match($expected, $out[0]) || exit(1); |
54
|
|
|
echo 'PLAIN'.PHP_EOL; |
55
|
|
|
preg_match($expected, s($testdata)) || exit(1); |
56
|
|
|
echo 'TEXT'.PHP_EOL; |
57
|
|
|
preg_match($expected, ~~d($testdata)) || exit(1); |
58
|
|
|
|
59
|
|
|
if ($error) { |
60
|
|
|
echo 'Errors occurred'.PHP_EOL; |
61
|
|
|
exit(1); |
62
|
|
|
} else { |
63
|
|
|
exit(0); |
64
|
|
|
} |
65
|
|
|
|
This check examines a number of code elements and verifies that they conform to the given naming conventions.
You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.