Browse Source

Merge pull request #6600 from cakephp/master-debuginfo

Add __debugInfo() to common class types
Mark Story 10 years ago
parent
commit
77017c6b32

+ 19 - 0
src/Console/Shell.php

@@ -666,4 +666,23 @@ class Shell
     {
         exit($status);
     }
+
+    /**
+     * Returns an array that can be used to describe the internal state of this
+     * object.
+     *
+     * @return array
+     */
+    public function __debugInfo()
+    {
+        return [
+            'name' => $this->name,
+            'plugin' => $this->plugin,
+            'command' => $this->command,
+            'tasks' => $this->tasks,
+            'params' => $this->params,
+            'args' => $this->args,
+            'interactive' => $this->interactive,
+        ];
+    }
 }

+ 15 - 0
src/Controller/Component.php

@@ -180,4 +180,19 @@ class Component implements EventListenerInterface
         }
         return $events;
     }
+
+    /**
+     * Returns an array that can be used to describe the internal state of this
+     * object.
+     *
+     * @return array
+     */
+    public function __debugInfo()
+    {
+        return [
+            'components' => $this->components,
+            'implementedEvents' => $this->implementedEvents(),
+            '_config' => $this->config(),
+        ];
+    }
 }

+ 19 - 0
src/View/Helper.php

@@ -219,4 +219,23 @@ class Helper implements EventListenerInterface
         }
         return $events;
     }
+
+    /**
+     * Returns an array that can be used to describe the internal state of this
+     * object.
+     *
+     * @return array
+     */
+    public function __debugInfo()
+    {
+        return [
+            'helpers' => $this->helpers,
+            'theme' => $this->theme,
+            'plugin' => $this->plugin,
+            'fieldset' => $this->fieldset,
+            'tags' => $this->tags,
+            'implementedEvents' => $this->implementedEvents(),
+            '_config' => $this->config(),
+        ];
+    }
 }

+ 25 - 5
tests/TestCase/Console/ShellTest.php

@@ -501,7 +501,7 @@ class ShellTest extends TestCase
         $this->assertTextEquals($contents, file_get_contents($file));
         $this->assertTrue($result, 'Did create file.');
     }
-    
+
     /**
      * Test that there is no user prompt in non-interactive mode while file already exists.
      *
@@ -511,14 +511,14 @@ class ShellTest extends TestCase
     {
         $path = TMP . 'shell_test';
         $file = $path . DS . 'file1.php';
-        
+
         new Folder($path, true);
-        
+
         touch($file);
         $this->assertTrue(file_exists($file));
-        
+
         $this->io->expects($this->never())->method('askChoice');
-        
+
         $this->Shell->interactive = false;
         $result = $this->Shell->createFile($file, 'My content');
         $this->assertTrue($result);
@@ -966,4 +966,24 @@ TEXT;
         $this->Shell = $this->getMock(__NAMESPACE__ . '\ShellTestShell', ['_useLogger'], [$io]);
         $this->Shell->runCommand(['foo', '--quiet']);
     }
+
+    /**
+     * Tests __debugInfo
+     *
+     * @return void
+     */
+    public function testDebugInfo()
+    {
+        $expected = [
+            'name' => 'ShellTestShell',
+            'plugin' => null,
+            'command' => null,
+            'tasks' => [],
+            'params' => [],
+            'args' => [],
+            'interactive' => true
+        ];
+        $result = $this->Shell->__debugInfo();
+        $this->assertEquals($expected, $result);
+    }
 }

+ 23 - 0
tests/TestCase/Controller/ComponentTest.php

@@ -145,4 +145,27 @@ class ComponentTest extends TestCase
         $this->assertInstanceOf('TestApp\Controller\Component\SomethingWithCookieComponent', $Controller->SomethingWithCookie);
         $this->assertInstanceOf('Cake\Controller\Component\CookieComponent', $Controller->SomethingWithCookie->Cookie);
     }
+
+    /**
+     * Tests __debugInfo
+     *
+     * @return void
+     */
+    public function testDebugInfo()
+    {
+        $Collection = new ComponentRegistry();
+        $Component = new AppleComponent($Collection);
+
+        $expected = [
+            'components' => [
+                'Orange'
+            ],
+            'implementedEvents' => [
+                'Controller.startup' => 'startup'
+            ],
+            '_config' => []
+        ];
+        $result = $Component->__debugInfo();
+        $this->assertEquals($expected, $result);
+    }
 }

+ 29 - 0
tests/TestCase/View/HelperTest.php

@@ -161,4 +161,33 @@ class HelperTest extends TestCase
         $resultA->testprop = 1;
         $this->assertEquals($resultA->testprop, $resultB->testprop);
     }
+
+    /**
+     * Tests __debugInfo
+     *
+     * @return void
+     */
+    public function testDebugInfo()
+    {
+        $Helper = new TestHelper($this->View);
+
+        $expected = [
+            'helpers' => [
+                'Html',
+                'TestPlugin.OtherHelper'
+            ],
+            'theme' => null,
+            'plugin' => null,
+            'fieldset' => [],
+            'tags' => [],
+            'implementedEvents' => [
+            ],
+            '_config' => [
+                'key1' => 'val1',
+                'key2' => ['key2.1' => 'val2.1', 'key2.2' => 'val2.2']
+            ]
+        ];
+        $result = $Helper->__debugInfo();
+        $this->assertEquals($expected, $result);
+    }
 }