Author: ts
Date: Tue Feb 12 10:55:29 2008
New Revision: 7346

Log:
- Added ezcDebugOptions class.
# Preperation of #10701: Getting a readable backtrace.

Added:
    trunk/Debug/src/options.php   (with props)
    trunk/Debug/tests/debug_options_test.php   (with props)
Modified:
    trunk/Debug/design/class_diagram.png
    trunk/Debug/src/debug.php
    trunk/Debug/src/debug_autoload.php
    trunk/Debug/tests/debug_test.php
    trunk/Debug/tests/suite.php

Modified: trunk/Debug/design/class_diagram.png
==============================================================================
Binary files - no diff available.

Modified: trunk/Debug/src/debug.php
==============================================================================
--- trunk/Debug/src/debug.php [iso-8859-1] (original)
+++ trunk/Debug/src/debug.php [iso-8859-1] Tue Feb 12 10:55:29 2008
@@ -71,6 +71,13 @@
 class ezcDebug
 {
     /**
+     * Properties. 
+     * 
+     * @var array(string=>mixed)
+     */
+    protected $properties = array();
+
+    /**
      * Instance of the singleton ezcDebug object.
      *
      * Use the getInstance() method to retrieve the instance.
@@ -114,6 +121,8 @@
      */
     private function __construct()
     {
+        $this->options = new ezcDebugOptions();
+
         $original = ezcLog::getInstance();
 
         $this->log = clone( $original ); 
@@ -132,28 +141,60 @@
 
 
     /**
-     * Throws always an [EMAIL PROTECTED] ezcBasePropertyNotFoundException}. 
+     * Property get access.
      *
      * @throws ezcBasePropertyNotFoundException
-     * @param string $name
+     *         If the given property could not be found.
+     * @param string $propertyName
      * @ignore
      */
-    public function __get( $name )
-    {
-        throw new ezcBasePropertyNotFoundException( $name );
-    }
-
-    /**
-     * Throws always an [EMAIL PROTECTED] ezcBasePropertyNotFoundException}. 
+    public function __get( $propertyName )
+    {
+        if ( $this->__isset( $propertyName ) )
+        {
+            return $this->properties[$propertyName];
+        }
+        throw new ezcBasePropertyNotFoundException( $propertyName );
+    }
+
+    /**
+     * Property set access.
      *
      * @throws ezcBasePropertyNotFoundException
-     * @param string $name
-     * @param string $value
+     * @param string $propertyName
+     * @param string $propertyValue
      * @ignore
      */
-    public function __set( $name, $value )
-    {
-        throw new ezcBasePropertyNotFoundException( $name );
+    public function __set( $propertyName, $propertyValue )
+    {
+        switch ( $propertyName )
+        {
+            case 'options':
+                if ( !( $propertyValue instanceof ezcDebugOptions ) )
+                {
+                    throw new ezcBaseValueException(
+                        $propertyName,
+                        $propertyValue,
+                        'ezcDebugOptions'
+                    );
+                }
+                break;
+            default:
+                throw new ezcBasePropertyNotFoundException( $propertyName );
+        }
+        $this->properties[$propertyName] = $propertyValue;
+    }
+
+    /**
+     * Property isset access. 
+     * 
+     * @param string $propertyName 
+     * @return bool
+     * @ignore
+     */
+    public function __isset( $propertyName )
+    {
+        return array_key_exists( $propertyName, $this->properties );
     }
 
 

Modified: trunk/Debug/src/debug_autoload.php
==============================================================================
--- trunk/Debug/src/debug_autoload.php [iso-8859-1] (original)
+++ trunk/Debug/src/debug_autoload.php [iso-8859-1] Tue Feb 12 10:55:29 2008
@@ -15,6 +15,7 @@
     'ezcDebugHtmlFormatter'     => 'Debug/formatters/html_formatter.php',
     'ezcDebugMemoryWriter'      => 'Debug/writers/memory_writer.php',
     'ezcDebugMessage'           => 'Debug/debug_message.php',
+    'ezcDebugOptions'           => 'Debug/options.php',
     'ezcDebugStructure'         => 'Debug/structs/debug_structure.php',
     'ezcDebugSwitchTimerStruct' => 'Debug/structs/switch_timer.php',
     'ezcDebugTimer'             => 'Debug/debug_timer.php',

Added: trunk/Debug/src/options.php
==============================================================================
--- trunk/Debug/src/options.php (added)
+++ trunk/Debug/src/options.php [iso-8859-1] Tue Feb 12 10:55:29 2008
@@ -1,0 +1,80 @@
+<?php
+/**
+ * This file contains the ezcDebugOptions class.
+ *
+ * @package Debug
+ * @version //autogentag//
+ * @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ * @filesource
+ */
+
+/**
+ * Options class for ezcDebug.
+ *
+ * @property bool $stackTrace
+ *           Determines if a stack trace is stored and displayed with every
+ *           debug message by default. Default is false.
+ * @property int $stackTraceDepth
+ *           The number of levels to store for the stack trace. 0 means no
+ *           limit and a complete stack trace will always be stored. Not that
+ *           this might consume a large amount of memory. Default is 5.
+ * @package Debug
+ * @version //autogen//
+ */
+class ezcDebugOptions extends ezcBaseOptions
+{
+    /**
+     * Properties.
+     * 
+     * @var array(string=>mixed)
+     */
+    protected $properties = array(
+        'stackTrace'      => false,
+        'stackTraceDepth' => 5,
+    );
+
+    /**
+     * Property write access.
+     * 
+     * @param string $propertyName Name of the property.
+     * @param mixed $propertyValue The value for the property.
+     *
+     * @throws ezcBasePropertyPermissionException
+     *         If the property you try to access is read-only.
+     * @throws ezcBasePropertyNotFoundException 
+     *         If the the desired property is not found.
+     * @ignore
+     */
+    public function __set( $propertyName, $propertyValue )
+    {
+        switch ( $propertyName )
+        {
+            case 'stackTrace':
+                if ( !is_bool( $propertyValue ) )
+                {
+                    throw new ezcBaseValueException(
+                        $propertyName,
+                        $propertyValue,
+                        'bool'
+                    );
+                }
+                break;
+            case 'stackTraceDepth':
+                if ( !is_int( $propertyValue ) || $propertyValue < 0 )
+                {
+                    throw new ezcBaseValueException(
+                        $propertyName,
+                        $propertyValue,
+                        'int >= 0'
+                    );
+                }
+                break;
+            default:
+                ezcBasePropertyNotFoundException( $propertyName );
+        }
+        $this->properties[$propertyName] = $propertyValue;
+    }
+}
+
+?>

Propchange: trunk/Debug/src/options.php
------------------------------------------------------------------------------
    svn:eol-style = native

Added: trunk/Debug/tests/debug_options_test.php
==============================================================================
--- trunk/Debug/tests/debug_options_test.php (added)
+++ trunk/Debug/tests/debug_options_test.php [iso-8859-1] Tue Feb 12 10:55:29 
2008
@@ -1,0 +1,75 @@
+<?php
+/**
+ * @copyright Copyright (C) 2005-2008 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ * @version //autogentag//
+ * @filesource
+ * @package Debug
+ * @subpackage Tests
+ */
+
+/**
+ * Test suite for the ezcDebugOptions class.
+ *
+ * @package Debug
+ * @subpackage Tests
+ */
+class ezcDebugOptionsTest extends ezcTestCase
+{
+    public static function suite()
+    {
+        return new PHPUnit_Framework_TestSuite( __CLASS__ );
+    }
+
+    public function testCtor()
+    {
+        $opts = new ezcDebugOptions();
+
+        $this->assertSame(
+            false,
+            $opts->stackTrace,
+            'Default value for option $stackTrace incorrect.'
+        );
+        $this->assertSame(
+            5,
+            $opts->stackTraceDepth,
+            'Default value for option $stackTraceDepth incorrect.'
+        );
+    }
+
+    public function testSetSuccess()
+    {
+        $opts = new ezcDebugOptions();
+
+        $opts->stackTrace      = true;
+        $opts->stackTraceDepth = 100;
+
+        $this->assertSetProperty(
+            $opts,
+            'stackTrace',
+            array( true, false )
+        );
+        $this->assertSetProperty(
+            $opts,
+            'stackTraceDepth',
+            array( 0, 1, 23 )
+        );
+    }
+
+    public function testSetFailure()
+    {
+        $opts = new ezcDebugOptions();
+
+        $this->assertSetPropertyFails(
+            $opts,
+            'stackTrace',
+            array( null, 23, 'foobar', array(), new stdClass() )
+        );
+        $this->assertSetPropertyFails(
+            $opts,
+            'stackTraceDepth',
+            array( null, true, -23, 'foobar', array(), new stdClass() )
+        );
+    }
+}
+?>

Propchange: trunk/Debug/tests/debug_options_test.php
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: trunk/Debug/tests/debug_test.php
==============================================================================
--- trunk/Debug/tests/debug_test.php [iso-8859-1] (original)
+++ trunk/Debug/tests/debug_test.php [iso-8859-1] Tue Feb 12 10:55:29 2008
@@ -47,6 +47,60 @@
         }
     }
 
+    public function testGetAccessSuccess()
+    {
+        $this->assertEquals(
+            new ezcDebugOptions(),
+            $this->dbg->options,
+            'Property $options does not have proper default value.'
+        );
+    }
+
+    public function testGetAccessFailures()
+    {
+        try
+        {
+            echo $this->dbg->foobar;
+            $this->fail( 'Exception not thrown on get access to unknown 
property $foobar.' );
+        }
+        catch ( ezcBasePropertyNotFoundException $e )
+        {}
+    }
+
+    public function testSetAccessSuccess()
+    {
+        $this->assertSetProperty(
+            $this->dbg,
+            'options',
+            array( new ezcDebugOptions(), )
+        );
+    }
+
+    public function testSetAccessFailure()
+    {
+        $this->assertSetPropertyFails(
+            $this->dbg,
+            'options',
+            array( null, true, 23, 23.42, 'foobar', array(), new stdClass )
+        );
+    }
+
+    public function testIssetAccessSuccess()
+    {
+        $this->assertTrue(
+            isset( $this->dbg->options ),
+            'Property $options does not seem to be set.'
+        );
+    }
+
+    public function testIssetAccessFailure()
+    {
+        $this->assertFalse(
+            isset( $this->dbg->foobar ),
+            'Property $foobar seems to be set.'
+        );
+    }
+
     // Messages are already tested in DebugMemoryWriterTest.
     // Quick test if the basics work.
     public function testSimpleMessage()

Modified: trunk/Debug/tests/suite.php
==============================================================================
--- trunk/Debug/tests/suite.php [iso-8859-1] (original)
+++ trunk/Debug/tests/suite.php [iso-8859-1] Tue Feb 12 10:55:29 2008
@@ -14,6 +14,7 @@
 
 require_once "debug_delayed_init_test.php";
 require_once "debug_test.php";
+require_once "debug_options_test.php";
 require_once "debug_timer_test.php";
 require_once "writers/memory_writer_test.php";
 require_once "formatters/html_formatter_test.php";
@@ -33,6 +34,7 @@
                $this->addTest( ezcDebugMemoryWriterTest::suite() );
                $this->addTest( ezcDebugTimerTest::suite() );
                $this->addTest( ezcDebugTest::suite() );
+               $this->addTest( ezcDebugOptionsTest::suite() );
                $this->addTest( ezcDebugHtmlFormatterTest::suite() );
        }
 


-- 
svn-components mailing list
[EMAIL PROTECTED]
http://lists.ez.no/mailman/listinfo/svn-components

Reply via email to