Browse Source

Add test case for __debugInfo throwing exception

Corey Taylor 4 years ago
parent
commit
bc8cceeb29

+ 13 - 0
tests/TestCase/Error/DebuggerTest.php

@@ -32,6 +32,7 @@ use stdClass;
 use TestApp\Error\TestDebugger;
 use TestApp\Error\Thing\DebuggableThing;
 use TestApp\Error\Thing\SecurityThing;
+use TestApp\Utility\ThrowsDebugInfo;
 
 /**
  * DebuggerTest class
@@ -520,6 +521,18 @@ TEXT;
     }
 
     /**
+     * Test exportVar with an exception during __debugInfo()
+     *
+     * @return void
+     */
+    public function testExportVarInvalidDebugInfo()
+    {
+        $result = Debugger::exportVar(new ThrowsDebugInfo());
+        $expected = '(unable to export object: from __debugInfo)';
+        $this->assertTextEquals($expected, $result);
+    }
+
+    /**
      * Text exportVarAsNodes()
      *
      * @return void

+ 14 - 0
tests/test_app/TestApp/Utility/ThrowsDebugInfo.php

@@ -0,0 +1,14 @@
+<?php
+declare(strict_types=1);
+
+namespace TestApp\Utility;
+
+use Exception;
+
+class ThrowsDebugInfo
+{
+    public function __debugInfo()
+    {
+        throw new Exception('from __debugInfo');
+    }
+}