Skip to content

Commit

Permalink
compatibility with PHP 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Nov 29, 2020
1 parent d3bb9f4 commit 458bb14
Show file tree
Hide file tree
Showing 22 changed files with 42 additions and 103 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ php:
- 7.2
- 7.3
- 7.4
- 8.0snapshot

env:
- PHP_BIN=php
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ composer require tracy/tracy
Alternatively, you can download the whole package or [tracy.phar](https://github.com/nette/tester/releases) file.

| Tracy | PHP | compatible with browsers
|-----------|---------------|----------
| Tracy 2.6 | PHP 7.1 – 7.4 | Chrome 49+, Firefox 45+, MS Edge 14+, Safari 10+ and iOS Safari 10.2+
|-----------|-----------------|----------
| Tracy 2.6 | PHP 7.1 – 8.0 | Chrome 49+, Firefox 45+, MS Edge 14+, Safari 10+ and iOS Safari 10.2+
| Tracy 2.5 | PHP 5.4.4 – 7.3 | Chrome 49+, Firefox 45+, MS Edge 12+, Safari 10+ and iOS Safari 10.2+
| Tracy 2.4 | PHP 5.4.4 – 7.2 | Chrome 29+, Firefox 28+, IE 11+ (except AJAX), MS Edge 12+, Safari 9+ and iOS Safari 9.2+

Expand Down
8 changes: 4 additions & 4 deletions src/Tracy/Helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public static function getSource(): string
. $_SERVER['REQUEST_URI'];
} else {
return 'CLI (PID: ' . getmypid() . ')'
. ': ' . implode(' ', array_map([self::class, 'escapeArg'], $_SERVER['argv']));
. (isset($_SERVER['argv']) ? ': ' . implode(' ', array_map([self::class, 'escapeArg'], $_SERVER['argv'])) : '');
}
}

Expand All @@ -188,7 +188,7 @@ public static function improveException(\Throwable $e): void
$message .= ", did you mean $hint()?";
$replace = ["$m[2](", "$hint("];

} elseif (preg_match('#^Undefined variable: (\w+)#', $message, $m) && !empty($e->context)) {
} elseif (preg_match('#^Undefined variable:? \$?(\w+)#', $message, $m) && !empty($e->context)) {
$hint = self::getSuggestion(array_keys($e->context), $m[1]);
$message = "Undefined variable $$m[1], did you mean $$hint?";
$replace = ["$$m[1]", "$$hint"];
Expand All @@ -200,7 +200,7 @@ public static function improveException(\Throwable $e): void
$message .= ", did you mean $$hint?";
$replace = ["->$m[2]", "->$hint"];

} elseif (preg_match('#^Access to undeclared static property: ([\w\\\\]+)::\$(\w+)#', $message, $m)) {
} elseif (preg_match('#^Access to undeclared static property:? ([\w\\\\]+)::\$(\w+)#', $message, $m)) {
$rc = new \ReflectionClass($m[1]);
$items = array_intersect($rc->getProperties(\ReflectionProperty::IS_PUBLIC), $rc->getProperties(\ReflectionProperty::IS_STATIC));
$hint = self::getSuggestion($items, $m[2]);
Expand All @@ -223,7 +223,7 @@ public static function improveException(\Throwable $e): void
/** @internal */
public static function improveError(string $message, array $context = []): string
{
if (preg_match('#^Undefined variable: (\w+)#', $message, $m) && $context) {
if (preg_match('#^Undefined variable:? \$?(\w+)#', $message, $m) && $context) {
$hint = self::getSuggestion(array_keys($context), $m[1]);
return $hint ? "Undefined variable $$m[1], did you mean $$hint?" : $message;

Expand Down
1 change: 1 addition & 0 deletions tests/Tracy/Debugger.autoloading.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
/**
* Test: Tracy\Debugger autoloading.
* @outputMatch %A%: Declaration of B::test(%a?%) should be compatible %a% A::test() in %A%
* @phpVersion < 8
*/

declare(strict_types=1);
Expand Down
2 changes: 1 addition & 1 deletion tests/Tracy/Debugger.exception.html.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ function third($arg1)


define('MY_CONST', 123);
echo @$undefined;
@hex2bin('a'); // E_WARNING
first(10, 'any string');
2 changes: 1 addition & 1 deletion tests/Tracy/Debugger.logSeverity.E_NOTICE.development.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ require __DIR__ . '/../bootstrap.php';
Debugger::enable(Debugger::DEVELOPMENT, getTempDir());
Debugger::$logSeverity = E_NOTICE;

$variable = $missingVariable;
$variable = &pi();

Assert::count(0, glob(getTempDir() . '/exception*.html'));
Assert::count(0, glob(getTempDir() . '/error.log'));
4 changes: 2 additions & 2 deletions tests/Tracy/Debugger.logSeverity.E_NOTICE.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ require __DIR__ . '/../bootstrap.php';
Debugger::enable(Debugger::PRODUCTION, getTempDir());
Debugger::$logSeverity = E_NOTICE;

$variable = $missingVariable;
$variable = &pi();

Assert::same('Undefined variable: missingVariable', error_get_last()['message']);
Assert::same('Only variables should be assigned by reference', error_get_last()['message']);

Assert::count(1, glob(getTempDir() . '/exception*.html'));
Assert::count(1, glob(getTempDir() . '/error.log'));
4 changes: 2 additions & 2 deletions tests/Tracy/Debugger.logging.warnings.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Debugger::enable(Debugger::PRODUCTION, $logDirectory, '[email protected]');


// throw error
$a++;
hex2bin('a'); // E_WARNING

Assert::match('%a%PHP Notice: Undefined variable: a in %a%', file_get_contents($logDirectory . '/error.log'));
Assert::match('%a%PHP Warning: hex2bin(): Hexadecimal input string must have an even length in %a%', file_get_contents($logDirectory . '/error.log'));
Assert::true(is_file($logDirectory . '/email-sent'));
5 changes: 2 additions & 3 deletions tests/Tracy/Debugger.scream.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ header('Content-Type: text/plain; charset=utf-8');

Debugger::enable();

@mktime(); // E_DEPRECATED
@$x++; // E_NOTICE
@min(1); // E_WARNING
@$x = &pi(); // E_NOTICE
@hex2bin('a'); // E_WARNING
@require __DIR__ . '/fixtures/E_COMPILE_WARNING.php'; // E_COMPILE_WARNING (not working)
5 changes: 2 additions & 3 deletions tests/Tracy/Debugger.shut-up.warnings.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ header('Content-Type: text/plain; charset=utf-8');

Debugger::enable();

@mktime(); // E_DEPRECATED
@$x++; // E_NOTICE
@min(1); // E_WARNING
@$x = &pi(); // E_NOTICE
@hex2bin('a'); // E_WARNING
@require __DIR__ . '/fixtures/E_COMPILE_WARNING.php'; // E_COMPILE_WARNING
2 changes: 1 addition & 1 deletion tests/Tracy/Debugger.strict.console.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ function second($arg1, $arg2)

function third($arg1)
{
$x++;
$x = &pi();
}


Expand Down
2 changes: 1 addition & 1 deletion tests/Tracy/Debugger.strict.html.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function second($arg1, $arg2)

function third($arg1)
{
$x++;
$x = &pi();
}


Expand Down
11 changes: 4 additions & 7 deletions tests/Tracy/Debugger.warnings.console.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,17 @@ function second($arg1, $arg2)

function third($arg1)
{
mktime(); // E_DEPRECATED
$x++; // E_NOTICE
min(1); // E_WARNING
$x = &pi(); // E_NOTICE
hex2bin('a'); // E_WARNING
require __DIR__ . '/fixtures/E_COMPILE_WARNING.php'; // E_COMPILE_WARNING
}


first(10, 'any string');
Assert::match("
Deprecated: mktime(): You should be using the time() function instead in %a% on line %d%
Notice: Only variables should be assigned by reference in %a% on line %d%
Notice: Undefined variable: x in %a% on line %d%
Warning: %a% in %a% on line %d%
Warning: hex2bin(): Hexadecimal input string must have an even length in %a% on line %d%
Warning: Unsupported declare 'foo' in %a% on line %d%
", ob_get_clean());
13 changes: 4 additions & 9 deletions tests/Tracy/Debugger.warnings.html.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,11 @@ Warning: Unsupported declare \'foo\' in %a% on line %d%%A%', $output);
Assert::match('%A%<table class="tracy-sortable">
<tr>
<td class="tracy-right">1%a%</td>
<td><pre>PHP Deprecated: mktime(): You should be using the time() function instead in %a%:%d%</a></pre></td>
<td><pre>PHP Notice: Only variables should be assigned by reference in %a%:%d%</a></pre></td>
</tr>
<tr>
<td class="tracy-right">1%a%</td>
<td><pre>PHP Notice: Undefined variable: x in %a%:%d%</a></pre></td>
</tr>
<tr>
<td class="tracy-right">1%a%</td>
<td><pre>PHP Warning: %a% in %a%:%d%</a></pre></td>
<td><pre>PHP Warning: hex2bin(): Hexadecimal input string must have an even length in %a%:%d%</a></pre></td>
</tr>
</table>
</div>%A%', $panelContent);
Expand All @@ -66,9 +62,8 @@ function second($arg1, $arg2)

function third($arg1)
{
mktime(); // E_DEPRECATED
$x++; // E_NOTICE
min(1); // E_WARNING
$x = &pi(); // E_NOTICE
hex2bin('a'); // E_WARNING
require __DIR__ . '/fixtures/E_COMPILE_WARNING.php'; // E_COMPILE_WARNING
}

Expand Down
5 changes: 2 additions & 3 deletions tests/Tracy/Debugger.warnings.production.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ Debugger::$productionMode = true;

Debugger::enable();

mktime(); // E_DEPRECATED
$x++; // E_NOTICE
min(1); // E_WARNING
$x = &pi(); // E_NOTICE
hex2bin('a'); // E_WARNING
require __DIR__ . '/fixtures/E_COMPILE_WARNING.php'; // E_COMPILE_WARNING
4 changes: 2 additions & 2 deletions tests/Tracy/Helpers.improveException.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ test(function () use ($obj) { // suggest only static property
} catch (\Error $e) {
}
Helpers::improveException($e);
Assert::same('Access to undeclared static property: TestClass::$publicStaticX, did you mean $publicStatic?', $e->getMessage());
Assert::match('Access to undeclared static property%a?% TestClass::$publicStaticX, did you mean $publicStatic?', $e->getMessage());
Assert::match('editor://fix/?file=%a%Helpers.improveException.phpt&line=%d%&search=%3A%3A%24publicStaticX&replace=%3A%3A%24publicStatic', $e->tracyAction['link']);
Assert::same('fix it', $e->tracyAction['label']);
});
Expand All @@ -184,7 +184,7 @@ test(function () use ($obj) { // suggest only public static property
} catch (\Error $e) {
}
Helpers::improveException($e);
Assert::same('Access to undeclared static property: TestClass::$protectedMethodX', $e->getMessage());
Assert::match('Access to undeclared static property%a?% TestClass::$protectedMethodX', $e->getMessage());
Assert::false(isset($e->tracyAction));
});

Expand Down
21 changes: 0 additions & 21 deletions tests/Tracy/PHP.errorHandler.phpt

This file was deleted.

20 changes: 2 additions & 18 deletions tests/Tracy/expected/Debugger.error-in-eval.expect
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<tr><th>$message</th><td><pre class="tracy-dump"><span class="tracy-dump-string">"The my error"</span> (%d%)
</pre>
</td></tr>
<tr><th>$error_type</th><td><pre class="tracy-dump"><span class="tracy-dump-number">256</span>
<tr><th>$error_%a%</th><td><pre class="tracy-dump"><span class="tracy-dump-number">256</span>
</pre>
</td></tr>
</table>
Expand Down Expand Up @@ -99,23 +99,7 @@
</li>
</ol>
</div></div>


<div class="panel">
<h2><a data-tracy-ref="^+" class="tracy-toggle tracy-collapsed">Variables</a></h2>

<div class="tracy-collapsed inner">
<div class="outer">
<table class="tracy-sortable">
<tr><th>$user</th><td><pre class="tracy-dump"><span class="tracy-dump-string">"root"</span> (4)
</pre>
</td></tr>
<tr><th>$pass</th><td><pre class="tracy-dump"><span class="tracy-dump-string">"*****"</span> (5)
</pre>
</td></tr>
</table>
</div>
</div></div>
%A%



Expand Down
2 changes: 1 addition & 1 deletion tests/Tracy/expected/Debugger.exception.html.expect
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
<h2><a data-tracy-ref="^+" class="tracy-toggle tracy-collapsed">Last muted error</a></h2>
<div class="tracy-collapsed inner">

<h3>Notice: Undefined variable: undefined</h3>
<h3>Warning: hex2bin(): Hexadecimal input string must have an even length</h3>
<p><a href="editor:%a%" title="%a%Debugger.exception.html.phpt:%d%">%a%<b>Debugger.exception.html.phpt</b>:%d%</a></p>
<div>%A%</div>

Expand Down
6 changes: 2 additions & 4 deletions tests/Tracy/expected/Debugger.scream.expect
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

Deprecated: mktime(): You should be using the time() function instead in %a% on line %d%
Notice: Only variables should be assigned by reference in %a% on line %d%

Notice: Undefined variable: x in %a% on line %d%

Warning: %a% in %a% on line %d%
Warning: hex2bin(): Hexadecimal input string must have an even length in %a% on line %d%
4 changes: 2 additions & 2 deletions tests/Tracy/expected/Debugger.strict.console.expect
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ErrorException: Undefined variable: x in %a%
ErrorException: Only variables should be assigned by reference in %a%
Stack trace:
#0 %a%: Tracy\Debugger::errorHandler(8, '%a%', '%a%', %a%, Array)
#0 %a%: Tracy\Debugger::errorHandler(8, '%a%', '%a%', %a%)
#1 %a%: third(Array)
#2 %a%: second(true, false)
#3 %a%: first(10, 'any string')
Expand Down
19 changes: 3 additions & 16 deletions tests/Tracy/expected/Debugger.strict.html.expect
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<meta name="robots" content="noindex">
<meta name="generator" content="Tracy by Nette Framework">

<title>Notice: Undefined variable: x</title>
<title>Notice: Only variables should be assigned by reference</title>
<!-- in %a%:%d% -->

%A%
Expand All @@ -19,7 +19,7 @@
<div id="tracy-bs-error" class="panel">
<p>Notice</p>

<h1><span>Undefined variable: x</span>
<h1><span>Only variables should be assigned by reference</span>
<a href="%a%" target="_blank" rel="noreferrer noopener">search&#x25ba;</a>
</h1>
</div>
Expand Down Expand Up @@ -106,20 +106,7 @@
</li>
</ol>
</div></div>


<div class="panel">
<h2><a data-tracy-ref="^+" class="tracy-toggle tracy-collapsed">Variables</a></h2>

<div class="tracy-collapsed inner">
<div class="outer">
<table class="tracy-sortable">
<tr><th>$arg1</th><td><pre class="tracy-dump" data-tracy-dump='[[0,1],[1,2],[2,3]]'></pre>
</td></tr>%A?%
</table>
</div>
</div></div>

%A%


<div class="panel">
Expand Down

0 comments on commit 458bb14

Please sign in to comment.