Ejemplo n.º 1
0
 /**
  * @param $dsn
  * @param null $username
  * @param null $password
  * @param array $options
  * @dataProvider GoodFactoryCreateArgumentProvider
  */
 public function testGetAvailableDrivers($dsn, $username = null, $password = null, array $options = [])
 {
     if (count(PDO::getAvailableDrivers()) < 1) {
         $this->markTestSkipped('No drivers available!');
     } else {
         $db = Factory::create($dsn, $username, $password, $options);
         $this->assertEquals(count(array_diff_assoc(PDO::getAvailableDrivers(), $db->getAvailableDrivers())), 0);
         $this->assertEquals(count(array_diff_assoc(PDO::getAvailableDrivers(), $db->getPdo()->getAvailableDrivers())), 0);
         $this->assertEquals(count(array_diff_assoc($db->getAvailableDrivers(), $db->getPdo()->getAvailableDrivers())), 0);
     }
 }
Ejemplo n.º 2
0
 /**
  * EasyDB data provider
  * Returns an array of callables that return instances of EasyDB
  * @return array
  * @see EasyDBTest::GoodFactoryCreateArgumentProvider()
  */
 public function GoodFactoryCreateArgument2EasyDBProvider()
 {
     return array_map(function (array $arguments) {
         $dsn = $arguments[0];
         $username = isset($arguments[1]) ? $arguments[1] : null;
         $password = isset($arguments[2]) ? $arguments[2] : null;
         $options = isset($arguments[3]) ? $arguments[3] : [];
         return [function () use($dsn, $username, $password, $options) {
             return Factory::create($dsn, $username, $password, $options);
         }];
     }, $this->GoodFactoryCreateArgumentProvider());
 }
Ejemplo n.º 3
0
 /**
  * @param $dsn
  * @param string|null $username
  * @param string|null $password
  * @param array $options
  * @dataProvider GoodFactoryCreateArgumentProvider
  */
 public function testInTransaction($dsn, $username = null, $password = null, array $options = [])
 {
     $db = Factory::create($dsn, $username, $password, $options);
     $this->assertFalse($db->inTransaction());
     $db->beginTransaction();
     $this->assertTrue($db->inTransaction());
     $db->commit();
     $this->assertFalse($db->inTransaction());
     $db->beginTransaction();
     $this->assertTrue($db->inTransaction());
     $db->rollBack();
     $this->assertFalse($db->inTransaction());
 }
Ejemplo n.º 4
0
 /**
  * EasyDB data provider
  * Returns an array of callables that return instances of EasyDB
  * @return array
  * @see EasyDBTest::GoodFactoryCreateArgumentProvider()
  */
 public function GoodFactoryCreateArgument2EasyDBProvider()
 {
     return array_map(function (array $arguments) {
         $dsn = $arguments[0];
         $username = isset($arguments[1]) ? $arguments[1] : null;
         $password = isset($arguments[2]) ? $arguments[2] : null;
         $options = isset($arguments[3]) ? $arguments[3] : [];
         return [function () use($dsn, $username, $password, $options) {
             $factory = Factory::create($dsn, $username, $password, $options);
             try {
                 $factory->run('CREATE TABLE irrelevant_but_valid_tablename (foo char(36) PRIMARY KEY)');
             } catch (Exception $e) {
                 $this->markTestSkipped($e->getMessage());
                 return null;
             }
             return $factory;
         }];
     }, $this->GoodFactoryCreateArgumentProvider());
 }
 /**
  * @dataProvider GoodFactoryCreateArgumentProvider
  * @param $dsn
  * @param null $username
  * @param null $password
  * @param array $options
  */
 public function testEmulatePreparesDisabled($dsn, $username = null, $password = null, $options = [])
 {
     $db = Factory::create($dsn, $username, $password, $options);
     $recheckWithForcedFalse = false;
     try {
         $this->assertFalse($db->getPdo()->getAttribute(PDO::ATTR_EMULATE_PREPARES));
         $recheckWithForcedFalse = true;
     } catch (PDOException $e) {
         $this->assertStringEndsWith(': Driver does not support this function: driver does not support that attribute', $e->getMessage());
     }
     $options[PDO::ATTR_EMULATE_PREPARES] = true;
     $db = Factory::create($dsn, $username, $password, $options);
     try {
         $this->assertFalse($db->getPdo()->getAttribute(PDO::ATTR_EMULATE_PREPARES));
     } catch (PDOException $e) {
         $this->assertStringEndsWith(': Driver does not support this function: driver does not support that attribute', $e->getMessage());
     }
     if ($recheckWithForcedFalse) {
         $options[PDO::ATTR_EMULATE_PREPARES] = false;
         $db = Factory::create($dsn, $username, $password, $options);
         $this->assertFalse($db->getPdo()->getAttribute(PDO::ATTR_EMULATE_PREPARES));
     }
 }
Ejemplo n.º 6
0
 /**
  * @dataProvider BadFactoryCreateArgumentProvider
  * @param $dsn
  * @param null $username
  * @param null $password
  * @param array $options
  */
 public function testConstructorFailed($dsn, $username = null, $password = null, $options = [])
 {
     $this->expectException(ConstructorFailed::class);
     Factory::create($dsn, $username, $password, $options);
 }
Ejemplo n.º 7
0
 /**
  * @dataProvider GoodFactoryCreateArgumentProvider
  * @depends      testIs1DArray
  * @param $dsn
  * @param null $username
  * @param null $password
  * @param array $options
  */
 public function testSingleThrowsException($dsn, $username = null, $password = null, $options = [])
 {
     $db = Factory::create($dsn, $username, $password, $options);
     $this->expectException(InvalidArgumentException::class);
     $db->single('SELECT "column"', [[1]]);
 }
Ejemplo n.º 8
0
 /**
  * @param $dsn
  * @param string|null $username
  * @param string|null $password
  * @param array $options
  * @param string $expectedDriver
  *
  * @dataProvider GoodFactoryCreateArgumentProvider
  */
 public function testGetDriver($dsn, $username = null, $password = null, $options = [], $expectedDriver)
 {
     $db = Factory::create($dsn, $username, $password, $options);
     $this->assertEquals($db->getDriver(), $expectedDriver);
 }