/**
  * Test drop table command.
  */
 public function testDropTable()
 {
     $this->assertEquals(['writers1', 'writers2', 'writers3'], $this->connection->getTableNames());
     $this->assertTrue($this->connection->tableExists('writers2'));
     $this->connection->dropTable('writers2');
     $this->assertEquals(['writers1', 'writers3'], $this->connection->getTableNames());
     $this->assertFalse($this->connection->tableExists('writers2'));
 }
 /**
  * {@inheritdoc}
  */
 public function tearDown()
 {
     $this->connection->turnOffForeignKeyChecks();
     $this->connection->execute('DROP TABLE IF EXISTS `writers`');
     $this->connection->execute('DROP TABLE IF EXISTS `periods`');
     $this->connection->execute('DROP TABLE IF EXISTS `topics`');
     $this->connection->turnOnForeignKeyChecks();
     $this->assertEquals([], $this->connection->getTableNames());
     parent::tearDown();
 }
예제 #3
0
 /**
  * Tear down test environment.
  */
 public function tearDown()
 {
     if ($triggers = $this->connection->execute('SHOW TRIGGERS')) {
         foreach ($triggers as $trigger) {
             $this->connection->execute('DROP TRIGGER ' . $this->connection->escapeFieldName($trigger['Trigger']));
         }
     }
     $this->connection->execute('SET foreign_key_checks = 0;');
     foreach ($this->connection->getTableNames() as $table_name) {
         $this->connection->dropTable($table_name);
     }
     $this->connection->execute('SET foreign_key_checks = 1;');
     $this->connection = null;
     $this->link->close();
     parent::tearDown();
 }
예제 #4
0
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     $this->addToContainer('link', function ($c) {
         $db_host = $this->getTestMySqlConnectionParam('host', 'localhost');
         $db_port = $this->getTestMySqlConnectionParam('port', 3306);
         $db_user = $this->getTestMySqlConnectionParam('user', 'root');
         $db_pass = $this->getTestMySqlConnectionParam('pass', '');
         $db_name = $this->getTestMySqlConnectionParam('database', $this->getTestMySqlDatabaseName($c['app_name']));
         $link = new \MySQLi("{$db_host}:{$db_port}", $db_user, $db_pass);
         if ($link->connect_error) {
             throw new RuntimeException('Failed to connect to database. MySQL said: ' . $link->connect_error);
         }
         if (!$link->select_db($db_name)) {
             throw new RuntimeException('Failed to select database');
         }
         return $link;
     });
     $this->addToContainer('connection', function ($c) {
         $connection = new MysqliConnection($c['link']);
         $connection->execute('SET foreign_key_checks = 0;');
         foreach ($connection->getTableNames() as $table_name) {
             $connection->dropTable($table_name);
         }
         $connection->execute('SET foreign_key_checks = 1;');
         return $connection;
     });
 }