コード例 #1
0
ファイル: DatabaseTest.php プロジェクト: rlanvin/php-dbtools
 public function testSetConfig()
 {
     $dsn = 'sqlite::memory:';
     Database::setConfig(['default' => ['dsn' => $dsn, 'attributes' => [PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC]]]);
     $c = Database::getConfig();
     $this->assertEquals('PDO', $c['default']['class'], 'setConfig preserves default values');
     $this->assertEquals($dsn, $c['default']['dsn'], 'setConfig merges values');
     $this->assertEquals(PDO::ERRMODE_EXCEPTION, $c['default']['attributes'][PDO::ATTR_ERRMODE], 'setConfig preserves default attributes');
     $this->assertEquals(PDO::FETCH_ASSOC, $c['default']['attributes'][PDO::ATTR_DEFAULT_FETCH_MODE], 'setConfig preserves default attributes');
 }
コード例 #2
0
ファイル: PagerTest.php プロジェクト: rlanvin/php-dbtools
 public function testQueryForTotal()
 {
     Database::setConfig(['default' => ['dsn' => 'sqlite::memory:']]);
     $dbh = Database::get();
     $pager = new Pager();
     $pager->queryForTotal($dbh, 'SELECT 42');
     $this->assertEquals(42, $pager->getTotal());
     $stmt = $dbh->prepare('SELECT 666');
     $pager->queryForTotal($stmt);
     $this->assertEquals(666, $pager->getTotal());
 }
コード例 #3
0
    public static function setUpBeforeClass()
    {
        Database::setConfig(['default' => ['dsn' => 'sqlite::memory:']]);
        $dbh = Database::get();
        $dbh->exec('CREATE TABLE items (
			id INTEGER PRIMARY KEY AUTOINCREMENT,
			a INT,
			b TEXT
		)');
        $dbh->exec(sprintf('INSERT INTO items (a,b) VALUES(42, %s)', $dbh->quote('The Answer')));
    }
コード例 #4
0
 /**
  * @dataProvider invalidStandardWhereClauses
  * @expectedException InvalidArgumentException
  */
 public function testComputeStandardWhereClauseInvalid($opt)
 {
     $dbh = Database::get();
     $fields = ['id'];
     $where = [];
     $method = new ReflectionMethod('DbTools\\TableModel', 'computeStandardWhereClause');
     $method->setAccessible(true);
     $method->invokeArgs(null, [$dbh, $fields, $opt, &$where]);
 }