Пример #1
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;
     });
 }
Пример #2
0
 /**
  * Test drop user account.
  */
 public function testDropUser()
 {
     $this->connection->execute('CREATE USER ?@? IDENTIFIED BY ?', 'monty', '%', 'some_pass');
     $this->assertTrue($this->connection->userExists('monty'));
     $this->connection->dropUser('monty');
     $this->assertFalse($this->connection->userExists('monty'));
 }
 /**
  * Test drop database.
  */
 public function testDropDatabase()
 {
     $this->connection->execute('CREATE DATABASE activecollab_database_connection_test_create');
     $this->assertTrue($this->connection->databaseExists('activecollab_database_connection_test_create'));
     $this->connection->dropDatabase('activecollab_database_connection_test_create');
     $this->assertFalse($this->connection->databaseExists('activecollab_database_connection_test_create'));
 }
 /**
  * Test if affected rows returns the correct value.
  */
 public function testAffectedRows()
 {
     $this->assertEquals(1, $this->connection->executeFirstCell('SELECT COUNT(`id`) AS "row_count" FROM `writers` WHERE `name` = ?', 'Leo Tolstoy'));
     $this->connection->execute('UPDATE `writers` SET `name` = ? WHERE `name` = ?', 'Lev Nikolayevich Tolstoy', 'Leo Tolstoy');
     $this->assertEquals(1, $this->connection->affectedRows());
     $this->connection->execute('UPDATE `writers` SET `name` = ? WHERE `name` = ?', 'Nothing to Update', 'Leo Tolstoy');
     $this->assertEquals(0, $this->connection->affectedRows());
 }
 /**
  * Tear down test environment.
  */
 public function tearDown()
 {
     $this->connection->execute('DROP TABLE IF EXISTS `' . MySqlQueue::BATCHES_TABLE_NAME . '`');
     $this->connection->execute('DROP TABLE IF EXISTS `' . MySqlQueue::JOBS_TABLE_NAME . '`');
     $this->connection->execute('DROP TABLE IF EXISTS `' . MySqlQueue::FAILED_JOBS_TABLE_NAME . '`');
     $this->link->close();
     $this->last_failed_job = $this->last_failure_message = null;
     parent::tearDown();
 }
 /**
  * {@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();
 }
 /**
  * Test list tables from a specified database (user needs to have proper permissions over that database).
  */
 public function testListTablesFromAnotherDatabase()
 {
     if ($this->connection->databaseExists('test_another_database')) {
         $this->connection->execute('DROP DATABASE `test_another_database`');
     }
     $this->connection->execute('CREATE DATABASE `test_another_database`');
     $this->assertTrue($this->connection->databaseExists('test_another_database'));
     $this->connection->execute('CREATE TABLE `test_another_database`.`test_table` (id INT(11) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT)');
     $this->assertEquals(['test_table'], $this->connection->getTableNames('test_another_database'));
     $this->connection->execute('DROP DATABASE `test_another_database`');
     $this->assertFalse($this->connection->databaseExists('test_another_database'));
 }
Пример #8
0
 /**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     $this->link = new \MySQLi('localhost', 'root', '', 'activecollab_promises_test');
     if ($this->link->connect_error) {
         throw new \RuntimeException('Failed to connect to database. MySQL said: ' . $this->link->connect_error);
     }
     $this->connection = new MysqliConnection($this->link);
     $this->connection->execute('DROP TABLE IF EXISTS `' . PromisesInterface::PROMISES_TABLE_NAME . '`');
     $this->now = new Carbon();
     Carbon::setTestNow($this->now);
 }
Пример #9
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();
 }
Пример #10
0
 /**
  * Tear down the test environment.
  */
 public function tearDown()
 {
     $this->connection->execute('DROP TABLE `writers`');
     parent::tearDown();
 }