Skip to content

Commit

Permalink
Merge pull request #6600 from cakephp/master-debuginfo
Browse files Browse the repository at this point in the history
Add __debugInfo() to common class types
  • Loading branch information
markstory committed May 20, 2015
2 parents 61e9d23 + 7ae4ca9 commit 77017c6
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 5 deletions.
19 changes: 19 additions & 0 deletions src/Console/Shell.php
Expand Up @@ -666,4 +666,23 @@ protected function _stop($status = 0)
{
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 changes: 15 additions & 0 deletions src/Controller/Component.php
Expand Up @@ -180,4 +180,19 @@ public function implementedEvents()
}
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 changes: 19 additions & 0 deletions src/View/Helper.php
Expand Up @@ -219,4 +219,23 @@ public function implementedEvents()
}
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(),
];
}
}
30 changes: 25 additions & 5 deletions tests/TestCase/Console/ShellTest.php
Expand Up @@ -501,7 +501,7 @@ public function testCreateFileOverwrite()
$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.
*
Expand All @@ -511,14 +511,14 @@ public function testCreateFileOverwriteNonInteractive()
{
$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);
Expand Down Expand Up @@ -966,4 +966,24 @@ public function testQuietLog()
$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 changes: 23 additions & 0 deletions tests/TestCase/Controller/ComponentTest.php
Expand Up @@ -145,4 +145,27 @@ public function testSomethingReferencingCookieComponent()
$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 changes: 29 additions & 0 deletions tests/TestCase/View/HelperTest.php
Expand Up @@ -161,4 +161,33 @@ public function testLazyLoadingUsesReferences()
$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);
}
}

0 comments on commit 77017c6

Please sign in to comment.