Exemplo n.º 1
0
 /**
  * Test for `Field::isAutoIncrement()`.
  *
  * @since 1.0.0
  * @access public
  *
  * @requires function Freyja\Database\Schema\Field::__construct
  * @requires function Freyja\Database\Schema\Field::isAutoIncrement
  */
 public function testIsAutoIncrement()
 {
     $field = new Field('name');
     $this->assertFalse($field->isAutoIncrement(), 'Failed asserting that Field::isAutoIncrement() correctly state whether the field is auto increment or not.');
 }
Exemplo n.º 2
0
 /**
  * Build single field.
  *
  * This method is used by `Freyja\Database\Schema\Table::buildCreate()` and
  * uses a property initialized in that method, therefore you SHOULD NOT use
  * this method alone. Using this method alone will be the same of casting the
  * Field to a string.
  *
  * @since 1.0.0
  * @access public
  *
  * @param Freyja\Database\Schema\Field $field
  * @return string
  *
  * @throws Freyja\Exceptions\LogicException if AUTO_INCREMENT is set on more
  * than one field, or in a non primary key field.
  */
 public function buildField(Field $field)
 {
     if (isset($this->autoinc_field)) {
         if ($field->isAutoIncrement()) {
             if ($this->autoinc_field == true) {
                 unset($this->autoinc_field);
                 throw new LogicException('AUTO_INCREMENT cannot be set on more than one field');
             }
             if (!in_array($field->getName(), $this->primary_keys)) {
                 unset($this->autoinc_field);
                 throw new LogicException('AUTO_INCREMENT cannot be set on a field that isn\'t primary key');
             }
             $this->autoinc_field = true;
         }
     }
     return (string) $field;
 }