示例#1
0
 /**
  * Create database
  *
  * @param \PDO $pdo Database connection
  *
  * @return Database
  */
 public static function create(\PDO $pdo)
 {
     /**
      * Tables
      */
     $tables = new TableCollection();
     foreach ($pdo->query('SHOW TABLES;') as $row) {
         $table = TableFactory::create($row[0], $pdo);
         $tables->add($table);
     }
     /**
      * Initialization
      */
     $database = new Database($tables);
     return $database;
 }
示例#2
0
 /**
  * @covers ::getTables
  */
 public function testGetTables()
 {
     $tables = new Database\TableCollection();
     $tables->add(new Database\Table('foo', null, new Database\Table\ColumnCollection(), new Database\Table\IndexCollection()));
     $database = new Database($tables);
     $databaseTables = $database->getTables();
     $this->assertSame(1, count($databaseTables));
     foreach ($databaseTables as $i => $table) {
         switch ($i) {
             case 0:
                 $this->assertSame('foo', $table->getName());
                 break;
             default:
                 $this->fail();
                 break;
         }
     }
 }
 /**
  * @covers ::add
  *
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage Collection may only contain "Zortje\MySQLKeeper\Database\Table" objects, "integer" is not allowed
  */
 public function testAddException()
 {
     $tables = new TableCollection();
     $tables->add(42);
 }