/**
  * Provided a modelClassName, members and corresponding rules columns array is generated for schema generation.
  * Members with unique validators are tracked separately to be used with index array generation later.
  * @param string $modelClassName
  * @param array $members
  * @param array $rules
  * @param $messageLogger
  * @return array
  * @throws CException
  */
 public static function resolve($modelClassName, array $members, array $rules, &$messageLogger)
 {
     $messageLogger->addInfoMessage(Zurmo::t('Core', 'Building Column definitions for {{model}}', array('{{model}}' => $modelClassName)));
     $membersWithRules = array();
     $columns = array();
     foreach ($rules as $rule) {
         if (in_array($rule[0], $members)) {
             $membersWithRules[$rule[0]][] = $rule;
         }
     }
     foreach ($membersWithRules as $member => $rules) {
         $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName, $rules, $messageLogger);
         if ($column) {
             $columns[] = $column;
         } else {
             $errorMessage = Zurmo::t('Core', 'Failed to resolve {{model}}.{{member}} to column', array('{{model}}' => $modelClassName, '{{member}}' => $member));
             $messageLogger->addErrorMessage($errorMessage);
             throw new CException($errorMessage);
         }
     }
     if (count($members) != count($columns)) {
         $errorMessage = Zurmo::t('Core', 'Not all members for {{model}} could be translated to columns.', array('{{model}}' => $modelClassName));
         $messageLogger->addErrorMessage($errorMessage);
         $errorMessage .= Zurmo::t('Core', 'Members') . ': (';
         $errorMessage .= join(', ', $members);
         $errorMessage .= '),' . Zurmo::t('Core', 'Columns') . ' (';
         // Not Coding Standard
         $columnNames = RedBeanModelMemberToColumnUtil::resolveColumnNamesArrayFromColumnSchemaDefinition($columns);
         $columnNames = join(', ', $columnNames);
         $errorMessage .= $columnNames . ')';
         throw new CException($errorMessage);
     }
     $messageLogger->addInfoMessage(Zurmo::t('Core', 'Column definitions Built'));
     return $columns;
 }
 /**
  * @depends testResolveUniqueIndexesFromValidator
  */
 public function testResolveWithUniqueValidator()
 {
     $unsigned = null;
     $assumedSigned = RedBeanModelMemberRulesToColumnAdapter::ASSUME_SIGNED;
     if (!$assumedSigned) {
         $unsigned = 'UNSIGNED';
     }
     $modelClassName = 'AuditEvent';
     $rules = array(array('attributeName', 'unique'), array('attributeName', 'type', 'type' => 'integer'));
     $column = RedBeanModelMemberRulesToColumnAdapter::resolve($modelClassName, $rules, static::$messageLogger);
     $this->assertNotEmpty($column);
     $this->assertArrayHasKey('name', $column);
     $this->assertArrayHasKey('type', $column);
     $this->assertArrayHasKey('unsigned', $column);
     $this->assertArrayHasKey('notNull', $column);
     $this->assertArrayHasKey('collation', $column);
     $this->assertArrayHasKey('default', $column);
     $this->assertEquals('attributename', $column['name']);
     $this->assertEquals('INT(11)', $column['type']);
     $this->assertEquals($unsigned, $column['unsigned']);
     $this->assertEquals('NULL', $column['notNull']);
     // Not Coding Standard
     $this->assertNull($column['collation']);
     $this->assertEquals('DEFAULT NULL', $column['default']);
     // Not Coding Standard
     $uniqueIndex = RedBeanModelMemberRulesToColumnAdapter::resolveUniqueIndexesFromValidator($modelClassName);
     $this->assertNotEmpty($uniqueIndex);
     $this->assertCount(1, $uniqueIndex);
     $indexName = key($uniqueIndex);
     $this->assertCount(2, $uniqueIndex[$indexName]);
     $this->assertArrayHasKey('members', $uniqueIndex[$indexName]);
     $this->assertArrayHasKey('unique', $uniqueIndex[$indexName]);
     $this->assertCount(1, $uniqueIndex[$indexName]['members']);
     $this->assertEquals('attributeName', $uniqueIndex[$indexName]['members'][0]);
     $this->assertTrue($uniqueIndex[$indexName]['unique']);
 }