Author: Derick Rethans
Date: 2006-01-12 17:12:56 +0100 (Thu, 12 Jan 2006)
New Revision: 1792

Log:
- Added the new exceptions.

Added:
   packages/Base/trunk/src/exceptions/exception.php
   packages/Base/trunk/src/exceptions/file_exception.php
   packages/Base/trunk/src/exceptions/file_io.php
   packages/Base/trunk/src/exceptions/file_not_found.php
   packages/Base/trunk/src/exceptions/file_permission.php
   packages/Base/trunk/src/exceptions/property_not_found.php
   packages/Base/trunk/src/exceptions/property_permission.php
   packages/Base/trunk/src/exceptions/setting_not_found.php
   packages/Base/trunk/src/exceptions/setting_value.php
   packages/Base/trunk/src/exceptions/value.php
   packages/Base/trunk/src/exceptions/value_exception.php
Removed:
   packages/Base/trunk/src/exceptions/base_exception.php
   packages/Base/trunk/src/exceptions/config_exception.php
   packages/Base/trunk/src/exceptions/property_exception.php
   packages/Base/trunk/src/exceptions/property_read_only_exception.php
   packages/Base/trunk/src/exceptions/type_exception.php
Modified:
   packages/Base/trunk/src/base.php
   packages/Base/trunk/src/base_autoload.php
   packages/Base/trunk/tests/base_test.php

Modified: packages/Base/trunk/src/base.php
===================================================================
--- packages/Base/trunk/src/base.php    2006-01-12 16:09:13 UTC (rev 1791)
+++ packages/Base/trunk/src/base.php    2006-01-12 16:12:56 UTC (rev 1792)
@@ -190,24 +190,5 @@
 
         require( ezcBase::$packageDir . $file );
     }
-
-
-    /**
-     * Throws an ezcBaseTypeException when the given instance is not from 
-     * expected type. If the instance is from the given type, nothing happens.
-     *
-     * @param object $instance  Instance that should be of the type $type.
-     * @param string $type      The expected type of the instance.
-     *
-     * @throws ezcBaseTypeException
-     */
-    public static function assertType( $instance, $type )
-    {
-        if ( !( $instance instanceof $type ) ) 
-        {
-            throw new ezcBaseTypeException( $type, gettype( $instance ) );
-        }
-    }
 }
-
 ?>

Modified: packages/Base/trunk/src/base_autoload.php
===================================================================
--- packages/Base/trunk/src/base_autoload.php   2006-01-12 16:09:13 UTC (rev 
1791)
+++ packages/Base/trunk/src/base_autoload.php   2006-01-12 16:12:56 UTC (rev 
1792)
@@ -8,11 +8,16 @@
  */
 
 return array(
-    'ezcBaseException'                     => 
'Base/exceptions/base_exception.php',
-    'ezcBasePropertyException'             => 
'Base/exceptions/property_exception.php',
-    'ezcBasePropertyNotFoundException'     => 
'Base/exceptions/property_not_found_exception.php',
-    'ezcBasePropertyReadOnlyException'     => 
'Base/exceptions/property_read_only_exception.php',
-    'ezcBaseTypeException'                 => 
'Base/exceptions/type_exception.php',
-    'ezcBaseConfigException'               => 
'Base/exceptions/config_exception.php',
+    'ezcBaseException'                     => 'Base/exceptions/exception.php',
+    'ezcBaseFileException'                 => 
'Base/exceptions/file_exception.php',
+
+    'ezcBaseFileNotFoundException'         => 
'Base/exceptions/file_not_found.php',
+    'ezcBaseFileIoException'               => 'Base/exceptions/file_io.php',
+    'ezcBaseFilePermissionException'       => 
'Base/exceptions/file_permission.php',
+    'ezcBasePropertyPermissionException'   => 
'Base/exceptions/property_permission.php',
+    'ezcBasePropertyNotFoundException'     => 
'Base/exceptions/property_not_found.php',
+    'ezcBaseSettingNotFoundException'      => 
'Base/exceptions/setting_not_found.php',
+    'ezcBaseSettingValueException'         => 
'Base/exceptions/setting_value.php',
+    'ezcBaseValueException'                => 'Base/exceptions/value.php',
 );
 ?>

Deleted: packages/Base/trunk/src/exceptions/base_exception.php
===================================================================
--- packages/Base/trunk/src/exceptions/base_exception.php       2006-01-12 
16:09:13 UTC (rev 1791)
+++ packages/Base/trunk/src/exceptions/base_exception.php       2006-01-12 
16:12:56 UTC (rev 1792)
@@ -1,20 +0,0 @@
-<?php
-/**
- * File containing the ezcBaseException class.
- *
- * @package Base
- * @version //autogen//
- * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
- * @license http://ez.no/licenses/new_bsd New BSD License
- */
-/**
- * ezcBaseException is a container from which all other exceptions in the
- * components library descent.
- *
- * @package Base
- * @version //autogen//
- */
-abstract class ezcBaseException extends Exception
-{
-}
-?>

Deleted: packages/Base/trunk/src/exceptions/config_exception.php
===================================================================
--- packages/Base/trunk/src/exceptions/config_exception.php     2006-01-12 
16:09:13 UTC (rev 1791)
+++ packages/Base/trunk/src/exceptions/config_exception.php     2006-01-12 
16:12:56 UTC (rev 1792)
@@ -1,53 +0,0 @@
-<?php
-/**
- * File containing the ezcBaseConfigException class.
- *
- * @package Base
- * @version //autogen//
- * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
- * @license http://ez.no/licenses/new_bsd New BSD License
- */
-/**
- * ezcBaseConfigException is thrown whenever there is something wrong with
- * configuration that is set through the setOptions() method of a class.
- *
- * @package Base
- */
-class ezcBaseConfigException extends ezcBaseException
-{
-    /**
-     * Used for when a config setting was unknown
-     */
-    const UNKNOWN_CONFIG_SETTING = 1;
-
-    /**
-     * Used when an option's value was out of range
-     */
-    const VALUE_OUT_OF_RANGE = 2;
-
-    /**
-     * Constructs a new ezcBaseConfigException
-     *
-     * Constructs a new ezcBaseConfigException
-     *
-     * @param string  $settingName The name of the setting where something was
-     *                wrong with.
-     * @param int $exceptionType The type of exception (use one of the
-     *                class' constants for this)
-     * @param mixed   $value The value that the option was tried to be set too
-     */
-    function __construct( $settingName, $exceptionType, $value = null )
-    {
-        switch ( $exceptionType )
-        {
-            case self::UNKNOWN_CONFIG_SETTING:
-                $msg = "The setting <{$settingName}> is not a valid 
configuration setting.";
-                break;
-            case self::VALUE_OUT_OF_RANGE:
-                $msg = "The value <{$value}> that you were trying to assign to 
setting <{$settingName}> is invalid.";
-                break;
-        }
-        parent::__construct( $msg, $exceptionType );
-    }
-}
-?>

Copied: packages/Base/trunk/src/exceptions/exception.php (from rev 1762, 
packages/Base/trunk/src/exceptions/base_exception.php)

Added: packages/Base/trunk/src/exceptions/file_exception.php
===================================================================
--- packages/Base/trunk/src/exceptions/file_exception.php       2006-01-12 
16:09:13 UTC (rev 1791)
+++ packages/Base/trunk/src/exceptions/file_exception.php       2006-01-12 
16:12:56 UTC (rev 1792)
@@ -0,0 +1,24 @@
+<?php
+/**
+ * File containing the ezcPropertyReadOnlyException class
+ *
+ * @package Base
+ * @version //autogen//
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+/**
+ * ezcBaseFileException is the exception from which all file related exceptions
+ * inherit.
+ *
+ * @package Base
+ * @version //autogen//
+ */
+abstract class ezcBaseFileException extends ezcBaseException
+{
+    const READ    = 1;
+    const WRITE   = 2;
+    const EXECUTE = 4;
+    const CHANGE  = 8;
+}
+?>


Property changes on: packages/Base/trunk/src/exceptions/file_exception.php
___________________________________________________________________
Name: svn:eol-style
   + native

Added: packages/Base/trunk/src/exceptions/file_io.php
===================================================================
--- packages/Base/trunk/src/exceptions/file_io.php      2006-01-12 16:09:13 UTC 
(rev 1791)
+++ packages/Base/trunk/src/exceptions/file_io.php      2006-01-12 16:12:56 UTC 
(rev 1792)
@@ -0,0 +1,50 @@
+<?php
+/**
+ * File containing the ezcPropertyReadOnlyException class
+ *
+ * @package Base
+ * @version //autogen//
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+/**
+ * ezcBaseFileIoException is thrown when a problem occurs while writing
+ * and reading to/from an open file.
+ *
+ * @package Base
+ * @version //autogen//
+ */
+class ezcBaseFileIoException extends ezcBaseFileException
+{
+    /**
+     * Constructs a new ezcBaseFileIoException for the file $path.
+     *
+     * @param string $name The name of the file.
+     * @param int    $mode The mode of the property that is allowed
+     *               (ezcBaseFileException::READ, ezcBaseFileException::WRITE,
+     *               ezcBaseFileException::EXECUTE or
+     *               ezcBaseFileException::CHANGE).
+     * @param string $message A string with extra information.
+     */
+    function __construct( $path, $mode, $message = null )
+    {
+        switch ( $mode )
+        {
+            case ezcBaseFileException::READ:
+                $operation = "An error occurred while reading from <{$path}>";
+                break;
+            case ezcBaseFileException::WRITE:
+                $operation = "An error occurred while writing to <{$path}>";
+                break;
+        }
+        
+        $messagePart = '';
+        if ( $message )
+        {
+            $messagePart = " ($message)";
+        }
+        
+        parent::__construct( "$operation.$messagePart" );
+    }
+}
+?>


Property changes on: packages/Base/trunk/src/exceptions/file_io.php
___________________________________________________________________
Name: svn:eol-style
   + native

Added: packages/Base/trunk/src/exceptions/file_not_found.php
===================================================================
--- packages/Base/trunk/src/exceptions/file_not_found.php       2006-01-12 
16:09:13 UTC (rev 1791)
+++ packages/Base/trunk/src/exceptions/file_not_found.php       2006-01-12 
16:12:56 UTC (rev 1792)
@@ -0,0 +1,43 @@
+<?php
+/**
+ * File containing the ezcPropertyReadOnlyException class
+ *
+ * @package Base
+ * @version //autogen//
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+/**
+ * ezcBaseFileNotFoundException is thrown when a file or directory was tried to
+ * be opened, but did not exist.
+ *
+ * @package Base
+ * @version //autogen//
+ */
+class ezcBaseFileNotFoundException extends ezcBaseFileException
+{
+    /**
+     * Constructs a new ezcBaseFileNotFoundException.
+     *
+     * @param string $name The name of the file.
+     * @param string $type The type of the file.
+     * @param string $message A string with extra information.
+     */
+    function __construct( $path, $type = null, $message = null )
+    {
+        $typePart = '';
+        if ( $type )
+        {
+            $typePart = "$type ";
+        }
+        
+        $messagePart = '';
+        if ( $message )
+        {
+            $messagePart = " ($message)";
+        }
+        
+        parent::__construct( "The {$typePart}file <{$path}> could not be 
found.$messagePart" );
+    }
+}
+?>


Property changes on: packages/Base/trunk/src/exceptions/file_not_found.php
___________________________________________________________________
Name: svn:eol-style
   + native

Added: packages/Base/trunk/src/exceptions/file_permission.php
===================================================================
--- packages/Base/trunk/src/exceptions/file_permission.php      2006-01-12 
16:09:13 UTC (rev 1791)
+++ packages/Base/trunk/src/exceptions/file_permission.php      2006-01-12 
16:12:56 UTC (rev 1792)
@@ -0,0 +1,56 @@
+<?php
+/**
+ * File containing the ezcPropertyReadOnlyException class
+ *
+ * @package Base
+ * @version //autogen//
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+/**
+ * ezcBaseFilePermissionException is thrown whenever a permission problem with
+ * a file, directory or stream occurred.
+ *
+ * @package Base
+ * @version //autogen//
+ */
+class ezcBaseFilePermissionException extends ezcBaseFileException
+{
+    /**
+     * Constructs a new ezcPropertyPermissionException for the property $name.
+     *
+     * @param string $name The name of the file.
+     * @param int    $mode The mode of the property that is allowed
+     *               (ezcBaseFileException::READ, ezcBaseFileException::WRITE,
+     *               ezcBaseFileException::EXECUTE or
+     *               ezcBaseFileException::CHANGE).
+     * @param string $message A string with extra information.
+     */
+    function __construct( $path, $mode, $message = null )
+    {
+        switch ( $mode )
+        {
+            case ezcBaseFileException::READ:
+                $operation = "The file <{$path}> can not be opened for 
reading";
+                break;
+            case ezcBaseFileException::WRITE:
+                $operation = "The file <{$path}> can not be opened for 
writing";
+                break;
+            case ezcBaseFileException::EXECUTE:
+                $operation = "The file <{$path}> can not be executed";
+                break;
+            case ezcBaseFileException::CHANGE:
+                $operation = "The permissions for <{$path}> can not be 
changed";
+                break;
+        }
+        
+        $messagePart = '';
+        if ( $message )
+        {
+            $messagePart = " ($message)";
+        }
+        
+        parent::__construct( "$operation.$messagePart" );
+    }
+}
+?>


Property changes on: packages/Base/trunk/src/exceptions/file_permission.php
___________________________________________________________________
Name: svn:eol-style
   + native

Deleted: packages/Base/trunk/src/exceptions/property_exception.php
===================================================================
--- packages/Base/trunk/src/exceptions/property_exception.php   2006-01-12 
16:09:13 UTC (rev 1791)
+++ packages/Base/trunk/src/exceptions/property_exception.php   2006-01-12 
16:12:56 UTC (rev 1792)
@@ -1,29 +0,0 @@
-<?php
-/**
- * File containing the ezcPropertyException class
- *
- * @package Base
- * @version //autogen//
- * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
- * @license http://ez.no/licenses/new_bsd New BSD License
- */
-/**
- * ezcBasePropertyException is thrown whenever a property is tried to be set
- * with an illegal value.
- *
- * @package Base
- * @version //autogen//
- */
-class ezcBasePropertyException extends ezcBaseException
-{
-    /**
-     * Constructs a new ezcBasePropertyException for the property $name for 
the value $value. 
-     * Optionally specify the $range you would have expected the parameter to 
be in.
-     */
-    function __construct( $name, $value, $range = null )
-    {
-        $rangePart = $range == NULL ? '' : " (expected <{$range}>)";
-        parent::__construct( "The value <{$value}> is illegal for the property 
<{$name}>$rangePart.", 0 );
-    }
-}
-?>

Added: packages/Base/trunk/src/exceptions/property_not_found.php
===================================================================
--- packages/Base/trunk/src/exceptions/property_not_found.php   2006-01-12 
16:09:13 UTC (rev 1791)
+++ packages/Base/trunk/src/exceptions/property_not_found.php   2006-01-12 
16:12:56 UTC (rev 1792)
@@ -0,0 +1,28 @@
+<?php
+/**
+ * File containing the ezcPropertyNotFoundException class
+ *
+ * @package Base
+ * @version //autogen//
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+/**
+ * ezcBasePropertyNotFoundException is thrown whenever a non existent property
+ * is accessed in the Components library.
+ *
+ * @package Base
+ * @version //autogen//
+ */
+class ezcBasePropertyNotFoundException extends ezcBaseException
+{
+    /**
+     * Constructs a new ezcPropertyNotFoundException for the property
+     * $name.
+     */
+    function __construct( $name )
+    {
+        parent::__construct( "No such property name <{$name}>." );
+    }
+}
+?>


Property changes on: packages/Base/trunk/src/exceptions/property_not_found.php
___________________________________________________________________
Name: svn:eol-style
   + native

Copied: packages/Base/trunk/src/exceptions/property_permission.php (from rev 
1763, packages/Base/trunk/src/exceptions/property_read_only_exception.php)
===================================================================
--- packages/Base/trunk/src/exceptions/property_read_only_exception.php 
2006-01-11 13:52:45 UTC (rev 1763)
+++ packages/Base/trunk/src/exceptions/property_permission.php  2006-01-12 
16:12:56 UTC (rev 1792)
@@ -0,0 +1,42 @@
+<?php
+/**
+ * File containing the ezcPropertyReadOnlyException class
+ *
+ * @package Base
+ * @version //autogen//
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+/**
+ * ezcBasePropertyPermissionException is thrown whenever a read-only property
+ * is tried to be changed, or when a write-only property was accessed for 
reading.
+ *
+ * @package Base
+ * @version //autogen//
+ */
+class ezcBasePropertyPermissionException extends ezcBaseException
+{
+    /**
+     * Used when the property is read-only.
+     */
+    const READ  = 1;
+    
+    /**
+     * Used when the property is write-only.
+     */
+    const WRITE = 2;
+
+    /**
+     * Constructs a new ezcPropertyPermissionException for the property $name.
+     *
+     * @param string $name The name of the property.
+     * @param int    $mode The mode of the property that is allowed (::READ or 
::WRITE).
+     */
+    function __construct( $name, $mode )
+    {
+        parent::__construct( "The property <{$name}> is " .
+            ( $mode == self::READ ? "read" : "write" ) .
+            "-only." );
+    }
+}
+?>

Deleted: packages/Base/trunk/src/exceptions/property_read_only_exception.php
===================================================================
--- packages/Base/trunk/src/exceptions/property_read_only_exception.php 
2006-01-12 16:09:13 UTC (rev 1791)
+++ packages/Base/trunk/src/exceptions/property_read_only_exception.php 
2006-01-12 16:12:56 UTC (rev 1792)
@@ -1,28 +0,0 @@
-<?php
-/**
- * File containing the ezcPropertyReadOnlyException class
- *
- * @package Base
- * @version //autogen//
- * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
- * @license http://ez.no/licenses/new_bsd New BSD License
- */
-/**
- * ezcBasePropertyReadOnlyException is thrown whenever a read-only property
- * is accessed in the Components library.
- *
- * @package Base
- * @version //autogen//
- */
-class ezcBasePropertyReadOnlyException extends ezcBaseException
-{
-    /**
-     * Constructs a new ezcPropertyReadOnlyException for the property
-     * $name.
-     */
-    function __construct( $name )
-    {
-        parent::__construct( "The property <{$name}> is read-only.", 0 );
-    }
-}
-?>

Copied: packages/Base/trunk/src/exceptions/setting_not_found.php (from rev 
1763, packages/Base/trunk/src/exceptions/config_exception.php)
===================================================================
--- packages/Base/trunk/src/exceptions/config_exception.php     2006-01-11 
13:52:45 UTC (rev 1763)
+++ packages/Base/trunk/src/exceptions/setting_not_found.php    2006-01-12 
16:12:56 UTC (rev 1792)
@@ -0,0 +1,28 @@
+<?php
+/**
+ * File containing the ezcBaseConfigException class.
+ *
+ * @package Base
+ * @version //autogen//
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+/**
+ * ezcBaseSettingNotFoundException is thrown whenever there is a name passed as
+ * part as the options array to setOptions() for an option that doesn't exist.
+ *
+ * @package Base
+ */
+class ezcBaseSettingNotFoundException extends ezcBaseException
+{
+    /**
+     * Constructs a new ezcBaseSettingNotFoundException for $settingName.
+     *
+     * @param string $settingName The name of the setting that does not exist.
+     */
+    function __construct( $settingName )
+    {
+        parent::__construct( "The setting <{$settingName}> is not a valid 
configuration setting." );
+    }
+}
+?>

Added: packages/Base/trunk/src/exceptions/setting_value.php
===================================================================
--- packages/Base/trunk/src/exceptions/setting_value.php        2006-01-12 
16:09:13 UTC (rev 1791)
+++ packages/Base/trunk/src/exceptions/setting_value.php        2006-01-12 
16:12:56 UTC (rev 1792)
@@ -0,0 +1,41 @@
+<?php
+/**
+ * File containing the ezcBaseConfigException class.
+ *
+ * @package Base
+ * @version //autogen//
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+/**
+ * ezcBaseSettingValueExeception is thrown whenever a value to a class'
+ * configuration option is either of the wrong type, or has a wrong value.
+ *
+ * @package Base
+ */
+class ezcBaseSettingValueException extends ezcBaseException
+{
+    /**
+     * Constructs a new ezcBaseConfigException
+     *
+     * @param string  $settingName The name of the setting where something was
+     *                wrong with.
+     * @param mixed   $value The value that the option was tried to be set too.
+     * @param string  $expectedValue A string explaining the allowed type and 
value range.
+     */
+    function __construct( $settingName, $value, $expectedValue = null )
+    {
+        $type = gettype( $value );
+        if ( in_array( $type, array( 'array', 'object', 'resource' ) ) )
+        {
+            $value = serialize( $value );
+        }
+        $msg = "The value <{$value}> that you were trying to assign to setting 
<{$settingName}> is invalid.";
+        if ( $expectedValue )
+        {
+            $msg .= " Allowed values are: " . $expectedValue;
+        }
+        parent::__construct( $msg );
+    }
+}
+?>


Property changes on: packages/Base/trunk/src/exceptions/setting_value.php
___________________________________________________________________
Name: svn:eol-style
   + native

Deleted: packages/Base/trunk/src/exceptions/type_exception.php
===================================================================
--- packages/Base/trunk/src/exceptions/type_exception.php       2006-01-12 
16:09:13 UTC (rev 1791)
+++ packages/Base/trunk/src/exceptions/type_exception.php       2006-01-12 
16:12:56 UTC (rev 1792)
@@ -1,27 +0,0 @@
-<?php
-/**
- * File containing the ezcBaseTypeException class.
- *
- * @package Base
- * @version //autogen//
- * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
- * @license http://ez.no/licenses/new_bsd New BSD License
- */
-/**
- * ezcBaseTypeException is thrown whenever the type of the given instance is 
not 
- * as expected.
- *
- * @package Base
- * @version //autogen//
- */
-class ezcBaseTypeException extends ezcBaseException
-{
-    /**
-     * Constructs a new ezcBaseTypeException on the 
-     */
-    function __construct( $expectedType, $gotType )
-    {
-        parent::__construct( "Expected type <{$expectedType}> but got type 
<{$gotType}> for argument." );
-    }
-}
-?>

Added: packages/Base/trunk/src/exceptions/value.php
===================================================================
--- packages/Base/trunk/src/exceptions/value.php        2006-01-12 16:09:13 UTC 
(rev 1791)
+++ packages/Base/trunk/src/exceptions/value.php        2006-01-12 16:12:56 UTC 
(rev 1792)
@@ -0,0 +1,42 @@
+<?php
+/**
+ * File containing the ezcBaseTypeException class.
+ *
+ * @package Base
+ * @version //autogen//
+ * @copyright Copyright (C) 2005, 2006 eZ systems as. All rights reserved.
+ * @license http://ez.no/licenses/new_bsd New BSD License
+ */
+/**
+ * ezcBaseValueException is thrown whenever the type or value of the given
+ * variable is not as expected.
+ *
+ * @package Base
+ * @version //autogen//
+ */
+class ezcBaseValueException extends ezcBaseException
+{
+    /**
+     * Constructs a new ezcBaseValueException on the $name variable.
+     *
+     * @param string  $settingName The name of the setting where something was
+     *                wrong with.
+     * @param mixed   $value The value that the option was tried to be set too.
+     * @param string  $expectedValue A string explaining the allowed type and 
value range.
+     */
+    function __construct( $settingName, $value, $expectedValue = null )
+    {
+        $type = gettype( $value );
+        if ( in_array( $type, array( 'array', 'object', 'resource' ) ) )
+        {
+            $value = serialize( $value );
+        }
+        $msg = "The value <{$value}> that you were trying to assign to setting 
<{$settingName}> is invalid.";
+        if ( $expectedValue )
+        {
+            $msg .= " Allowed values are: " . $expectedValue . '.';
+        }
+        parent::__construct( $msg );
+    }
+}
+?>


Property changes on: packages/Base/trunk/src/exceptions/value.php
___________________________________________________________________
Name: svn:eol-style
   + native

Copied: packages/Base/trunk/src/exceptions/value_exception.php (from rev 1763, 
packages/Base/trunk/src/exceptions/type_exception.php)

Modified: packages/Base/trunk/tests/base_test.php
===================================================================
--- packages/Base/trunk/tests/base_test.php     2006-01-12 16:09:13 UTC (rev 
1791)
+++ packages/Base/trunk/tests/base_test.php     2006-01-12 16:12:56 UTC (rev 
1792)
@@ -12,58 +12,222 @@
  */
 class ezcBaseTest extends ezcTestCase
 {
-    public function testAssertType()
+    public function testConfigExceptionUnknownSetting()
     {
-        $base = new ezcBase();
-        ezcBase::assertType( $base, "ezcBase" );
-        
         try
         {
-            $a = array();
-            ezcBase::assertType( $a, "ezcBase" );
-            $this->fail( "Expected an ezcBaseTypeException from 'array'" );
+            throw new ezcBaseSettingNotFoundException( 'broken' );
         }
-        catch ( ezcBaseTypeException $e)
+        catch ( ezcBaseSettingNotFoundException $e )
         {
-            $this->assertTrue( true );
+            $this->assertEquals( "The setting <broken> is not a valid 
configuration setting.", $e->getMessage() );
         }
+    }
 
+    public function testConfigExceptionOutOfRange1()
+    {
         try
         {
-            $baseTest = new ezcBaseTest();
-            ezcBase::assertType( $a, "ezcBase" );
-            $this->fail( "Expected an ezcBaseTypeException from 'ezcBaseTest'" 
);
+            throw new ezcBaseSettingValueException( 'broken', 42 );
         }
-        catch ( ezcBaseTypeException $e)
+        catch ( ezcBaseSettingValueException $e )
         {
-            $this->assertTrue( true );
+            $this->assertEquals( "The value <42> that you were trying to 
assign to setting <broken> is invalid.", $e->getMessage() );
         }
     }
 
-    public function testConfigExceptionUnknownSetting()
+    public function testConfigExceptionOutOfRange2()
     {
         try
         {
-            throw new ezcBaseConfigException( 'broken', 
ezcBaseConfigException::UNKNOWN_CONFIG_SETTING );
+            throw new ezcBaseSettingValueException( 'broken', 42, "40 to 48" );
         }
-        catch ( ezcBaseConfigException $e )
+        catch ( ezcBaseSettingValueException $e )
         {
-            $this->assertEquals( "The setting <broken> is not a valid 
configuration setting.", $e->getMessage() );
+            $this->assertEquals( "The value <42> that you were trying to 
assign to setting <broken> is invalid. Allowed values are: 40 to 48", 
$e->getMessage() );
         }
     }
 
-    public function testConfigExceptionOutOfRange()
+    public function testFileIoException1()
     {
         try
         {
-            throw new ezcBaseConfigException( 'broken', 
ezcBaseConfigException::VALUE_OUT_OF_RANGE, 42 );
+            throw new ezcBaseFileIoException( 'testfile.php', 
ezcBaseFileException::READ );
         }
-        catch ( ezcBaseConfigException $e )
+        catch ( ezcBaseFileIoException $e )
         {
-            $this->assertEquals( "The value <42> that you were trying to 
assign to setting <broken> is invalid.", $e->getMessage() );
+            $this->assertEquals( "An error occurred while reading from 
<testfile.php>.", $e->getMessage() );
         }
     }
 
+    public function testFileIoException2()
+    {
+        try
+        {
+            throw new ezcBaseFileIoException( 'testfile.php', 
ezcBaseFileException::WRITE );
+        }
+        catch ( ezcBaseFileIoException $e )
+        {
+            $this->assertEquals( "An error occurred while writing to 
<testfile.php>.", $e->getMessage() );
+        }
+    }
+
+    public function testFileIoException3()
+    {
+        try
+        {
+            throw new ezcBaseFileIoException( 'testfile.php', 
ezcBaseFileException::WRITE, "Extra extra" );
+        }
+        catch ( ezcBaseFileIoException $e )
+        {
+            $this->assertEquals( "An error occurred while writing to 
<testfile.php>. (Extra extra)", $e->getMessage() );
+        }
+    }
+
+    public function testFileNotFoundException1()
+    {
+        try
+        {
+            throw new ezcBaseFileNotFoundException( 'testfile.php' );
+        }
+        catch ( ezcBaseFileNotFoundException $e )
+        {
+            $this->assertEquals( "The file <testfile.php> could not be 
found.", $e->getMessage() );
+        }
+    }
+
+    public function testFileNotFoundException2()
+    {
+        try
+        {
+            throw new ezcBaseFileNotFoundException( 'testfile.php', 'INI' );
+        }
+        catch ( ezcBaseFileNotFoundException $e )
+        {
+            $this->assertEquals( "The INI file <testfile.php> could not be 
found.", $e->getMessage() );
+        }
+    }
+
+    public function testFileNotFoundException3()
+    {
+        try
+        {
+            throw new ezcBaseFileNotFoundException( 'testfile.php', 'INI', 
"Extra extra" );
+        }
+        catch ( ezcBaseFileNotFoundException $e )
+        {
+            $this->assertEquals( "The INI file <testfile.php> could not be 
found. (Extra extra)", $e->getMessage() );
+        }
+    }
+
+    public function testFilePermissionException1()
+    {
+        try
+        {
+            throw new ezcBaseFilePermissionException( 'testfile.php', 
ezcBaseFileException::READ );
+        }
+        catch ( ezcBaseFilePermissionException $e )
+        {
+            $this->assertEquals( "The file <testfile.php> can not be opened 
for reading.", $e->getMessage() );
+        }
+    }
+
+    public function testFilePermissionException2()
+    {
+        try
+        {
+            throw new ezcBaseFilePermissionException( 'testfile.php', 
ezcBaseFileException::WRITE );
+        }
+        catch ( ezcBaseFileException $e )
+        {
+            $this->assertEquals( "The file <testfile.php> can not be opened 
for writing.", $e->getMessage() );
+        }
+    }
+
+    public function testFilePermissionException3()
+    {
+        try
+        {
+            throw new ezcBaseFilePermissionException( 'testfile.php', 
ezcBaseFileException::EXECUTE );
+        }
+        catch ( ezcBaseException $e )
+        {
+            $this->assertEquals( "The file <testfile.php> can not be 
executed.", $e->getMessage() );
+        }
+    }
+
+    public function testFilePermissionException4()
+    {
+        try
+        {
+            throw new ezcBaseFilePermissionException( 'testfile.php', 
ezcBaseFilePermissionException::CHANGE, "Extra extra" );
+        }
+        catch ( ezcBaseException $e )
+        {
+            $this->assertEquals( "The permissions for <testfile.php> can not 
be changed. (Extra extra)", $e->getMessage() );
+        }
+    }
+
+    public function testPropertyNotFoundException()
+    {
+        try
+        {
+            throw new ezcBasePropertyNotFoundException( 'broken' );
+        }
+        catch ( ezcBasePropertyNotFoundException $e )
+        {
+            $this->assertEquals( "No such property name <broken>.", 
$e->getMessage() );
+        }
+    }
+
+    public function testPropertyPermissionException1()
+    {
+        try
+        {
+            throw new ezcBasePropertyPermissionException( 'broken', 
ezcBasePropertyPermissionException::READ );
+        }
+        catch ( ezcBaseException $e )
+        {
+            $this->assertEquals( "The property <broken> is read-only.", 
$e->getMessage() );
+        }
+    }
+
+    public function testPropertyPermissionException2()
+    {
+        try
+        {
+            throw new ezcBasePropertyPermissionException( 'broken', 
ezcBasePropertyPermissionException::WRITE );
+        }
+        catch ( ezcBaseException $e )
+        {
+            $this->assertEquals( "The property <broken> is write-only.", 
$e->getMessage() );
+        }
+    }
+
+    public function testBaseValue1()
+    {
+        try
+        {
+            throw new ezcBaseValueException( 'broken', array( 42 ) );
+        }
+        catch ( ezcBaseValueException $e )
+        {
+            $this->assertEquals( "The value <a:1:{i:0;i:42;}> that you were 
trying to assign to setting <broken> is invalid.", $e->getMessage() );
+        }
+    }
+
+    public function testBaseValue2()
+    {
+        try
+        {
+            throw new ezcBaseValueException( 'broken', "string", "strings" );
+        }
+        catch ( ezcBaseValueException $e )
+        {
+            $this->assertEquals( "The value <string> that you were trying to 
assign to setting <broken> is invalid. Allowed values are: strings.", 
$e->getMessage() );
+        }
+    }
+
     public static function suite()
     {
         return new ezcTestSuite("ezcBaseTest");

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

Reply via email to