diff --git a/src/YiiFactoryGirl/Factory.php b/src/YiiFactoryGirl/Factory.php index 6f84b26..c8ee43a 100644 --- a/src/YiiFactoryGirl/Factory.php +++ b/src/YiiFactoryGirl/Factory.php @@ -4,6 +4,8 @@ class Factory extends \CApplicationComponent { + const LOG_CATEGORY = 'yii-factory-girl'; + /** * @var string the name of the initialization script that would be executed before the whole test set runs. * Defaults to 'init.php'. If the script does not exist, every table with a factory file will be reset. @@ -71,7 +73,7 @@ public function getDbConnection() if ($this->_db === null) { $this->_db = \Yii::app()->getComponent($this->connectionID); if (!$this->_db instanceof \CDbConnection) { - throw new \CException(\Yii::t('yii-factory-girl', '\YiiFactoryGirl\Factory.connectionID "{id}" is invalid. Please make sure it refers to the ID of a CDbConnection application component.', + throw new \CException(\Yii::t(self::LOG_CATEGORY, '\YiiFactoryGirl\Factory.connectionID "{id}" is invalid. Please make sure it refers to the ID of a CDbConnection application component.', array('{id}' => $this->connectionID))); } } @@ -212,6 +214,7 @@ public function truncateTables($schema = '') * @param array $args * @param null $alias * @return \CActiveRecord + * @throws FactoryException */ public function build($class, array $args = array(), $alias = null) { @@ -228,7 +231,7 @@ public function build($class, array $args = array(), $alias = null) $property->setAccessible(true); $property->setValue($value); } else { - throw new FactoryException(\Yii::t('yii-factory-girl', 'Unknown attribute "{attr} for class {class}.', array( + throw new FactoryException(\Yii::t(self::LOG_CATEGORY, 'Unknown attribute "{attr} for class {class}.', array( '{attr}' => $key, '{class}' => $class ))); @@ -304,7 +307,7 @@ public function getFactoryData($class) { throw new \CException("Bad param"); } } catch (\CException $e) { - throw new FactoryException(\Yii::t('yii-factory-girl', 'There is no {class} class loaded.', array( + throw new FactoryException(\Yii::t(self::LOG_CATEGORY, 'There is no {class} class loaded.', array( '{class}' => $class, ))); } diff --git a/src/YiiFactoryGirl/FactoryData.php b/src/YiiFactoryGirl/FactoryData.php index 046fe18..03bef59 100644 --- a/src/YiiFactoryGirl/FactoryData.php +++ b/src/YiiFactoryGirl/FactoryData.php @@ -25,7 +25,7 @@ public function __construct($className, array $attributes = array(), array $alia try { $this->tableName = $className::model()->tableName(); } catch (\CException $e) { - throw new FactoryException(\Yii::t('yii-factory-girl', 'Unable to call {class}::model()->tableName().', array( + throw new FactoryException(\Yii::t(Factory::LOG_CATEGORY, 'Unable to call {class}::model()->tableName().', array( '{class}' => $className ))); } @@ -38,7 +38,7 @@ public function getAttributes($args = array(), $alias = null) $attributes = $this->attributes; if ($alias !== null) { if (!isset($this->aliases[$alias])) { - throw new FactoryException(\Yii::t('yii-factory-girl', 'Alias "{alias}" not found for class "{class}"', array( + throw new FactoryException(\Yii::t(Factory::LOG_CATEGORY, 'Alias "{alias}" not found for class "{class}"', array( '{alias}' => $alias, '{class}' => $this->className, ))); @@ -56,7 +56,7 @@ public static function fromFile($path, $suffix) { $parts = explode(DIRECTORY_SEPARATOR, $path); $fileName = end($parts); if (!substr($fileName, -(strlen($suffix)) === $suffix || !is_file($path))) { - throw new FactoryException(\Yii::t('yii-factory-girl', '"{file}" does not seem to be factory data file.', array( + throw new FactoryException(\Yii::t(Factory::LOG_CATEGORY, '"{file}" does not seem to be factory data file.', array( '{file}' => $path ))); } @@ -67,7 +67,7 @@ public static function fromFile($path, $suffix) { // load actual config $config = require $path; if (!is_array($config) || !isset($config['attributes']) || !is_array($config['attributes'])) { - throw new FactoryException(\Yii::t('yii-factory-girl', '"{path}" expected to return config array with "attributes" inside.', array( + throw new FactoryException(\Yii::t(Factory::LOG_CATEGORY, '"{path}" expected to return config array with "attributes" inside.', array( '{path}' => $path, ))); }