Example #1
0
 /**
  * Test for `Field::getField()`.
  *
  * @since 1.0.0
  * @access public
  *
  * @requires function Freyja\Database\Schema\Field::__construct
  * @requires function Freyja\Database\Schema\Field::float
  * @requires function Freyja\Database\Schema\Field::setDefault
  * @requires function Freyja\Database\Schema\Field::autoIncrement
  * @requires function Freyja\Database\Schema\Field::notNull
  * @requires function Freyja\Database\Schema\Field::getField
  */
 public function testGetFieldWithLengthAndDecimals()
 {
     $field = new Field('field');
     $field_info = $field->float(28)->setDefault(1.5)->autoIncrement()->notNull()->getField();
     $expected = array('field' => array('type' => 'FLOAT(28,2)', 'default' => 1.5, 'NOT NULL' => true, 'UNSIGNED' => false, 'AUTO_INCREMENT' => true));
     $this->assertEquals($field_info, $expected, 'Failed asserting that Field::getField() correctly retrieves the field information, in particular the type with the length and decimals.');
 }
Example #2
0
 /**
  * Test for `Table::getTable()`.
  *
  * @since 1.0.0
  * @access public
  *
  * @requires function Freyja\Database\Schema\Field::__construct
  * @requires function Freyja\Database\Schema\Field::integer
  * @requires function Freyja\Database\Schema\Field::float
  * @requires function Freyja\Database\Schema\Table::__construct
  * @requires function Freyja\Database\Schema\Table::primaryKey
  * @requires function Freyja\Database\Schema\Table::foreignKey
  * @requries function Freyja\Database\Schema\Table::getTable
  */
 public function testGetTableWithPrimaryAndForeignKeys()
 {
     $f1 = new Field('f1');
     $f2 = new Field('f2');
     $table = new Table('table', array($f1->integer()->autoIncrement(), $f2->float()));
     $table->primaryKey('f1', 'f')->foreignKey('f2', 'some_table', 'some_field');
     $expected = array('table' => array('fields' => array('f1' => array('type' => 'INT(11)', 'default' => null, 'NOT NULL' => false, 'UNSIGNED' => false, 'AUTO_INCREMENT' => true), 'f2' => array('type' => 'FLOAT(10,2)', 'default' => null, 'NOT NULL' => false, 'UNSIGNED' => false, 'AUTO_INCREMENT' => false)), 'primary' => array('f' => array('f1')), 'foreign' => array('f2' => array('references' => 'some_table', 'on' => 'some_field')), 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'engine' => 'InnoDB'));
     $this->assertEquals($expected, $table->getTable(), 'Failed asserting that Table::getTable() returns the correct information of the table.');
 }