2008-05-30 11:40:08 +00:00
|
|
|
<?php
|
|
|
|
/**
|
2009-05-01 21:05:46 +00:00
|
|
|
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
|
2012-03-13 02:46:07 +00:00
|
|
|
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2009-05-01 21:05:46 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2012-03-13 02:46:07 +00:00
|
|
|
* @copyright Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
|
2010-01-26 22:54:34 +00:00
|
|
|
* @link http://cakephp.org CakePHP Project
|
2008-10-30 17:30:26 +00:00
|
|
|
* @since CakePHP(tm) v 1.2.0.5432
|
2009-05-01 21:05:46 +00:00
|
|
|
* @license MIT License (http://www.opensource.org/licenses/mit-license.php)
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2010-12-09 05:55:24 +00:00
|
|
|
App::uses('Debugger', 'Utility');
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* DebugggerTestCaseDebuggger class
|
2008-12-07 20:44:00 +00:00
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Utility
|
2008-12-07 20:44:00 +00:00
|
|
|
*/
|
2009-03-18 17:55:58 +00:00
|
|
|
class DebuggerTestCaseDebugger extends Debugger {
|
2008-12-07 20:44:00 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-12-07 20:44:00 +00:00
|
|
|
/**
|
2009-03-18 17:55:58 +00:00
|
|
|
* DebuggerTest class
|
2008-05-30 11:40:08 +00:00
|
|
|
*
|
2012-03-14 02:59:20 +00:00
|
|
|
* !!! Be careful with changing code below as it may
|
|
|
|
* !!! change line numbers which are used in the tests
|
|
|
|
*
|
2011-07-26 06:16:14 +00:00
|
|
|
* @package Cake.Test.Case.Utility
|
2008-05-30 11:40:08 +00:00
|
|
|
*/
|
2008-07-21 02:40:58 +00:00
|
|
|
class DebuggerTest extends CakeTestCase {
|
2012-03-14 02:59:20 +00:00
|
|
|
|
2010-11-15 01:19:15 +00:00
|
|
|
protected $_restoreError = false;
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* setUp method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function setUp() {
|
2011-12-04 21:27:51 +00:00
|
|
|
parent::setUp();
|
2010-11-14 05:59:45 +00:00
|
|
|
Configure::write('debug', 2);
|
2008-05-30 11:40:08 +00:00
|
|
|
Configure::write('log', false);
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2009-03-18 17:55:58 +00:00
|
|
|
/**
|
|
|
|
* tearDown method
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function tearDown() {
|
2011-12-04 21:27:51 +00:00
|
|
|
parent::tearDown();
|
2009-03-18 17:55:58 +00:00
|
|
|
Configure::write('log', true);
|
2010-11-15 01:19:15 +00:00
|
|
|
if ($this->_restoreError) {
|
|
|
|
restore_error_handler();
|
|
|
|
}
|
2009-03-18 17:55:58 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
2008-06-02 19:22:55 +00:00
|
|
|
* testDocRef method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDocRef() {
|
2008-06-20 20:17:23 +00:00
|
|
|
ini_set('docref_root', '');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(ini_get('docref_root'), '');
|
2008-06-20 20:17:23 +00:00
|
|
|
$debugger = new Debugger();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals(ini_get('docref_root'), 'http://php.net/');
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-10-18 01:23:33 +00:00
|
|
|
/**
|
|
|
|
* test Excerpt writing
|
|
|
|
*
|
|
|
|
* @return void
|
2009-03-18 17:55:58 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testExcerpt() {
|
2009-05-01 21:05:46 +00:00
|
|
|
$result = Debugger::excerpt(__FILE__, __LINE__, 2);
|
|
|
|
$this->assertTrue(is_array($result));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(5, count($result));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/function(.+)testExcerpt/', $result[1]);
|
2009-05-01 21:05:46 +00:00
|
|
|
|
|
|
|
$result = Debugger::excerpt(__FILE__, 2, 2);
|
|
|
|
$this->assertTrue(is_array($result));
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals(4, count($result));
|
2009-05-01 21:05:46 +00:00
|
|
|
|
2011-09-04 00:06:00 +00:00
|
|
|
$pattern = '/<code><span style\="color\: \#\d+">.*?<\?php/';
|
|
|
|
$this->assertRegExp($pattern, $result[0]);
|
2009-03-18 17:55:58 +00:00
|
|
|
|
2008-10-18 01:23:33 +00:00
|
|
|
$return = Debugger::excerpt('[internal]', 2, 2);
|
|
|
|
$this->assertTrue(empty($return));
|
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testOutput method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testOutput() {
|
2010-11-15 01:19:15 +00:00
|
|
|
set_error_handler('Debugger::showError');
|
|
|
|
$this->_restoreError = true;
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = Debugger::output(false);
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('', $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
$out .= '';
|
|
|
|
$result = Debugger::output(true);
|
2008-06-05 15:20:45 +00:00
|
|
|
|
2012-03-23 06:37:12 +00:00
|
|
|
$this->assertEquals('Notice', $result[0]['error']);
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/Undefined variable\:\s+out/', $result[0]['description']);
|
|
|
|
$this->assertRegExp('/DebuggerTest::testOutput/i', $result[0]['trace']);
|
2008-06-05 15:20:45 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
ob_start();
|
|
|
|
Debugger::output('txt');
|
|
|
|
$other .= '';
|
|
|
|
$result = ob_get_clean();
|
2008-06-05 15:20:45 +00:00
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/Undefined variable:\s+other/', $result);
|
|
|
|
$this->assertRegExp('/Context:/', $result);
|
|
|
|
$this->assertRegExp('/DebuggerTest::testOutput/i', $result);
|
2008-06-05 15:20:45 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
ob_start();
|
|
|
|
Debugger::output('html');
|
|
|
|
$wrong .= '';
|
|
|
|
$result = ob_get_clean();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/<pre class="cake-error">.+<\/pre>/', $result);
|
|
|
|
$this->assertRegExp('/<b>Notice<\/b>/', $result);
|
|
|
|
$this->assertRegExp('/variable:\s+wrong/', $result);
|
2008-06-05 15:20:45 +00:00
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
ob_start();
|
|
|
|
Debugger::output('js');
|
|
|
|
$buzz .= '';
|
2009-05-01 21:05:46 +00:00
|
|
|
$result = explode('</a>', ob_get_clean());
|
|
|
|
$this->assertTags($result[0], array(
|
2011-09-02 13:18:33 +00:00
|
|
|
'pre' => array('class' => 'cake-error'),
|
2009-05-01 21:05:46 +00:00
|
|
|
'a' => array(
|
|
|
|
'href' => "javascript:void(0);",
|
2011-05-05 03:30:24 +00:00
|
|
|
'onclick' => "preg:/document\.getElementById\('cakeErr[a-z0-9]+\-trace'\)\.style\.display = " .
|
2012-11-21 14:39:03 +00:00
|
|
|
"\(document\.getElementById\('cakeErr[a-z0-9]+\-trace'\)\.style\.display == 'none'" .
|
|
|
|
" \? '' \: 'none'\);/"
|
2009-05-01 21:05:46 +00:00
|
|
|
),
|
2009-07-25 17:27:17 +00:00
|
|
|
'b' => array(), 'Notice', '/b', ' (8)',
|
2009-05-01 21:05:46 +00:00
|
|
|
));
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/Undefined variable:\s+buzz/', $result[1]);
|
|
|
|
$this->assertRegExp('/<a[^>]+>Code/', $result[1]);
|
|
|
|
$this->assertRegExp('/<a[^>]+>Context/', $result[2]);
|
2012-05-17 01:07:45 +00:00
|
|
|
$this->assertContains('$wrong = ''', $result[3], 'Context should be HTML escaped.');
|
2009-05-01 21:05:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests that changes in output formats using Debugger::output() change the templates used.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testChangeOutputFormats() {
|
2010-11-15 01:19:15 +00:00
|
|
|
set_error_handler('Debugger::showError');
|
|
|
|
$this->_restoreError = true;
|
|
|
|
|
2009-05-01 21:05:46 +00:00
|
|
|
Debugger::output('js', array(
|
|
|
|
'traceLine' => '{:reference} - <a href="txmt://open?url=file://{:file}' .
|
2012-05-17 01:07:45 +00:00
|
|
|
'&line={:line}">{:path}</a>, line {:line}'
|
2009-05-01 21:05:46 +00:00
|
|
|
));
|
|
|
|
$result = Debugger::trace();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/' . preg_quote('txmt://open?url=file://', '/') . '(\/|[A-Z]:\\\\)' . '/', $result);
|
2009-05-01 21:05:46 +00:00
|
|
|
|
|
|
|
Debugger::output('xml', array(
|
|
|
|
'error' => '<error><code>{:code}</code><file>{:file}</file><line>{:line}</line>' .
|
2012-11-21 14:39:03 +00:00
|
|
|
'{:description}</error>',
|
2009-05-01 21:05:46 +00:00
|
|
|
'context' => "<context>{:context}</context>",
|
|
|
|
'trace' => "<stack>{:trace}</stack>",
|
|
|
|
));
|
|
|
|
Debugger::output('xml');
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$foo .= '';
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = ob_get_clean();
|
2009-05-01 21:05:46 +00:00
|
|
|
|
|
|
|
$data = array(
|
|
|
|
'error' => array(),
|
|
|
|
'code' => array(), '8', '/code',
|
|
|
|
'file' => array(), 'preg:/[^<]+/', '/file',
|
2010-06-07 04:40:35 +00:00
|
|
|
'line' => array(), '' . (intval(__LINE__) - 7), '/line',
|
2010-01-15 04:06:48 +00:00
|
|
|
'preg:/Undefined variable:\s+foo/',
|
2009-05-01 21:05:46 +00:00
|
|
|
'/error'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $data, true);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2011-08-21 14:19:43 +00:00
|
|
|
/**
|
|
|
|
* Test that outputAs works.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testOutputAs() {
|
|
|
|
Debugger::outputAs('html');
|
|
|
|
$this->assertEquals('html', Debugger::outputAs());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-02-23 23:29:53 +00:00
|
|
|
* Test that choosing a non-existent format causes an exception
|
2011-08-21 14:19:43 +00:00
|
|
|
*
|
|
|
|
* @expectedException CakeException
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testOutputAsException() {
|
|
|
|
Debugger::outputAs('Invalid junk');
|
|
|
|
}
|
|
|
|
|
2011-08-21 14:30:10 +00:00
|
|
|
/**
|
|
|
|
* Tests that changes in output formats using Debugger::output() change the templates used.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testAddFormat() {
|
|
|
|
set_error_handler('Debugger::showError');
|
|
|
|
$this->_restoreError = true;
|
|
|
|
|
|
|
|
Debugger::addFormat('js', array(
|
|
|
|
'traceLine' => '{:reference} - <a href="txmt://open?url=file://{:file}' .
|
2012-11-21 14:39:03 +00:00
|
|
|
'&line={:line}">{:path}</a>, line {:line}'
|
2011-08-21 14:30:10 +00:00
|
|
|
));
|
|
|
|
Debugger::outputAs('js');
|
|
|
|
|
|
|
|
$result = Debugger::trace();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/' . preg_quote('txmt://open?url=file://', '/') . '(\/|[A-Z]:\\\\)' . '/', $result);
|
2011-08-21 14:30:10 +00:00
|
|
|
|
|
|
|
Debugger::addFormat('xml', array(
|
|
|
|
'error' => '<error><code>{:code}</code><file>{:file}</file><line>{:line}</line>' .
|
2012-11-21 14:39:03 +00:00
|
|
|
'{:description}</error>',
|
2011-08-21 14:30:10 +00:00
|
|
|
));
|
|
|
|
Debugger::outputAs('xml');
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$foo .= '';
|
|
|
|
$result = ob_get_clean();
|
|
|
|
|
|
|
|
$data = array(
|
|
|
|
'<error',
|
|
|
|
'<code', '8', '/code',
|
|
|
|
'<file', 'preg:/[^<]+/', '/file',
|
|
|
|
'<line', '' . (intval(__LINE__) - 7), '/line',
|
|
|
|
'preg:/Undefined variable:\s+foo/',
|
|
|
|
'/error'
|
|
|
|
);
|
|
|
|
$this->assertTags($result, $data, true);
|
|
|
|
}
|
|
|
|
|
2011-09-02 13:18:33 +00:00
|
|
|
/**
|
|
|
|
* Test adding a format that is handled by a callback.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-08-21 14:47:52 +00:00
|
|
|
public function testAddFormatCallback() {
|
|
|
|
set_error_handler('Debugger::showError');
|
|
|
|
$this->_restoreError = true;
|
|
|
|
|
|
|
|
Debugger::addFormat('callback', array('callback' => array($this, 'customFormat')));
|
|
|
|
Debugger::outputAs('callback');
|
|
|
|
|
|
|
|
ob_start();
|
|
|
|
$foo .= '';
|
|
|
|
$result = ob_get_clean();
|
2011-10-01 02:44:04 +00:00
|
|
|
$this->assertContains('Notice: I eated an error', $result);
|
|
|
|
$this->assertContains('DebuggerTest.php', $result);
|
2011-08-21 14:47:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Test method for testing addFormat with callbacks.
|
|
|
|
*/
|
|
|
|
public function customFormat($error, $strings) {
|
2012-09-10 01:08:21 +00:00
|
|
|
return $error['error'] . ': I eated an error ' . $error['file'];
|
2011-08-21 14:47:52 +00:00
|
|
|
}
|
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testTrimPath method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testTrimPath() {
|
2012-09-05 22:52:17 +00:00
|
|
|
$this->assertEquals('APP' . DS, Debugger::trimPath(APP));
|
|
|
|
$this->assertEquals('CORE', Debugger::trimPath(CAKE_CORE_INCLUDE_PATH));
|
|
|
|
$this->assertEquals('ROOT', Debugger::trimPath(ROOT));
|
|
|
|
$this->assertEquals('CORE' . DS . 'Cake' . DS, Debugger::trimPath(CAKE));
|
|
|
|
$this->assertEquals('Some/Other/Path', Debugger::trimPath('Some/Other/Path'));
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testExportVar method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testExportVar() {
|
2010-12-09 05:55:24 +00:00
|
|
|
App::uses('Controller', 'Controller');
|
2008-05-30 11:40:08 +00:00
|
|
|
$Controller = new Controller();
|
|
|
|
$Controller->helpers = array('Html', 'Form');
|
|
|
|
$View = new View($Controller);
|
2011-10-15 15:42:09 +00:00
|
|
|
$View->int = 2;
|
|
|
|
$View->float = 1.333;
|
|
|
|
|
2008-05-30 11:40:08 +00:00
|
|
|
$result = Debugger::exportVar($View);
|
2011-10-15 15:42:09 +00:00
|
|
|
$expected = <<<TEXT
|
|
|
|
object(View) {
|
|
|
|
Helpers => object(HelperCollection) {}
|
2011-12-18 03:53:21 +00:00
|
|
|
Blocks => object(ViewBlock) {}
|
2011-10-15 15:42:09 +00:00
|
|
|
plugin => null
|
|
|
|
name => ''
|
|
|
|
passedArgs => array()
|
|
|
|
helpers => array(
|
|
|
|
(int) 0 => 'Html',
|
|
|
|
(int) 1 => 'Form'
|
|
|
|
)
|
|
|
|
viewPath => ''
|
|
|
|
viewVars => array()
|
|
|
|
view => null
|
|
|
|
layout => 'default'
|
|
|
|
layoutPath => null
|
|
|
|
autoLayout => true
|
|
|
|
ext => '.ctp'
|
|
|
|
subDir => null
|
|
|
|
theme => null
|
|
|
|
cacheAction => false
|
|
|
|
validationErrors => array()
|
|
|
|
hasRendered => false
|
|
|
|
uuids => array()
|
2012-06-04 13:29:28 +00:00
|
|
|
request => object(CakeRequest) {}
|
2012-02-06 15:15:00 +00:00
|
|
|
response => object(CakeResponse) {}
|
2011-10-15 15:42:09 +00:00
|
|
|
elementCache => 'default'
|
2012-07-07 05:08:39 +00:00
|
|
|
elementCacheSettings => array()
|
2011-10-15 15:42:09 +00:00
|
|
|
int => (int) 2
|
|
|
|
float => (float) 1.333
|
2012-08-06 17:31:35 +00:00
|
|
|
|
|
|
|
TEXT;
|
|
|
|
if (version_compare(PHP_VERSION, '5.3.0') >= 0) {
|
|
|
|
$expected .= <<<TEXT
|
|
|
|
[protected] _passedVars => array(
|
|
|
|
(int) 0 => 'viewVars',
|
|
|
|
(int) 1 => 'autoLayout',
|
|
|
|
(int) 2 => 'ext',
|
|
|
|
(int) 3 => 'helpers',
|
|
|
|
(int) 4 => 'view',
|
|
|
|
(int) 5 => 'layout',
|
|
|
|
(int) 6 => 'name',
|
|
|
|
(int) 7 => 'theme',
|
|
|
|
(int) 8 => 'layoutPath',
|
|
|
|
(int) 9 => 'viewPath',
|
|
|
|
(int) 10 => 'request',
|
|
|
|
(int) 11 => 'plugin',
|
|
|
|
(int) 12 => 'passedArgs',
|
|
|
|
(int) 13 => 'cacheAction'
|
|
|
|
)
|
|
|
|
[protected] _scripts => array()
|
|
|
|
[protected] _paths => array()
|
|
|
|
[protected] _helpersLoaded => false
|
|
|
|
[protected] _parents => array()
|
|
|
|
[protected] _current => null
|
|
|
|
[protected] _currentType => ''
|
|
|
|
[protected] _stack => array()
|
|
|
|
[protected] _eventManager => object(CakeEventManager) {}
|
|
|
|
[protected] _eventManagerConfigured => false
|
|
|
|
|
|
|
|
TEXT;
|
|
|
|
}
|
|
|
|
$expected .= <<<TEXT
|
2011-10-15 15:42:09 +00:00
|
|
|
}
|
|
|
|
TEXT;
|
2012-08-06 17:31:35 +00:00
|
|
|
|
2012-01-25 02:12:26 +00:00
|
|
|
$this->assertTextEquals($expected, $result);
|
2012-01-25 01:52:43 +00:00
|
|
|
|
|
|
|
$data = array(
|
|
|
|
1 => 'Index one',
|
|
|
|
5 => 'Index five'
|
|
|
|
);
|
|
|
|
$result = Debugger::exportVar($data);
|
|
|
|
$expected = <<<TEXT
|
|
|
|
array(
|
|
|
|
(int) 1 => 'Index one',
|
|
|
|
(int) 5 => 'Index five'
|
|
|
|
)
|
2012-06-11 00:00:34 +00:00
|
|
|
TEXT;
|
|
|
|
$this->assertTextEquals($expected, $result);
|
|
|
|
|
|
|
|
$data = array(
|
|
|
|
'key' => array(
|
|
|
|
'value'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
$result = Debugger::exportVar($data, 1);
|
|
|
|
$expected = <<<TEXT
|
|
|
|
array(
|
|
|
|
'key' => array(
|
|
|
|
[maximum depth reached]
|
|
|
|
)
|
|
|
|
)
|
2012-10-12 14:03:05 +00:00
|
|
|
TEXT;
|
|
|
|
$this->assertTextEquals($expected, $result);
|
|
|
|
|
|
|
|
$data = false;
|
|
|
|
$result = Debugger::exportVar($data);
|
|
|
|
$expected = <<<TEXT
|
|
|
|
false
|
2012-01-25 01:52:43 +00:00
|
|
|
TEXT;
|
2012-01-25 02:12:26 +00:00
|
|
|
$this->assertTextEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-02 19:22:55 +00:00
|
|
|
/**
|
|
|
|
* testLog method
|
2008-06-05 15:20:45 +00:00
|
|
|
*
|
2008-06-02 19:22:55 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testLog() {
|
2008-05-30 11:40:08 +00:00
|
|
|
if (file_exists(LOGS . 'debug.log')) {
|
|
|
|
unlink(LOGS . 'debug.log');
|
|
|
|
}
|
|
|
|
|
|
|
|
Debugger::log('cool');
|
|
|
|
$result = file_get_contents(LOGS . 'debug.log');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/DebuggerTest\:\:testLog/i', $result);
|
2011-11-17 02:31:16 +00:00
|
|
|
$this->assertRegExp("/'cool'/", $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
|
2012-05-11 01:32:00 +00:00
|
|
|
unlink(LOGS . 'debug.log');
|
2008-05-30 11:40:08 +00:00
|
|
|
|
|
|
|
Debugger::log(array('whatever', 'here'));
|
2012-05-11 01:32:00 +00:00
|
|
|
$result = file_get_contents(LOGS . 'debug.log');
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/DebuggerTest\:\:testLog/i', $result);
|
|
|
|
$this->assertRegExp('/\[main\]/', $result);
|
|
|
|
$this->assertRegExp('/array/', $result);
|
2011-11-17 02:31:16 +00:00
|
|
|
$this->assertRegExp("/'whatever',/", $result);
|
|
|
|
$this->assertRegExp("/'here'/", $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-06-05 15:20:45 +00:00
|
|
|
/**
|
|
|
|
* testDump method
|
2008-06-11 08:54:27 +00:00
|
|
|
*
|
2008-06-05 15:20:45 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testDump() {
|
2008-05-30 11:40:08 +00:00
|
|
|
$var = array('People' => array(
|
2011-10-15 15:42:09 +00:00
|
|
|
array(
|
|
|
|
'name' => 'joeseph',
|
|
|
|
'coat' => 'technicolor',
|
|
|
|
'hair_color' => 'brown'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'name' => 'Shaft',
|
|
|
|
'coat' => 'black',
|
|
|
|
'hair' => 'black'
|
|
|
|
)
|
|
|
|
));
|
2008-05-30 11:40:08 +00:00
|
|
|
ob_start();
|
|
|
|
Debugger::dump($var);
|
|
|
|
$result = ob_get_clean();
|
2011-10-15 19:38:45 +00:00
|
|
|
$expected = <<<TEXT
|
|
|
|
<pre>array(
|
|
|
|
'People' => array(
|
|
|
|
(int) 0 => array(
|
2012-06-11 00:00:34 +00:00
|
|
|
'name' => 'joeseph',
|
|
|
|
'coat' => 'technicolor',
|
|
|
|
'hair_color' => 'brown'
|
2011-10-15 19:38:45 +00:00
|
|
|
),
|
|
|
|
(int) 1 => array(
|
2012-06-11 00:00:34 +00:00
|
|
|
'name' => 'Shaft',
|
|
|
|
'coat' => 'black',
|
|
|
|
'hair' => 'black'
|
2011-10-15 19:38:45 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
)</pre>
|
|
|
|
TEXT;
|
2012-01-25 02:12:26 +00:00
|
|
|
$this->assertTextEquals($expected, $result);
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|
2009-07-24 19:18:37 +00:00
|
|
|
|
2008-12-07 20:44:00 +00:00
|
|
|
/**
|
|
|
|
* test getInstance.
|
|
|
|
*
|
|
|
|
* @return void
|
2009-03-18 17:55:58 +00:00
|
|
|
*/
|
2011-05-30 20:02:32 +00:00
|
|
|
public function testGetInstance() {
|
2010-06-09 04:34:31 +00:00
|
|
|
$result = Debugger::getInstance();
|
2011-10-15 15:42:09 +00:00
|
|
|
$this->assertInstanceOf('Debugger', $result);
|
2009-03-18 17:55:58 +00:00
|
|
|
|
2010-06-09 04:34:31 +00:00
|
|
|
$result = Debugger::getInstance('DebuggerTestCaseDebugger');
|
2011-10-15 15:42:09 +00:00
|
|
|
$this->assertInstanceOf('DebuggerTestCaseDebugger', $result);
|
2009-03-18 17:55:58 +00:00
|
|
|
|
2010-06-09 04:34:31 +00:00
|
|
|
$result = Debugger::getInstance();
|
2011-10-15 15:42:09 +00:00
|
|
|
$this->assertInstanceOf('DebuggerTestCaseDebugger', $result);
|
2009-03-18 17:55:58 +00:00
|
|
|
|
2010-06-09 04:34:31 +00:00
|
|
|
$result = Debugger::getInstance('Debugger');
|
2011-10-15 15:42:09 +00:00
|
|
|
$this->assertInstanceOf('Debugger', $result);
|
2008-12-07 20:44:00 +00:00
|
|
|
}
|
2011-06-24 08:12:08 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* testNoDbCredentials
|
|
|
|
*
|
|
|
|
* If a connection error occurs, the config variable is passed through exportVar
|
|
|
|
* *** our database login credentials such that they are never visible
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2011-10-27 14:01:36 +00:00
|
|
|
public function testNoDbCredentials() {
|
2011-06-24 08:12:08 +00:00
|
|
|
$config = array(
|
2011-11-04 22:07:31 +00:00
|
|
|
'datasource' => 'mysql',
|
2011-06-24 08:12:08 +00:00
|
|
|
'persistent' => false,
|
|
|
|
'host' => 'void.cakephp.org',
|
|
|
|
'login' => 'cakephp-user',
|
|
|
|
'password' => 'cakephp-password',
|
|
|
|
'database' => 'cakephp-database',
|
|
|
|
'prefix' => ''
|
|
|
|
);
|
|
|
|
|
|
|
|
$output = Debugger::exportVar($config);
|
|
|
|
|
|
|
|
$expectedArray = array(
|
2011-11-04 22:07:31 +00:00
|
|
|
'datasource' => 'mysql',
|
2011-06-24 08:12:08 +00:00
|
|
|
'persistent' => false,
|
|
|
|
'host' => '*****',
|
|
|
|
'login' => '*****',
|
|
|
|
'password' => '*****',
|
|
|
|
'database' => '*****',
|
|
|
|
'prefix' => ''
|
|
|
|
);
|
|
|
|
$expected = Debugger::exportVar($expectedArray);
|
|
|
|
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertEquals($expected, $output);
|
2011-06-24 08:12:08 +00:00
|
|
|
}
|
2011-10-27 14:01:36 +00:00
|
|
|
|
2012-08-09 02:30:27 +00:00
|
|
|
/**
|
|
|
|
* Test that exportVar() doesn't loop through recursive structures.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testExportVarRecursion() {
|
|
|
|
$output = Debugger::exportVar($GLOBALS);
|
|
|
|
$this->assertContains("'GLOBALS' => [recursion]", $output);
|
|
|
|
}
|
|
|
|
|
2011-10-27 14:01:36 +00:00
|
|
|
/**
|
|
|
|
* test trace exclude
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function testTraceExclude() {
|
|
|
|
$result = Debugger::trace();
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertRegExp('/^DebuggerTest::testTraceExclude/', $result);
|
2011-10-27 14:01:36 +00:00
|
|
|
|
|
|
|
$result = Debugger::trace(array(
|
|
|
|
'exclude' => array('DebuggerTest::testTraceExclude')
|
|
|
|
));
|
2011-11-16 00:07:56 +00:00
|
|
|
$this->assertNotRegExp('/^DebuggerTest::testTraceExclude/', $result);
|
2011-10-27 14:01:36 +00:00
|
|
|
}
|
2008-05-30 11:40:08 +00:00
|
|
|
}
|