/**
  * When the input is of the same class and has the same native value then return true.
  */
 public function testWhenTheInputIsOfTheSameClassAndHasTheSameNativeValueThenReturnTrue()
 {
     $stringInstanceOne = new StringLiteral('instanceWithSameValue');
     $stringInstanceTwo = new StringLiteral('instanceWithSameValue');
     $result = $stringInstanceOne->sameValueAs($stringInstanceTwo);
     static::assertTrue($result);
 }
 /**
  * When called will return the stored string value.
  */
 public function testWhenCalledWillReturnTheStoredStringValue()
 {
     $value = 'AAA123';
     $instance = new StringLiteral($value);
     $returnedValue = $instance->toNative();
     static::assertSame($value, $returnedValue);
 }
 /**
  * When called will return the credential contents as an associative array.
  */
 public function testWhenCalledWillReturnTheCredentialContentsAsAnAssociativeArray()
 {
     $object = MySQLCredentials::build(StringLiteral::fromNative($this->username), StringLiteral::fromNative($this->password), StringLiteral::fromNative($this->hostnameLiteral), StringLiteral::fromNative($this->database));
     $response = $object->toArray();
     $expected = ['username' => 'Alphanum_123', 'password' => 'Alphanum1234567890-=~!#$%^&*()[]_+?<>', 'host' => 'localhost', 'database' => 'employees_2016'];
     static::assertEquals($expected, $response);
 }
 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);
 }
 /**
  * When isNull is not boolean will throw exception.
  *
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage The isNull argument doesn't have a boolean value.
  */
 public function testWhenIsNullIsNotBooleanWillThrowException()
 {
     $name = 'sample-name';
     $type = 'varchar(123)';
     $key = 'sample-key';
     $default = 'sample-default';
     $extra = 'sample-extra';
     TableField::build(StringLiteral::fromNative($name), FieldType::fromNative($type), 'isNull', FieldKeyType::fromNative($key), FieldDefaultValue::fromNative($default), StringLiteral::fromNative($extra));
 }
 /**
  * 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 buildIndex($table, $nonUnique, $keyName, $seqInIndex, $columnName, $collation, $cardinality, $subPart, $packed, $isNull, $indexType, $comment, $indexComment)
 {
     $tableAttribute = StringLiteral::fromNative($table);
     $nonUniqueAttribute = StringLiteral::fromNative($nonUnique);
     $keyNameAttribute = StringLiteral::fromNative($keyName);
     $seqInIndexAttribute = StringLiteral::fromNative($seqInIndex);
     $columnNameAttribute = StringLiteral::fromNative($columnName);
     $collationAttribute = StringLiteral::fromNative($collation);
     $cardinalityAttribute = StringLiteral::fromNative($cardinality);
     $subPartAttribute = null === $subPart ? NullValue::create() : StringLiteral::fromNative($subPart);
     $packedAttribute = null === $packed ? NullValue::create() : StringLiteral::fromNative($packed);
     $isNullAttribute = (bool) $isNull;
     $indexTypeAttribute = StringLiteral::fromNative($indexType);
     $commentAttribute = StringLiteral::fromNative($comment);
     $indexCommentAttribute = StringLiteral::fromNative($indexComment);
     return TableIndex::build($tableAttribute, $nonUniqueAttribute, $keyNameAttribute, $seqInIndexAttribute, $columnNameAttribute, $collationAttribute, $cardinalityAttribute, $subPartAttribute, $packedAttribute, $isNullAttribute, $indexTypeAttribute, $commentAttribute, $indexCommentAttribute);
 }
 /**
  * @param string                                           $tableName
  * @param \DatabaseInspect\Persistence\Models\TableField[] $fieldEntries
  * @param \DatabaseInspect\Persistence\Models\TableIndex[] $indexEntries
  *
  * @return static
  */
 public function buildTableFromPersistence($tableName, $fieldEntries, $indexEntries)
 {
     $tableName = StringLiteral::fromNative($tableName);
     $indexCollection = $this->buildTableIndexCollectionFromPersistence($indexEntries);
     $fieldCollection = $this->buildTableFieldCollectionFromPersistence($fieldEntries);
     $table = Table::build($tableName, $fieldCollection, $indexCollection);
     return $table;
 }
 public function getExtra()
 {
     return $this->extra->toNative();
 }
 public function getDatabase()
 {
     return $this->database->toNative();
 }
 public function getIndexComment()
 {
     return $this->indexComment->toNative();
 }
 /**
  * When an invalid native is supplied then throw exception.
  * @expectedException \DatabaseInspect\Attributes\Exceptions\InvalidNativeArgumentException
  */
 public function testWhenAnInvalidNativeIsSuppliedThenThrowException()
 {
     $value = 123;
     StringLiteral::fromNative($value);
 }
Exemplo n.º 14
0
 public function jsonSerialize()
 {
     return ['name' => $this->name->toNative(), 'fields' => $this->fields->jsonSerialize(), 'indexes' => $this->indexes->jsonSerialize()];
 }
 /**
  * When the stored value is a non-empty string then return false.
  */
 public function testWhenTheStoredValueIsANonEmptyStringThenReturnFalse()
 {
     $stringInstance = new StringLiteral('ten');
     $result = $stringInstance->isEmpty();
     static::assertFalse($result);
 }