public function setUp()
 {
     MySQLHelper::resetMySQLDatabases();
     $this->dbDriver = DbGet::factory(getUnitTestDbConfig('HELPER1'));
     $this->fixtureLoader = new FixtureLoader(FixtureTestCase::getFixturesRootPath(), $this->dbDriver);
     parent::setUp();
 }
 /**
  * Reset MySQL databases.
  *
  * @throws DatabaseException
  */
 public static function resetMySQLDatabases()
 {
     $dbConfig1 = getUnitTestDbConfig('HELPER1');
     $mysql1 = new \mysqli($dbConfig1[DbConnector::DB_CFG_HOST], $dbConfig1[DbConnector::DB_CFG_USERNAME], $dbConfig1[DbConnector::DB_CFG_PASSWORD], $dbConfig1[DbConnector::DB_CFG_DATABASE], $dbConfig1[DbConnector::DB_CFG_PORT]);
     $dbConfig2 = getUnitTestDbConfig('HELPER2');
     $mysql2 = new \mysqli($dbConfig2[DbConnector::DB_CFG_HOST], $dbConfig2[DbConnector::DB_CFG_USERNAME], $dbConfig2[DbConnector::DB_CFG_PASSWORD], $dbConfig2[DbConnector::DB_CFG_DATABASE], $dbConfig2[DbConnector::DB_CFG_PORT]);
     // Drop all tables from testHelper1.
     self::dropAllMysqlTables($mysql1, $dbConfig1[DbConnector::DB_CFG_DATABASE]);
     // Create tables in testHelper1 database.
     $mysql1->query('CREATE TABLE `test1` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `col1` int(11) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB');
     $mysql1->query('CREATE TABLE `test2` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `col2` int(11) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB');
     $mysql1->query('CREATE TABLE `test3` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `col2` int(11) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB');
     $mysql1->query('CREATE VIEW `my_view`AS SELECT * FROM `test1`;');
     // Insert into testHelper1 database.
     $mysql1->query("INSERT INTO `test1` (`id`, `col1`) VALUES (NULL, '1')");
     $mysql1->query("INSERT INTO `test2` (`id`, `col2`) VALUES (NULL, '2')");
     $mysql1->query("INSERT INTO `test2` (`id`, `col2`) VALUES (NULL, '22')");
     // Drop all tables from testHelper2.
     self::dropAllMysqlTables($mysql2, $dbConfig2[DbConnector::DB_CFG_DATABASE]);
     // Create tables in testHelper2 database.
     $mysql2->query('CREATE TABLE `test2` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `col2` int(11) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB');
     $mysql2->query('CREATE TABLE `test3` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `col2` int(11) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB');
     // Insert into testHelper1 database.
     $mysql2->query("INSERT INTO `test2` (`id`, `col2`) VALUES (NULL, '123')");
     $mysql2->query("INSERT INTO `test2` (`id`, `col2`) VALUES (NULL, '321')");
 }
 /**
  * @covers ::factory
  */
 public function test_factory_notSameInstance()
 {
     // When
     $db1 = DbGet::factory(getUnitTestDbConfig('HELPER1'));
     $db2 = DbGet::factory(getUnitTestDbConfig('HELPER2'));
     // Then
     $this->assertNotSame($db1, $db2);
 }
 /**
  * @covers ::getFixtureLoader
  */
 public function test_getFixtureLoader_dbSet()
 {
     // Given
     $db = new MySQL();
     $db->dbSetup(getUnitTestDbConfig('HELPER1'))->dbConnect();
     // When
     $fLoader = FixtureTestCase::getFixtureLoader($db);
     // Then
     $this->assertInstanceOf('\\Kicaj\\Test\\Helper\\Loader\\FixtureLoader', $fLoader);
     $this->assertTrue($fLoader->isDbSet());
 }
 /**
  * @covers ::dbGetTableNames
  *
  * @expectedException \Kicaj\DbKit\DatabaseException
  * @expectedExceptionMessageRegExp /Incorrect database name/
  */
 public function test_dbGetTableNames_error()
 {
     // Given
     $driver = new MySQL();
     // When
     $driver->dbSetup(getUnitTestDbConfig('HELPER_NOT_THERE'))->dbConnect();
     // Then
     $driver->dbGetTableNames();
 }
 /**
  * @covers ::loadSql
  *
  * @expectedException \Exception
  * @expectedExceptionMessage Error opening fixture vfs://root/fixture.sql
  */
 public function test_loadSal_file_permissions_error()
 {
     // Given
     $vFsRoot = vfsStream::setup();
     vfsStream::newFile('fixture.sql', 00)->at($vFsRoot);
     // When
     $db = DbGet::factory(getUnitTestDbConfig('HELPER1'));
     // Then
     $fixtureLoader = new FixtureLoader($vFsRoot->url(), $db);
     $fixtureLoader->loadDbFixture('fixture.sql');
 }