From ed8b79529516fd1861b4f6e10380837c96ae4493 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Thu, 17 Jan 2013 19:55:10 -0500 Subject: [PATCH] renamed exception classes. --- framework/base/Application.php | 6 +++--- framework/base/BadCallException.php | 21 --------------------- framework/base/BadConfigException.php | 21 --------------------- framework/base/BadMethodException.php | 21 --------------------- framework/base/BadParamException.php | 21 --------------------- framework/base/BadPropertyException.php | 21 --------------------- framework/base/Component.php | 18 +++++++++--------- framework/base/Dictionary.php | 8 ++++---- framework/base/InvalidCallException.php | 21 +++++++++++++++++++++ framework/base/InvalidConfigException.php | 21 +++++++++++++++++++++ framework/base/Object.php | 18 +++++++++--------- framework/base/UnknownMethodException.php | 21 +++++++++++++++++++++ framework/base/UnknownPropertyException.php | 21 +++++++++++++++++++++ framework/base/Vector.php | 20 ++++++++++---------- framework/base/View.php | 8 ++++---- framework/db/ActiveRecord.php | 24 ++++++++++++------------ framework/db/ActiveRelation.php | 6 +++--- framework/db/DataReader.php | 6 +++--- framework/db/Schema.php | 6 +++--- framework/db/TableSchema.php | 6 +++--- framework/util/ArrayHelper.php | 8 +++++--- tests/unit/framework/base/ComponentTest.php | 6 +++--- tests/unit/framework/base/DictionaryTest.php | 4 ++-- tests/unit/framework/base/ObjectTest.php | 4 ++-- tests/unit/framework/base/VectorTest.php | 10 +++++----- 25 files changed, 164 insertions(+), 183 deletions(-) delete mode 100644 framework/base/BadCallException.php delete mode 100644 framework/base/BadConfigException.php delete mode 100644 framework/base/BadMethodException.php delete mode 100644 framework/base/BadParamException.php delete mode 100644 framework/base/BadPropertyException.php create mode 100644 framework/base/InvalidCallException.php create mode 100644 framework/base/InvalidConfigException.php create mode 100644 framework/base/UnknownMethodException.php create mode 100644 framework/base/UnknownPropertyException.php diff --git a/framework/base/Application.php b/framework/base/Application.php index 892e51f..e945160 100644 --- a/framework/base/Application.php +++ b/framework/base/Application.php @@ -9,7 +9,7 @@ namespace yii\base; -use yii\base\Exception; +use yii\base\InvalidCallException; /** * Application is the base class for all application classes. @@ -236,13 +236,13 @@ class Application extends Module /** * Sets the directory that stores runtime files. * @param string $path the directory that stores runtime files. - * @throws BadParamException if the directory does not exist or is not writable + * @throws InvalidCallException if the directory does not exist or is not writable */ public function setRuntimePath($path) { $p = \Yii::getAlias($path); if ($p === false || !is_dir($p) || !is_writable($path)) { - throw new BadParamException("Application runtime path \"$path\" is invalid. Please make sure it is a directory writable by the Web server process."); + throw new InvalidCallException("Application runtime path \"$path\" is invalid. Please make sure it is a directory writable by the Web server process."); } else { $this->_runtimePath = $p; } diff --git a/framework/base/BadCallException.php b/framework/base/BadCallException.php deleted file mode 100644 index 35c0b4a..0000000 --- a/framework/base/BadCallException.php +++ /dev/null @@ -1,21 +0,0 @@ - - * @since 2.0 - */ -class BadCallException extends \Exception -{ -} - diff --git a/framework/base/BadConfigException.php b/framework/base/BadConfigException.php deleted file mode 100644 index f9c0ffb..0000000 --- a/framework/base/BadConfigException.php +++ /dev/null @@ -1,21 +0,0 @@ - - * @since 2.0 - */ -class BadConfigException extends \Exception -{ -} - diff --git a/framework/base/BadMethodException.php b/framework/base/BadMethodException.php deleted file mode 100644 index aa5414b..0000000 --- a/framework/base/BadMethodException.php +++ /dev/null @@ -1,21 +0,0 @@ - - * @since 2.0 - */ -class BadMethodException extends \Exception -{ -} - diff --git a/framework/base/BadParamException.php b/framework/base/BadParamException.php deleted file mode 100644 index e711df1..0000000 --- a/framework/base/BadParamException.php +++ /dev/null @@ -1,21 +0,0 @@ - - * @since 2.0 - */ -class BadParamException extends \Exception -{ -} - diff --git a/framework/base/BadPropertyException.php b/framework/base/BadPropertyException.php deleted file mode 100644 index 7161e82..0000000 --- a/framework/base/BadPropertyException.php +++ /dev/null @@ -1,21 +0,0 @@ - - * @since 2.0 - */ -class BadPropertyException extends \Exception -{ -} - diff --git a/framework/base/Component.php b/framework/base/Component.php index 9c97894..fe959f8 100644 --- a/framework/base/Component.php +++ b/framework/base/Component.php @@ -42,7 +42,7 @@ class Component extends \yii\base\Object * @param string $name the property name * @return mixed the property value, event handlers attached to the event, * the behavior, or the value of a behavior's property - * @throws BadPropertyException if the property is not defined + * @throws UnknownPropertyException if the property is not defined * @see __set */ public function __get($name) @@ -60,7 +60,7 @@ class Component extends \yii\base\Object } } } - throw new BadPropertyException('Getting unknown property: ' . get_class($this) . '.' . $name); + throw new UnknownPropertyException('Getting unknown property: ' . get_class($this) . '.' . $name); } /** @@ -76,7 +76,7 @@ class Component extends \yii\base\Object * will be implicitly called when executing `$component->property = $value;`. * @param string $name the property name or the event name * @param mixed $value the property value - * @throws BadPropertyException if the property is not defined or read-only. + * @throws UnknownPropertyException if the property is not defined or read-only. * @see __get */ public function __set($name, $value) @@ -106,9 +106,9 @@ class Component extends \yii\base\Object } } if (method_exists($this, 'get' . $name)) { - throw new BadPropertyException('Setting read-only property: ' . get_class($this) . '.' . $name); + throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '.' . $name); } else { - throw new BadPropertyException('Setting unknown property: ' . get_class($this) . '.' . $name); + throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '.' . $name); } } @@ -151,7 +151,7 @@ class Component extends \yii\base\Object * Do not call this method directly as it is a PHP magic method that * will be implicitly called when executing `unset($component->property)`. * @param string $name the property name - * @throws BadPropertyException if the property is read only. + * @throws UnknownPropertyException if the property is read only. */ public function __unset($name) { @@ -170,7 +170,7 @@ class Component extends \yii\base\Object } } if (method_exists($this, 'get' . $name)) { - throw new BadPropertyException('Unsetting read-only property: ' . get_class($this) . '.' . $name); + throw new InvalidCallException('Unsetting read-only property: ' . get_class($this) . '.' . $name); } } @@ -186,7 +186,7 @@ class Component extends \yii\base\Object * @param string $name the method name * @param array $params method parameters * @return mixed the method return value - * @throws BadMethodException when calling unknown method + * @throws UnknownMethodException when calling unknown method */ public function __call($name, $params) { @@ -205,7 +205,7 @@ class Component extends \yii\base\Object } } - throw new BadMethodException('Calling unknown method: ' . get_class($this) . "::$name()"); + throw new UnknownMethodException('Calling unknown method: ' . get_class($this) . "::$name()"); } /** diff --git a/framework/base/Dictionary.php b/framework/base/Dictionary.php index 3f551c4..cc61886 100644 --- a/framework/base/Dictionary.php +++ b/framework/base/Dictionary.php @@ -184,7 +184,7 @@ class Dictionary extends Object implements \IteratorAggregate, \ArrayAccess, \Co * Copies iterable data into the dictionary. * Note, existing data in the dictionary will be cleared first. * @param mixed $data the data to be copied from, must be an array or an object implementing `Traversable` - * @throws BadParamException if data is neither an array nor an iterator. + * @throws InvalidCallException if data is neither an array nor an iterator. */ public function copyFrom($data) { @@ -199,7 +199,7 @@ class Dictionary extends Object implements \IteratorAggregate, \ArrayAccess, \Co $this->add($key, $value); } } else { - throw new BadParamException('Data must be either an array or an object implementing Traversable.'); + throw new InvalidCallException('Data must be either an array or an object implementing Traversable.'); } } @@ -216,7 +216,7 @@ class Dictionary extends Object implements \IteratorAggregate, \ArrayAccess, \Co * * @param array|\Traversable $data the data to be merged with. It must be an array or object implementing Traversable * @param boolean $recursive whether the merging should be recursive. - * @throws BadParamException if data is neither an array nor an object implementing `Traversable`. + * @throws InvalidCallException if data is neither an array nor an object implementing `Traversable`. */ public function mergeWith($data, $recursive = true) { @@ -240,7 +240,7 @@ class Dictionary extends Object implements \IteratorAggregate, \ArrayAccess, \Co } } } else { - throw new BadParamException('The data to be merged with must be an array or an object implementing Traversable.'); + throw new InvalidCallException('The data to be merged with must be an array or an object implementing Traversable.'); } } diff --git a/framework/base/InvalidCallException.php b/framework/base/InvalidCallException.php new file mode 100644 index 0000000..24e7b6e --- /dev/null +++ b/framework/base/InvalidCallException.php @@ -0,0 +1,21 @@ + + * @since 2.0 + */ +class InvalidCallException extends \Exception +{ +} + diff --git a/framework/base/InvalidConfigException.php b/framework/base/InvalidConfigException.php new file mode 100644 index 0000000..5256d7e --- /dev/null +++ b/framework/base/InvalidConfigException.php @@ -0,0 +1,21 @@ + + * @since 2.0 + */ +class InvalidConfigException extends \Exception +{ +} + diff --git a/framework/base/Object.php b/framework/base/Object.php index 113cce3..ddfe36b 100644 --- a/framework/base/Object.php +++ b/framework/base/Object.php @@ -58,7 +58,7 @@ class Object * @param string $name the property name * @return mixed the property value, event handlers attached to the event, * the named behavior, or the value of a behavior's property - * @throws BadPropertyException if the property is not defined + * @throws UnknownPropertyException if the property is not defined * @see __set */ public function __get($name) @@ -67,7 +67,7 @@ class Object if (method_exists($this, $getter)) { return $this->$getter(); } else { - throw new BadPropertyException('Getting unknown property: ' . get_class($this) . '.' . $name); + throw new UnknownPropertyException('Getting unknown property: ' . get_class($this) . '.' . $name); } } @@ -78,7 +78,7 @@ class Object * will be implicitly called when executing `$object->property = $value;`. * @param string $name the property name or the event name * @param mixed $value the property value - * @throws BadPropertyException if the property is not defined or read-only. + * @throws UnknownPropertyException if the property is not defined or read-only. * @see __get */ public function __set($name, $value) @@ -87,9 +87,9 @@ class Object if (method_exists($this, $setter)) { $this->$setter($value); } elseif (method_exists($this, 'get' . $name)) { - throw new BadPropertyException('Setting read-only property: ' . get_class($this) . '.' . $name); + throw new InvalidCallException('Setting read-only property: ' . get_class($this) . '.' . $name); } else { - throw new BadPropertyException('Setting unknown property: ' . get_class($this) . '.' . $name); + throw new UnknownPropertyException('Setting unknown property: ' . get_class($this) . '.' . $name); } } @@ -122,7 +122,7 @@ class Object * Note that if the property is not defined, this method will do nothing. * If the property is read-only, it will throw an exception. * @param string $name the property name - * @throws BadPropertyException if the property is read only. + * @throws UnknownPropertyException if the property is read only. */ public function __unset($name) { @@ -130,7 +130,7 @@ class Object if (method_exists($this, $setter)) { $this->$setter(null); } elseif (method_exists($this, 'get' . $name)) { - throw new BadPropertyException('Unsetting read-only property: ' . get_class($this) . '.' . $name); + throw new InvalidCallException('Unsetting read-only property: ' . get_class($this) . '.' . $name); } } @@ -143,7 +143,7 @@ class Object * will be implicitly called when an unknown method is being invoked. * @param string $name the method name * @param array $params method parameters - * @throws BadMethodException when calling unknown method + * @throws UnknownMethodException when calling unknown method * @return mixed the method return value */ public function __call($name, $params) @@ -155,7 +155,7 @@ class Object return call_user_func_array($func, $params); } } - throw new BadMethodException('Unknown method: ' . get_class($this) . "::$name()"); + throw new UnknownMethodException('Unknown method: ' . get_class($this) . "::$name()"); } /** diff --git a/framework/base/UnknownMethodException.php b/framework/base/UnknownMethodException.php new file mode 100644 index 0000000..8667d24 --- /dev/null +++ b/framework/base/UnknownMethodException.php @@ -0,0 +1,21 @@ + + * @since 2.0 + */ +class UnknownMethodException extends \Exception +{ +} + diff --git a/framework/base/UnknownPropertyException.php b/framework/base/UnknownPropertyException.php new file mode 100644 index 0000000..69581f9 --- /dev/null +++ b/framework/base/UnknownPropertyException.php @@ -0,0 +1,21 @@ + + * @since 2.0 + */ +class UnknownPropertyException extends \Exception +{ +} + diff --git a/framework/base/Vector.php b/framework/base/Vector.php index 931ee9e..c271ccc 100644 --- a/framework/base/Vector.php +++ b/framework/base/Vector.php @@ -101,7 +101,7 @@ class Vector extends Object implements \IteratorAggregate, \ArrayAccess, \Counta * Returns the item at the specified index. * @param integer $index the index of the item * @return mixed the item at the index - * @throws BadParamException if the index is out of range + * @throws InvalidCallException if the index is out of range */ public function itemAt($index) { @@ -110,7 +110,7 @@ class Vector extends Object implements \IteratorAggregate, \ArrayAccess, \Counta } elseif ($index >= 0 && $index < $this->_c) { // in case the value is null return $this->_d[$index]; } else { - throw new BadParamException('Index out of range: ' . $index); + throw new InvalidCallException('Index out of range: ' . $index); } } @@ -132,7 +132,7 @@ class Vector extends Object implements \IteratorAggregate, \ArrayAccess, \Counta * one step towards the end. * @param integer $index the specified position. * @param mixed $item new item to be inserted into the vector - * @throws BadParamException if the index specified is out of range, or the vector is read-only. + * @throws InvalidCallException if the index specified is out of range, or the vector is read-only. */ public function insertAt($index, $item) { @@ -142,7 +142,7 @@ class Vector extends Object implements \IteratorAggregate, \ArrayAccess, \Counta array_splice($this->_d, $index, 0, array($item)); $this->_c++; } else { - throw new BadParamException('Index out of range: ' . $index); + throw new InvalidCallException('Index out of range: ' . $index); } } @@ -169,7 +169,7 @@ class Vector extends Object implements \IteratorAggregate, \ArrayAccess, \Counta * Removes an item at the specified position. * @param integer $index the index of the item to be removed. * @return mixed the removed item. - * @throws BadParamException if the index is out of range, or the vector is read only. + * @throws InvalidCallException if the index is out of range, or the vector is read only. */ public function removeAt($index) { @@ -183,7 +183,7 @@ class Vector extends Object implements \IteratorAggregate, \ArrayAccess, \Counta return $item; } } else { - throw new BadParamException('Index out of range: ' . $index); + throw new InvalidCallException('Index out of range: ' . $index); } } @@ -242,7 +242,7 @@ class Vector extends Object implements \IteratorAggregate, \ArrayAccess, \Counta * Copies iterable data into the vector. * Note, existing data in the vector will be cleared first. * @param mixed $data the data to be copied from, must be an array or an object implementing `Traversable` - * @throws BadParamException if data is neither an array nor an object implementing `Traversable`. + * @throws InvalidCallException if data is neither an array nor an object implementing `Traversable`. */ public function copyFrom($data) { @@ -257,7 +257,7 @@ class Vector extends Object implements \IteratorAggregate, \ArrayAccess, \Counta $this->add($item); } } else { - throw new BadParamException('Data must be either an array or an object implementing Traversable.'); + throw new InvalidCallException('Data must be either an array or an object implementing Traversable.'); } } @@ -265,7 +265,7 @@ class Vector extends Object implements \IteratorAggregate, \ArrayAccess, \Counta * Merges iterable data into the vector. * New items will be appended to the end of the existing items. * @param array|\Traversable $data the data to be merged with. It must be an array or object implementing Traversable - * @throws BadParamException if data is neither an array nor an object implementing `Traversable`. + * @throws InvalidCallException if data is neither an array nor an object implementing `Traversable`. */ public function mergeWith($data) { @@ -277,7 +277,7 @@ class Vector extends Object implements \IteratorAggregate, \ArrayAccess, \Counta $this->add($item); } } else { - throw new BadParamException('The data to be merged with must be an array or an object implementing Traversable.'); + throw new InvalidCallException('The data to be merged with must be an array or an object implementing Traversable.'); } } diff --git a/framework/base/View.php b/framework/base/View.php index a721ef7..db0741a 100644 --- a/framework/base/View.php +++ b/framework/base/View.php @@ -105,7 +105,7 @@ class View extends Component * @param array $params the parameters that should be made available in the view. The PHP function `extract()` * will be called on this variable to extract the variables from this parameter. * @return string the rendering result - * @throws BadParamException if the view file cannot be found + * @throws InvalidCallException if the view file cannot be found */ public function renderPartial($view, $params = array()) { @@ -113,7 +113,7 @@ class View extends Component if ($file !== false) { return $this->renderFile($file, $params); } else { - throw new BadParamException("Unable to find the view file for view '$view'."); + throw new InvalidCallException("Unable to find the view file for view '$view'."); } } @@ -416,7 +416,7 @@ class View extends Component * The themed layout file will be returned if theme is enabled and the theme contains such a layout file. * * @return string|boolean the layout file path, or false if the context does not need layout. - * @throws BadParamException if the layout file cannot be found + * @throws InvalidCallException if the layout file cannot be found */ public function findLayoutFile() { @@ -454,7 +454,7 @@ class View extends Component } } if ($file === false || !is_file($file)) { - throw new BadParamException("Unable to find the layout file for layout '{$module->layout}' (specified by " . get_class($module) . ")"); + throw new InvalidCallException("Unable to find the layout file for layout '{$module->layout}' (specified by " . get_class($module) . ")"); } elseif ($this->localizeView) { return FileHelper::localize($file, $this->language, $this->sourceLanguage); } else { diff --git a/framework/db/ActiveRecord.php b/framework/db/ActiveRecord.php index 7568934..4647067 100644 --- a/framework/db/ActiveRecord.php +++ b/framework/db/ActiveRecord.php @@ -12,8 +12,8 @@ namespace yii\db; use yii\base\Model; use yii\base\ModelEvent; -use yii\base\BadMethodException; -use yii\base\BadParamException; +use yii\base\UnknownMethodException; +use yii\base\InvalidCallException; use yii\db\Connection; use yii\db\TableSchema; use yii\db\Expression; @@ -991,7 +991,7 @@ class ActiveRecord extends Model * It can be declared in either the Active Record class itself or one of its behaviors. * @param string $name the relation name * @return ActiveRelation the relation object - * @throws BadParamException if the named relation does not exist. + * @throws InvalidCallException if the named relation does not exist. */ public function getRelation($name) { @@ -1001,9 +1001,9 @@ class ActiveRecord extends Model if ($relation instanceof ActiveRelation) { return $relation; } - } catch (BadMethodException $e) { + } catch (UnknownMethodException $e) { } - throw new BadParamException(get_class($this) . ' has no relation named "' . $name . '".'); + throw new InvalidCallException(get_class($this) . ' has no relation named "' . $name . '".'); } /** @@ -1023,7 +1023,7 @@ class ActiveRecord extends Model * @param array $extraColumns additional column values to be saved into the pivot table. * This parameter is only meaningful for a relationship involving a pivot table * (i.e., a relation set with `[[ActiveRelation::via()]]` or `[[ActiveRelation::viaTable()]]`.) - * @throws BadParamException if the method is unable to link two models. + * @throws InvalidCallException if the method is unable to link two models. */ public function link($name, $model, $extraColumns = array()) { @@ -1059,7 +1059,7 @@ class ActiveRecord extends Model $p2 = $this->isPrimaryKey(array_values($relation->link)); if ($p1 && $p2) { if ($this->getIsNewRecord() && $model->getIsNewRecord()) { - throw new BadParamException('Unable to link models: both models are newly created.'); + throw new InvalidCallException('Unable to link models: both models are newly created.'); } elseif ($this->getIsNewRecord()) { $this->bindModels(array_flip($relation->link), $this, $model); } else { @@ -1070,7 +1070,7 @@ class ActiveRecord extends Model } elseif ($p2) { $this->bindModels($relation->link, $model, $this); } else { - throw new BadParamException('Unable to link models: the link does not involve any primary key.'); + throw new InvalidCallException('Unable to link models: the link does not involve any primary key.'); } } @@ -1098,7 +1098,7 @@ class ActiveRecord extends Model * @param boolean $delete whether to delete the model that contains the foreign key. * If false, the model's foreign key will be set null and saved. * If true, the model containing the foreign key will be deleted. - * @throws BadParamException if the models cannot be unlinked + * @throws InvalidCallException if the models cannot be unlinked */ public function unlink($name, $model, $delete = false) { @@ -1147,7 +1147,7 @@ class ActiveRecord extends Model } $delete ? $this->delete() : $this->save(false); } else { - throw new BadParamException('Unable to unlink models: the link does not involve any primary key.'); + throw new InvalidCallException('Unable to unlink models: the link does not involve any primary key.'); } } @@ -1186,14 +1186,14 @@ class ActiveRecord extends Model * @param array $link * @param ActiveRecord $foreignModel * @param ActiveRecord $primaryModel - * @throws BadParamException + * @throws InvalidCallException */ private function bindModels($link, $foreignModel, $primaryModel) { foreach ($link as $fk => $pk) { $value = $primaryModel->$pk; if ($value === null) { - throw new BadParamException('Unable to link models: the primary key of ' . get_class($primaryModel) . ' is null.'); + throw new InvalidCallException('Unable to link models: the primary key of ' . get_class($primaryModel) . ' is null.'); } $foreignModel->$fk = $value; } diff --git a/framework/db/ActiveRelation.php b/framework/db/ActiveRelation.php index bae81b2..26af7d1 100644 --- a/framework/db/ActiveRelation.php +++ b/framework/db/ActiveRelation.php @@ -12,7 +12,7 @@ namespace yii\db; use yii\db\Connection; use yii\db\Command; -use yii\base\BadParamException; +use yii\base\InvalidConfigException; /** * ActiveRelation represents a relation between two Active Record classes. @@ -137,12 +137,12 @@ class ActiveRelation extends ActiveQuery * @param string $name the relation name * @param array $primaryModels primary models * @return array the related models - * @throws BadParamException + * @throws InvalidConfigException */ public function findWith($name, &$primaryModels) { if (!is_array($this->link)) { - throw new BadParamException('Invalid link: it must be an array of key-value pairs.'); + throw new InvalidConfigException('Invalid link: it must be an array of key-value pairs.'); } if ($this->via instanceof self) { diff --git a/framework/db/DataReader.php b/framework/db/DataReader.php index a5be116..8e5291e 100644 --- a/framework/db/DataReader.php +++ b/framework/db/DataReader.php @@ -9,7 +9,7 @@ namespace yii\db; -use yii\base\BadCallException; +use yii\base\InvalidCallException; /** * DataReader represents a forward-only stream of rows from a query result set. @@ -212,7 +212,7 @@ class DataReader extends \yii\base\Object implements \Iterator, \Countable /** * Resets the iterator to the initial state. * This method is required by the interface Iterator. - * @throws BadCallException if this method is invoked twice + * @throws InvalidCallException if this method is invoked twice */ public function rewind() { @@ -220,7 +220,7 @@ class DataReader extends \yii\base\Object implements \Iterator, \Countable $this->_row = $this->_statement->fetch(); $this->_index = 0; } else { - throw new BadCallException('DataReader cannot rewind. It is a forward-only reader.'); + throw new InvalidCallException('DataReader cannot rewind. It is a forward-only reader.'); } } diff --git a/framework/db/Schema.php b/framework/db/Schema.php index a02ec28..bb4352a 100644 --- a/framework/db/Schema.php +++ b/framework/db/Schema.php @@ -10,7 +10,7 @@ namespace yii\db; use yii\base\NotSupportedException; -use yii\base\BadCallException; +use yii\base\InvalidCallException; /** * Schema is the base class for concrete DBMS-specific schema classes. @@ -205,7 +205,7 @@ abstract class Schema extends \yii\base\Object * Returns the ID of the last inserted row or sequence value. * @param string $sequenceName name of the sequence object (required by some DBMS) * @return string the row ID of the last row inserted, or the last value retrieved from the sequence object - * @throws BadCallException if the DB connection is not active + * @throws InvalidCallException if the DB connection is not active * @see http://www.php.net/manual/en/function.PDO-lastInsertId.php */ public function getLastInsertID($sequenceName = '') @@ -213,7 +213,7 @@ abstract class Schema extends \yii\base\Object if ($this->connection->isActive) { return $this->connection->pdo->lastInsertId($sequenceName); } else { - throw new BadCallException('DB Connection is not active.'); + throw new InvalidCallException('DB Connection is not active.'); } } diff --git a/framework/db/TableSchema.php b/framework/db/TableSchema.php index 344a68d..f3413bf 100644 --- a/framework/db/TableSchema.php +++ b/framework/db/TableSchema.php @@ -9,7 +9,7 @@ namespace yii\db; -use yii\base\BadParamException; +use yii\base\InvalidCallException; /** * TableSchema represents the metadata of a database table. @@ -87,7 +87,7 @@ class TableSchema extends \yii\base\Object /** * Manually specifies the primary key for this table. * @param string|array $keys the primary key (can be composite) - * @throws BadParamException if the specified key cannot be found in the table. + * @throws InvalidCallException if the specified key cannot be found in the table. */ public function fixPrimaryKey($keys) { @@ -102,7 +102,7 @@ class TableSchema extends \yii\base\Object if (isset($this->columns[$key])) { $this->columns[$key]->isPrimaryKey = true; } else { - throw new BadParamException("Primary key '$key' cannot be found in table '{$this->name}'."); + throw new InvalidCallException("Primary key '$key' cannot be found in table '{$this->name}'."); } } } diff --git a/framework/util/ArrayHelper.php b/framework/util/ArrayHelper.php index e068cbf..c14121b 100644 --- a/framework/util/ArrayHelper.php +++ b/framework/util/ArrayHelper.php @@ -9,6 +9,8 @@ namespace yii\util; +use yii\base\InvalidCallException; + /** * ArrayHelper provides additional array functionality you can use in your * application. @@ -240,7 +242,7 @@ class ArrayHelper * value is for sorting strings in case-insensitive manner. Please refer to * See [PHP manual](http://php.net/manual/en/function.sort.php) for more details. * When sorting by multiple keys with different sort flags, use an array of sort flags. - * @throws \yii\base\BadParamException if the $ascending or $sortFlag parameters do not have + * @throws InvalidCallException if the $ascending or $sortFlag parameters do not have * correct number of elements as that of $key. */ public static function multisort(&$array, $key, $ascending = true, $sortFlag = SORT_REGULAR) @@ -253,12 +255,12 @@ class ArrayHelper if (is_scalar($ascending)) { $ascending = array_fill(0, $n, $ascending); } elseif (count($ascending) !== $n) { - throw new \yii\base\BadParamException('The length of $ascending parameter must be the same as that of $keys.'); + throw new InvalidCallException('The length of $ascending parameter must be the same as that of $keys.'); } if (is_scalar($sortFlag)) { $sortFlag = array_fill(0, $n, $sortFlag); } elseif (count($sortFlag) !== $n) { - throw new \yii\base\BadParamException('The length of $ascending parameter must be the same as that of $keys.'); + throw new InvalidCallException('The length of $ascending parameter must be the same as that of $keys.'); } $args = array(); foreach ($keys as $i => $key) { diff --git a/tests/unit/framework/base/ComponentTest.php b/tests/unit/framework/base/ComponentTest.php index 2d95778..3a4bab2 100644 --- a/tests/unit/framework/base/ComponentTest.php +++ b/tests/unit/framework/base/ComponentTest.php @@ -64,7 +64,7 @@ class ComponentTest extends \yiiunit\TestCase public function testGetProperty() { $this->assertTrue('default' === $this->component->Text); - $this->setExpectedException('yii\base\BadPropertyException'); + $this->setExpectedException('yii\base\UnknownPropertyException'); $value2 = $this->component->Caption; } @@ -73,7 +73,7 @@ class ComponentTest extends \yiiunit\TestCase $value = 'new value'; $this->component->Text = $value; $this->assertEquals($value, $this->component->Text); - $this->setExpectedException('yii\base\BadPropertyException'); + $this->setExpectedException('yii\base\UnknownPropertyException'); $this->component->NewMember = $value; } @@ -182,7 +182,7 @@ class ComponentTest extends \yiiunit\TestCase $this->assertSame($behavior, $component->detachBehavior('a')); $this->assertFalse($component->hasProperty('p')); - $this->setExpectedException('yii\base\BadMethodException'); + $this->setExpectedException('yii\base\UnknownMethodException'); $component->test(); $p = 'as b'; diff --git a/tests/unit/framework/base/DictionaryTest.php b/tests/unit/framework/base/DictionaryTest.php index fc84dd8..7828300 100644 --- a/tests/unit/framework/base/DictionaryTest.php +++ b/tests/unit/framework/base/DictionaryTest.php @@ -95,7 +95,7 @@ class DictionaryTest extends \yiiunit\TestCase $this->assertEquals($this->item3, $this->dictionary['key3']); $this->assertEquals($this->item1, $this->dictionary['key4']); - $this->setExpectedException('yii\base\BadParamException'); + $this->setExpectedException('yii\base\InvalidCallException'); $this->dictionary->copyFrom($this); } @@ -114,7 +114,7 @@ class DictionaryTest extends \yiiunit\TestCase $this->assertEquals(3,$this->dictionary->getCount()); $this->assertEquals($this->item1,$this->dictionary['key2']); $this->assertEquals($this->item3,$this->dictionary['key3']); - $this->setExpectedException('yii\base\BadParamException'); + $this->setExpectedException('yii\base\InvalidCallException'); $this->dictionary->mergeWith($this,false); } diff --git a/tests/unit/framework/base/ObjectTest.php b/tests/unit/framework/base/ObjectTest.php index b7731bc..f93b4af 100644 --- a/tests/unit/framework/base/ObjectTest.php +++ b/tests/unit/framework/base/ObjectTest.php @@ -56,7 +56,7 @@ class ObjectTest extends \yiiunit\TestCase public function testGetProperty() { $this->assertTrue('default' === $this->object->Text); - $this->setExpectedException('yii\base\BadPropertyException'); + $this->setExpectedException('yii\base\UnknownPropertyException'); $value2 = $this->object->Caption; } @@ -65,7 +65,7 @@ class ObjectTest extends \yiiunit\TestCase $value = 'new value'; $this->object->Text = $value; $this->assertEquals($value, $this->object->Text); - $this->setExpectedException('yii\base\BadPropertyException'); + $this->setExpectedException('yii\base\UnknownPropertyException'); $this->object->NewMember = $value; } diff --git a/tests/unit/framework/base/VectorTest.php b/tests/unit/framework/base/VectorTest.php index 5943479..f7fadfd 100644 --- a/tests/unit/framework/base/VectorTest.php +++ b/tests/unit/framework/base/VectorTest.php @@ -65,7 +65,7 @@ class VectorTest extends \yiiunit\TestCase $this->assertEquals(2,$this->vector->indexOf($this->item2)); $this->assertEquals(0,$this->vector->indexOf($this->item3)); $this->assertEquals(1,$this->vector->indexOf($this->item1)); - $this->setExpectedException('yii\base\BadParamException'); + $this->setExpectedException('yii\base\InvalidCallException'); $this->vector->insertAt(4,$this->item3); } @@ -87,7 +87,7 @@ class VectorTest extends \yiiunit\TestCase $this->assertEquals(-1,$this->vector->indexOf($this->item2)); $this->assertEquals(1,$this->vector->indexOf($this->item3)); $this->assertEquals(0,$this->vector->indexOf($this->item1)); - $this->setExpectedException('yii\base\BadParamException'); + $this->setExpectedException('yii\base\InvalidCallException'); $this->vector->removeAt(2); } @@ -118,7 +118,7 @@ class VectorTest extends \yiiunit\TestCase $array=array($this->item3,$this->item1); $this->vector->copyFrom($array); $this->assertTrue(count($array)==2 && $this->vector[0]===$this->item3 && $this->vector[1]===$this->item1); - $this->setExpectedException('yii\base\BadParamException'); + $this->setExpectedException('yii\base\InvalidCallException'); $this->vector->copyFrom($this); } @@ -127,7 +127,7 @@ class VectorTest extends \yiiunit\TestCase $array=array($this->item3,$this->item1); $this->vector->mergeWith($array); $this->assertTrue($this->vector->getCount()==4 && $this->vector[0]===$this->item1 && $this->vector[3]===$this->item1); - $this->setExpectedException('yii\base\BadParamException'); + $this->setExpectedException('yii\base\InvalidCallException'); $this->vector->mergeWith($this); } @@ -141,7 +141,7 @@ class VectorTest extends \yiiunit\TestCase { $this->assertTrue($this->vector[0]===$this->item1); $this->assertTrue($this->vector[1]===$this->item2); - $this->setExpectedException('yii\base\BadParamException'); + $this->setExpectedException('yii\base\InvalidCallException'); $a=$this->vector[2]; }