public static function getInstanceSample()
 {
     $name = StringLiteral::fromNative('sample_table_name');
     $fields = TableFieldCollection::build([TableField::build(StringLiteral::fromNative('sample-name'), FieldType::fromNative('varchar(123)'), true, FieldKeyType::fromNative('sample-key'), FieldDefaultValue::fromNative('sample-default'), StringLiteral::fromNative('sample-extra'))]);
     $indexes = TableIndexCollection::build([TableIndex::build(new StringLiteral('sample-table'), new StringLiteral('sample-nonUnique'), new StringLiteral('sample-keyName'), new StringLiteral('sample-seqInIndex'), new StringLiteral('sample-columnName'), new StringLiteral('sample-collation'), new StringLiteral('sample-cardinality'), new StringLiteral('sample-subPart'), new StringLiteral('sample-packed'), false, new StringLiteral('sample-indexType'), new StringLiteral('sample-comment'), new StringLiteral('sample-indexComment'))]);
     $instance = Table::build($name, $fields, $indexes);
     return $instance;
 }
 /**
  * When entries are passed at build time then return them as an array.
  */
 public function testWhenEntriesArePassedThenStoreThem()
 {
     $fields = [TableField::build(StringLiteral::fromNative('id'), FieldType::fromNative('int(3)'), false, FieldKeyType::fromNative('PRI'), FieldDefaultValue::fromNative(''), StringLiteral::fromNative('')), TableField::build(StringLiteral::fromNative('name'), FieldType::fromNative('varchar(255)'), false, FieldKeyType::fromNative(''), FieldDefaultValue::fromNative(''), StringLiteral::fromNative(''))];
     $instance = TableFieldCollection::build($fields);
     $response = $instance->toArray();
     $expected = [['name' => 'id', 'type' => 'int(3)', 'null' => false, 'key' => 'PRI', 'default' => '', 'extra' => ''], ['name' => 'name', 'type' => 'varchar(255)', 'null' => false, 'key' => '', 'default' => '', 'extra' => '']];
     static::assertEquals($expected, $response);
 }
 /**
  * Store entries.
  */
 public function testStoreEntries()
 {
     $name = StringLiteral::fromNative('sample_table_name');
     $fields = TableFieldCollection::build([]);
     $indexes = TableIndexCollection::build([]);
     $instance = Table::build($name, $fields, $indexes);
     static::assertInstanceOf(Table::class, $instance);
     $helper = \ClassHelper::instance($instance);
     static::assertSame($name, $helper->name);
     static::assertSame($fields, $helper->fields);
     static::assertSame($indexes, $helper->indexes);
 }
 public function buildTableFieldCollectionFromPersistence(array $fields)
 {
     $fieldList = [];
     $length = count($fields);
     for ($i = 0; $i < $length; $i++) {
         /** @var \DatabaseInspect\Persistence\Models\TableField $persistenceField */
         $persistenceField = $fields[$i];
         // @todo Throw exception when the item is not a TableField.
         $name = $persistenceField->getName();
         $type = $persistenceField->getType();
         $null = $persistenceField->getIsNull();
         $key = $persistenceField->getKey();
         $default = $persistenceField->getDefault();
         $extra = $persistenceField->getExtra();
         $domainField = $this->buildField($name, $type, $null, $key, $default, $extra);
         $fieldList[] = $domainField;
     }
     return TableFieldCollection::build($fieldList);
 }
 /**
  * When among the entries is a non TableField object then throw exception.
  *
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage Invalid field entries.
  */
 public function testWhenAmongTheEntriesIsANonTableFieldObjectThenThrowException()
 {
     $fields = [new TableField(), new TableIndex()];
     TableFieldCollection::build($fields);
 }
 public function jsonSerialize()
 {
     return ['name' => $this->name->toNative(), 'fields' => $this->fields->jsonSerialize(), 'indexes' => $this->indexes->jsonSerialize()];
 }