From e1bc995a47fe8a12c71caec37bf12d9ce262d96e Mon Sep 17 00:00:00 2001 From: KyleKatarn Date: Thu, 17 Sep 2020 21:14:41 +0200 Subject: [PATCH 1/2] Use trigger_error() instead of actual error in tests --- tests/Phug/FormatterTest.php | 6 +++--- tests/Phug/RendererTest.php | 12 ++++++------ tests/Phug/Util/SandBoxTest.php | 9 +++------ 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/tests/Phug/FormatterTest.php b/tests/Phug/FormatterTest.php index 4326d812..f6d3123b 100644 --- a/tests/Phug/FormatterTest.php +++ b/tests/Phug/FormatterTest.php @@ -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); @@ -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(); @@ -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); diff --git a/tests/Phug/RendererTest.php b/tests/Phug/RendererTest.php index e9831c6a..03748bc6 100644 --- a/tests/Phug/RendererTest.php +++ b/tests/Phug/RendererTest.php @@ -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(); } @@ -479,7 +479,7 @@ public function testHandleErrorInString() ); self::assertNotContains( - '12/0', + 'trigger_error("Division'.'by'.'zero")', str_replace(' ', '', $message) ); @@ -487,7 +487,7 @@ public function testHandleErrorInString() $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(); } @@ -498,7 +498,7 @@ public function testHandleErrorInString() ); self::assertContains( - '12/0', + 'trigger_error("Division'.'by'.'zero")', str_replace(' ', '', $message) ); @@ -506,7 +506,7 @@ public function testHandleErrorInString() $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(); } @@ -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 ); } diff --git a/tests/Phug/Util/SandBoxTest.php b/tests/Phug/Util/SandBoxTest.php index 279cbf6d..146e766f 100644 --- a/tests/Phug/Util/SandBoxTest.php +++ b/tests/Phug/Util/SandBoxTest.php @@ -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; @@ -89,10 +89,7 @@ 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_NOTICE); $sandBox = new SandBox(function () { $a = []; @@ -111,7 +108,7 @@ public function testError() }); self::assertSame('interceptor', $sandBox->getThrowable()->getMessage()); - self::assertSame($undefinedOffsetSeverity, $sandBox->getThrowable()->getCode()); + self::assertSame(E_NOTICE, $sandBox->getThrowable()->getCode()); error_reporting($level); } From 9043e3248d85be658bb96292eec7f00995bc5156 Mon Sep 17 00:00:00 2001 From: KyleKatarn Date: Thu, 17 Sep 2020 21:19:27 +0200 Subject: [PATCH 2/2] Fix SandBox test compatibility with PHP 8 --- tests/Phug/Util/SandBoxTest.php | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/tests/Phug/Util/SandBoxTest.php b/tests/Phug/Util/SandBoxTest.php index 146e766f..5e5ab6fe 100644 --- a/tests/Phug/Util/SandBoxTest.php +++ b/tests/Phug/Util/SandBoxTest.php @@ -55,7 +55,7 @@ public function testError() { $sandBox = new SandBox(function () { echo 'foo'; - $a = trigger_error("Division by zero"); + $a = trigger_error('Division by zero'); echo 'bar'; return $a; @@ -89,11 +89,10 @@ public function testError() self::assertInstanceOf(ErrorException::class, $sandBox->getThrowable()); - error_reporting(E_ALL ^ E_NOTICE); + error_reporting(E_ALL ^ E_USER_NOTICE); $sandBox = new SandBox(function () { - $a = []; - $b = $a['foo']; + trigger_error('Undefined index'); }); self::assertNull($sandBox->getThrowable()); @@ -101,14 +100,13 @@ public function testError() 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(E_NOTICE, $sandBox->getThrowable()->getCode()); + self::assertSame(E_USER_NOTICE, $sandBox->getThrowable()->getCode()); error_reporting($level); }