Skip to content

Commit

Permalink
Merge pull request #75 from phug-php/feature/check-php-8
Browse files Browse the repository at this point in the history
Fix unit test compatibility with PHP 8
  • Loading branch information
kylekatarnls committed Sep 17, 2020
2 parents a6cd174 + 9043e32 commit 163ed88
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 19 deletions.
6 changes: 3 additions & 3 deletions tests/Phug/FormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ public function testDebugError()
$document->appendChild($htmlEl = new MarkupElement('html'));
$htmlEl->appendChild($bodyEl = new MarkupElement('body'));
$bodyEl->appendChild(new ExpressionElement(
'12 / 0',
'trigger_error("Division by zero")',
$node
));
$php = $formatter->format($document);
Expand All @@ -1196,7 +1196,7 @@ public function testDebugError()
'debug' => true,
]);
$helper = function () {
return 12 / 0;
trigger_error('Division by zero');
};
$node = new ExpressionNode(null, new SourceLocation(null, 7, 9));
$document = new DocumentElement();
Expand Down Expand Up @@ -1340,7 +1340,7 @@ public function testDebugErrorOnRemovedFile()
$document->appendChild($htmlEl = new MarkupElement('html'));
$htmlEl->appendChild($bodyEl = new MarkupElement('body'));
$bodyEl->appendChild(new ExpressionElement(
'12 / 0',
'trigger_error("Division by zero")',
$node
));
$php = $formatter->format($document);
Expand Down
12 changes: 6 additions & 6 deletions tests/Phug/RendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ public function testHandleErrorInString()
$message = null;

try {
$renderer->render('div: p=12/0');
$renderer->render('div: p=trigger_error("Division by zero")');
} catch (\Exception $error) {
$message = $error->getMessage();
}
Expand All @@ -479,15 +479,15 @@ public function testHandleErrorInString()
);

self::assertNotContains(
'12/0',
'trigger_error("Division'.'by'.'zero")',
str_replace(' ', '', $message)
);

$message = null;
$renderer->setOption('debug', true);

try {
$renderer->render('div: p=12/0');
$renderer->render('div: p=trigger_error("Division by zero")');
} catch (RendererException $error) {
$message = $error->getMessage();
}
Expand All @@ -498,15 +498,15 @@ public function testHandleErrorInString()
);

self::assertContains(
'12/0',
'trigger_error("Division'.'by'.'zero")',
str_replace(' ', '', $message)
);

$message = null;
$renderer->setOption('color_support', true);

try {
$renderer->render('div: p=12/0');
$renderer->render('div: p=trigger_error("Division by zero")');
} catch (RendererException $error) {
$message = $error->getMessage();
}
Expand All @@ -517,7 +517,7 @@ public function testHandleErrorInString()
);

self::assertContains(
"\033[43;30m> 1 | div: p\033[43;31m=\033[43;30m12/0\e[0m\n",
"\033[43;30m> 1 | div: p\033[43;31m=\033[43;30mtrigger_error(\"Division by zero\")\e[0m\n",
$message
);
}
Expand Down
15 changes: 5 additions & 10 deletions tests/Phug/Util/SandBoxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function testError()
{
$sandBox = new SandBox(function () {
echo 'foo';
$a = 5 / 0;
$a = trigger_error('Division by zero');
echo 'bar';

return $a;
Expand Down Expand Up @@ -89,29 +89,24 @@ public function testError()

self::assertInstanceOf(ErrorException::class, $sandBox->getThrowable());

$undefinedOffsetSeverity = version_compare(PHP_VERSION, '8.0.0-dev', '<')
? E_NOTICE
: E_WARNING;
error_reporting(E_ALL ^ $undefinedOffsetSeverity);
error_reporting(E_ALL ^ E_USER_NOTICE);

$sandBox = new SandBox(function () {
$a = [];
$b = $a['foo'];
trigger_error('Undefined index');
});

self::assertNull($sandBox->getThrowable());

error_reporting(E_ALL);

$sandBox = new SandBox(function () {
$a = [];
$b = $a['foo'];
trigger_error('Undefined index');
}, function ($number, $message, $file, $line) {
throw new ErrorException('interceptor', $number);
});

self::assertSame('interceptor', $sandBox->getThrowable()->getMessage());
self::assertSame($undefinedOffsetSeverity, $sandBox->getThrowable()->getCode());
self::assertSame(E_USER_NOTICE, $sandBox->getThrowable()->getCode());

error_reporting($level);
}
Expand Down

0 comments on commit 163ed88

Please sign in to comment.