Exemplo n.º 1
0
 public function testOperations()
 {
     $database = new Database('mysql', 'localhost', 'test');
     $table = new Table($database, 'test');
     $table->create([new Column('id', 'INT', false, true, true), new Column('data', 'VARCHAR(255)'), new Column('date', 'DATETIME')], true);
     $data = ['data' => 'test', 'date' => DateHelper::now()];
     $data2 = ['data' => 'test2', 'date' => DateHelper::addDays(DateHelper::now(), 2)->format('Y-m-d H:i:s')];
     $table->delete();
     $this->assertEquals(false, $table->exists($data));
     $this->assertEquals(0, $table->countRows());
     $this->assertEquals(0, $table->countRows($data));
     $table->insert(array_keys($data), array_values($data));
     $id = $table->getDatabase()->lastInsertId();
     $this->assertEquals(true, $table->exists([Table::DEAULT_ID_COLUMN => $id]));
     $this->assertEquals(1, $table->countRows());
     $this->assertEquals(1, $table->countRows($data));
     $this->assertEquals($data, $table->select($data, Table::OPERATOR_AND, array_keys($data))->fetch(Database::FETCH_ASSOC));
     $table->update($data2, [Table::DEAULT_ID_COLUMN => $id]);
     $this->assertEquals($data2, $table->select([Table::DEAULT_ID_COLUMN => $id], Table::OPERATOR_AND, array_keys($data))->fetch(Database::FETCH_ASSOC));
     // Clean up table
     $table->drop();
 }