Browse Source

change stackFrame to 1

saeid 8 years ago
parent
commit
477e7949ec
2 changed files with 29 additions and 4 deletions
  1. 1 1
      src/Core/functions.php
  2. 28 3
      tests/TestCase/Core/FunctionsTest.php

+ 1 - 1
src/Core/functions.php

@@ -258,7 +258,7 @@ if (!function_exists('triggerWarning')) {
      */
     function triggerWarning($message)
     {
-        $stackFrame = 2;
+        $stackFrame = 1;
         $trace = debug_backtrace();
         if (isset($trace[$stackFrame])) {
             $frame = $trace[$stackFrame];

+ 28 - 3
tests/TestCase/Core/FunctionsTest.php

@@ -44,7 +44,7 @@ class FunctionsTest extends TestCase
     }
 
     /**
-     * Test error messages coming out when debug is on, manually setting the stack frame
+     * Test error messages coming out when deprecated level is on, manually setting the stack frame
      *
      * @expectedException PHPUnit\Framework\Error\Deprecated
      * @expectedExceptionMessageRegExp /This is going away - (.*?)[\/\\]FunctionsTest.php, line\: \d+/
@@ -57,7 +57,7 @@ class FunctionsTest extends TestCase
     }
 
     /**
-     * Test error messages coming out when debug is on, not setting the stack frame manually
+     * Test error messages coming out when deprecated level is on, not setting the stack frame manually
      *
      * @expectedException PHPUnit\Framework\Error\Deprecated
      * @expectedExceptionMessageRegExp /This is going away - (.*?)[\/\\]TestCase.php, line\: \d+/
@@ -70,7 +70,7 @@ class FunctionsTest extends TestCase
     }
 
     /**
-     * Test no error when debug is off.
+     * Test no error when deprecated level is off.
      *
      * @return void
      */
@@ -82,6 +82,31 @@ class FunctionsTest extends TestCase
     }
 
     /**
+     * Test error messages coming out when warning level is on.
+     *
+     * @expectedException PHPUnit\Framework\Error\Warning
+     * @expectedExceptionMessageRegExp /This is going away - (.*?)[\/\\]TestCase.php, line\: \d+/
+     */
+    public function testTriggerWarningEnabled()
+    {
+        $this->withErrorReporting(E_ALL, function () {
+            triggerWarning('This is going away');
+        });
+    }
+
+    /**
+     * Test no error when warning level is off.
+     *
+     * @return void
+     */
+    public function testTriggerWarningLevelDisabled()
+    {
+        $this->withErrorReporting(E_ALL ^ E_USER_WARNING, function () {
+            $this->assertNull(triggerWarning('This is going away'));
+        });
+    }
+
+    /**
      * testing getTypeName()
      *
      * @return void