/**
  * @dataProvider getData
  *
  * @param array $data
  *
  * @return void
  */
 public function test_function(array $data)
 {
     // prepare
     $this->setExpectedException($data['exception'], $data['errorMessage']);
     // invoke logic
     MySQL::initMySQL($data['initialData'], $data['serverName'], $data['database'], $data['username'], $data['password'], []);
     if (isset($data['initTwice'])) {
         MySQL::initMySQL($data['initialData'], $data['serverName'], $data['database'], $data['username'], $data['password'], []);
     }
 }
Example #2
0
 public function setUp()
 {
     if (is_null($this->pdo)) {
         $this->pdo = new \PDO('mysql:host=localhost;', 'root', '');
     }
     $stmt = $this->pdo->prepare('DROP DATABASE IF EXISTS `DbMockLibraryTest`');
     $stmt->execute();
     $stmt = $this->pdo->prepare('CREATE DATABASE `DbMockLibraryTest`');
     $stmt->execute();
     $stmt = $this->pdo->prepare('CREATE TABLE IF NOT EXISTS DbMockLibraryTest.testTable (`id` INT, `foo` INT, PRIMARY KEY (`id`))');
     $stmt->execute();
     MySQL::initMySQL(['testTable' => [1 => ['foo' => 0, 'id' => 0]]], 'localhost', 'DbMockLibraryTest', 'root', '', []);
 }
 /**
  * @return void
  */
 public function test_function()
 {
     // prepare
     $dataArray = ['testTable' => [1 => ['foo' => 1, 'id' => 1]]];
     // invoke logic
     MySQL::initMySQL($dataArray, 'localhost', 'DbMockLibraryTest', 'root', '', []);
     // prepare
     $reflection = new \ReflectionClass('\\DbMockLibrary\\DbImplementations\\MySQL');
     $staticProperties = $reflection->getStaticProperties();
     // test
     $this->assertInstanceOf('\\DbMockLibrary\\DbImplementations\\MySQL', $staticProperties['instance']);
     $this->assertEquals($dataArray, $staticProperties['initialData']);
     // prepare
     $dataProperty = $reflection->getProperty('data');
     $dataProperty->setAccessible(true);
     $primaryKeysProperty = $reflection->getProperty('primaryKeys');
     $primaryKeysProperty->setAccessible(true);
     // test
     $this->assertEquals($dataArray, $dataProperty->getValue($staticProperties['instance']));
     $this->assertEquals(['testTable' => ['id']], $primaryKeysProperty->getValue($staticProperties['instance']));
 }