コード例 #1
0
ファイル: GetTest.php プロジェクト: snje1987/minifw
 /**
  * @covers Org\Snje\Minifw\Table::get
  */
 public function test_get()
 {
     $table1 = TableWithAll::get();
     $this->assertEquals('Org\\Snje\\MinifwTest\\Table\\TableWithAll', get_class($table1));
     $table2 = TableWithOne::get();
     $this->assertEquals('Org\\Snje\\MinifwTest\\Table\\TableWithOne', get_class($table2));
     $this->assertNotEquals($table2, $table1);
     $table3 = TableWithAll::get();
     $this->assertEquals($table1, $table3);
     $table4 = TableWithAll::get(['id' => 'def']);
     $this->assertEquals($table1, $table4);
 }
コード例 #2
0
ファイル: CreateTest.php プロジェクト: snje1987/minifw
    /**
     * @covers Org\Snje\Minifw\Table::create
     * @covers Org\Snje\Minifw\Table::drop
     */
    public function test_create()
    {
        $table_create = TableWithAll::get();
        $table_create->drop();
        $table_create->create();
        $db = \Org\Snje\Minifw\DB::get();
        $sql = 'show create table `' . $table_create::TBNAME . '`';
        $ret = $db->get_query($sql);
        $this->assertArrayHasKey(0, $ret);
        $ret = $ret[0];
        $leftsql = $ret['Create Table'];
        $rightsql = 'CREATE TABLE `table_with_all` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT \'ID\',
  `intfield` int(11) NOT NULL COMMENT \'A int field\',
  `charfield` varchar(200) NOT NULL COMMENT \'A varchar field\',
  `textfield` text NOT NULL COMMENT \'A text field\',
  `intfield_def` int(11) NOT NULL DEFAULT \'0\' COMMENT \'A int field\',
  `charfield_def` varchar(200) NOT NULL DEFAULT \'\' COMMENT \'A varchar field\',
  PRIMARY KEY (`id`),
  UNIQUE KEY `uniqueindex` (`intfield`),
  KEY `charfield` (`charfield`),
  KEY `intfield` (`intfield`,`charfield`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=\'Table To Create\'';
        $this->assertEquals($rightsql, $leftsql);
        $table_create = TableWithOne::get();
        $table_create->drop();
        $table_create->create();
        $sql = 'show create table `' . $table_create::TBNAME . '`';
        $ret = $db->get_query($sql);
        $this->assertArrayHasKey(0, $ret);
        $ret = $ret[0];
        $leftsql = $ret['Create Table'];
        $rightsql = 'CREATE TABLE `table_with_one` (
  `intfield` int(11) NOT NULL COMMENT \'A int field\'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT=\'Table To Create\'';
        $this->assertEquals($rightsql, $leftsql);
    }