Skip to content
This repository has been archived by the owner on Sep 14, 2020. It is now read-only.

Commit

Permalink
Log creating new factory.
Browse files Browse the repository at this point in the history
  • Loading branch information
ddinchev committed Jan 27, 2015
1 parent 963d655 commit ecd986e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions src/YiiFactoryGirl/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)));
}
}
Expand Down Expand Up @@ -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)
{
Expand All @@ -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
)));
Expand Down Expand Up @@ -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,
)));
}
Expand Down
8 changes: 4 additions & 4 deletions src/YiiFactoryGirl/FactoryData.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
)));
}
Expand All @@ -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,
)));
Expand All @@ -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
)));
}
Expand All @@ -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,
)));
}
Expand Down

0 comments on commit ecd986e

Please sign in to comment.