/** * Test for `Field::__toString()`. * * @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::unsigned * @requires function Freyja\Database\Schema\Field::autoIncrement * @requires function Freyja\Database\Schema\Field::decimal * @requires function Freyja\Database\Schema\Field::notNull * @requries function Freyja\Database\Schema\Field::setDefault * @requires function Freyja\Database\Schema\Field::__toString */ public function testToString() { $field_1 = new Field('field'); $field_1->integer(8)->unsigned()->autoIncrement(); $field_1_str = (string) $field_1; $expected = 'field INT(8) UNSIGNED AUTO_INCREMENT'; $this->assertEquals($field_1_str, $expected, 'Failed asserting that a field can be correctly cast to string.'); $field_2 = new Field('field'); $field_2->decimal(8, 5)->unsigned()->notNull()->setDefault(10.456); $field_2_str = (string) $field_2; $expected = 'field DECIMAL(8,5) DEFAULT 10.456 NOT NULL UNSIGNED'; $this->assertEquals($field_2_str, $expected, 'Failed asserting that a field can be correctly cast to string.'); }
/** * Test for `Table::buildAlter()`. * * @since 1.0.0 * @access public * * @requires function Freyja\Database\Schema\Table::__construct * @requires function Freyja\Database\Schema\Table::build * @requires function Freyja\Database\Schema\Table::buildAlter */ public function testBuildAlter() { $table = new Table('table'); $f1 = new Field('f1'); $f2 = new Field('f2'); $f3 = new Field('f3'); $table->addFields(array($f1->integer(), $f2->integer()))->removeFields(array($f3->integer())); $expected = 'ALTER TABLE table ADD f1 INT(11), ADD f2 INT(11), DROP COLUMN f3;'; $this->assertEquals($expected, $table->build(), 'Failed asserting that Table methods correctly build a DROP table.'); }