Пример #1
0
 /**
  * @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'], []);
     }
 }
Пример #2
0
 /**
  * @return void
  */
 public function test_function()
 {
     // prepare
     $stmt = $this->pdo->prepare('SELECT * FROM `DbMockLibraryTest`.testTable WHERE `id` = 0');
     $stmt->execute();
     $result = $stmt->fetchAll();
     $reflection = new \ReflectionClass(MySQL::getInstance());
     $deleteMethod = $reflection->getMethod('delete');
     $deleteMethod->setAccessible(true);
     // test
     $this->assertCount(1, $result);
     // invoke logic
     $deleteMethod->invoke(MySQL::getInstance(), 'testTable', 1);
     // prepare
     $stmt->execute();
     $result = $stmt->fetchAll();
     // test
     $this->assertCount(0, $result);
 }
Пример #3
0
 /**
  * @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']));
 }