Commit 934a6dce authored by Carsten  Rose's avatar Carsten Rose
Browse files

AbstractDatabase.php: renamed a variable

parent f2ab1e4a
......@@ -24,7 +24,7 @@ abstract class AbstractDatabaseTest extends PHPUnit_Framework_TestCase {
/**
* @var qfq\Database
*/
protected $database = null;
protected $db = null;
/*
* @var qfq\store\Store
*/
......@@ -57,7 +57,7 @@ abstract class AbstractDatabaseTest extends PHPUnit_Framework_TestCase {
protected function setUp() {
// Init the store also reads db credential configuration
$this->store = \qfq\store\Store::getInstance('');
$this->store = \qfq\store\Store::getInstance();
// SWITCH to TestDB
$this->store->setVar(SYSTEM_DB, $this->store->getVar(SYSTEM_TESTDB, STORE_SYSTEM), STORE_SYSTEM);
......@@ -77,9 +77,9 @@ abstract class AbstractDatabaseTest extends PHPUnit_Framework_TestCase {
}
}
if ($this->database === null) {
$this->database = new \qfq\Database();
$this->pdo = $this->database->pdo;
if ($this->db === null) {
$this->db = new \qfq\Database();
$this->pdo = $this->db->pdo;
}
}
}
......@@ -10,21 +10,21 @@ class DatabaseTest extends AbstractDatabaseTest {
public function testExecute() {
$this->database->prepareExecute('SELECT * FROM person');
$this->db->prepareExecute('SELECT * FROM Person');
$this->assertEquals(2, $this->database->rowCount());
$this->assertEquals(2, $this->db->rowCount());
}
public function testFetchOneRowAssocEmptyResult() {
$this->database->prepareExecute('SELECT * FROM person WHERE id=0', []);
$this->db->prepareExecute('SELECT * FROM Person WHERE id=0', []);
$this->assertEquals(array(), $this->database->fetchOne());
$this->assertEquals(array(), $this->db->fetchOne());
}
public function testFetchOne() {
$this->database->prepareExecute('SELECT * FROM person');
$this->db->prepareExecute('SELECT * FROM Person');
$oneRow = $this->database->fetchOne();
$oneRow = $this->db->fetchOne();
$this->assertArrayHasKey('name', $oneRow);
$this->assertArrayHasKey('firstname', $oneRow);
......@@ -35,9 +35,9 @@ class DatabaseTest extends AbstractDatabaseTest {
}
public function testFetchAll() {
$this->database->prepareExecute('SELECT * FROM person ORDER BY id LIMIT 2');
$this->db->prepareExecute('SELECT * FROM Person ORDER BY id LIMIT 2');
$allRows = $this->database->fetchAll();
$allRows = $this->db->fetchAll();
$this->assertCount(2, $allRows);
$this->assertEquals(1, $allRows[0]['id']);
......@@ -45,9 +45,9 @@ class DatabaseTest extends AbstractDatabaseTest {
}
public function testFetchAllEmpty() {
$this->database->prepareExecute('SELECT * FROM person WHERE id=0 ORDER BY id');
$this->db->prepareExecute('SELECT * FROM Person WHERE id=0 ORDER BY id');
$this->assertEquals(array(), $this->database->fetchAll());
$this->assertEquals(array(), $this->db->fetchAll());
}
public function testQuerySimple() {
......@@ -70,62 +70,62 @@ class DatabaseTest extends AbstractDatabaseTest {
];
// Check read rows
$dataArray = $this->database->sql('SELECT * FROM person ORDER BY id LIMIT 2');
$dataArray = $this->db->sql('SELECT * FROM Person ORDER BY id LIMIT 2');
// Check count
$this->assertEquals(2, $this->database->rowCount());
$this->assertEquals(2, $this->db->rowCount());
$this->assertEquals(2, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
// Compare rows
$this->assertSame($expected, $dataArray);
// Check rows
// Same as above, but specify 'ROW_REGULAR'
$dataArray = $this->database->sql('SELECT * FROM person ORDER BY id LIMIT 2', ROW_REGULAR);
$this->assertEquals(2, $this->database->rowCount());
$dataArray = $this->db->sql('SELECT * FROM Person ORDER BY id LIMIT 2', ROW_REGULAR);
$this->assertEquals(2, $this->db->rowCount());
// Check rows
$this->assertSame($expected, $dataArray);
// ROW_EXACT_1
$dataArray = $this->database->sql('SELECT * FROM person WHERE id=1', ROW_EXACT_1);
$this->assertEquals(1, $this->database->rowCount());
$dataArray = $this->db->sql('SELECT * FROM Person WHERE id=1', ROW_EXACT_1);
$this->assertEquals(1, $this->db->rowCount());
// Check rows
$this->assertSame($expected[0], $dataArray);
// ROW_EMPTY_IS_OK - one record
$dataArray = $this->database->sql('SELECT * FROM person WHERE id=1', ROW_EMPTY_IS_OK);
$this->assertEquals(1, $this->database->rowCount());
$dataArray = $this->db->sql('SELECT * FROM Person WHERE id=1', ROW_EMPTY_IS_OK);
$this->assertEquals(1, $this->db->rowCount());
// Check rows
$this->assertSame($expected[0], $dataArray);
// ROW_EMPTY_IS_OK - no record
$dataArray = $this->database->sql('SELECT * FROM person WHERE id=0', ROW_EMPTY_IS_OK);
$this->assertEquals(0, $this->database->rowCount());
$dataArray = $this->db->sql('SELECT * FROM Person WHERE id=0', ROW_EMPTY_IS_OK);
$this->assertEquals(0, $this->db->rowCount());
// Check rows
$this->assertSame(array(), $dataArray);
// Check Implode: 2 records
$data = $this->database->sql('SELECT * FROM person ORDER BY id LIMIT 2', ROW_IMPLODE_ALL);
$data = $this->db->sql('SELECT * FROM Person ORDER BY id LIMIT 2', ROW_IMPLODE_ALL);
$this->assertEquals(implode($expected[0]) . implode($expected[1]), $data);
// Check Implode: 1 record
$data = $this->database->sql('SELECT * FROM person ORDER BY id LIMIT 1', ROW_IMPLODE_ALL);
$data = $this->db->sql('SELECT * FROM Person ORDER BY id LIMIT 1', ROW_IMPLODE_ALL);
$this->assertEquals(implode($expected[0]), $data);
// Check Implode 0 record
$data = $this->database->sql('SELECT * FROM person WHERE id=0 ORDER BY id LIMIT 2', ROW_IMPLODE_ALL);
$data = $this->db->sql('SELECT * FROM Person WHERE id=0 ORDER BY id LIMIT 2', ROW_IMPLODE_ALL);
$this->assertEquals('', $data);
}
public function testQuerySimpleParameter() {
// Parameter Susbstitution by '?'
$dataArray = $this->database->sql('SELECT * FROM person WHERE name LIKE ? ORDER BY id', ROW_REGULAR, ['Smith']);
$dataArray = $this->db->sql('SELECT * FROM Person WHERE name LIKE ? ORDER BY id', ROW_REGULAR, ['Smith']);
// Check count
$this->assertEquals(1, $this->database->rowCount());
$this->assertEquals(1, $this->db->rowCount());
// Parameter Susbstitution by name
$dataArray = $this->database->sql('SELECT * FROM person WHERE name LIKE :valueOfName ORDER BY id ', ROW_REGULAR, [':valueOfName' => 'Smith']);
$dataArray = $this->db->sql('SELECT * FROM Person WHERE name LIKE :valueOfName ORDER BY id ', ROW_REGULAR, [':valueOfName' => 'Smith']);
// Check count
$this->assertEquals(1, $this->database->rowCount());
$this->assertEquals(1, $this->db->rowCount());
}
......@@ -134,31 +134,31 @@ class DatabaseTest extends AbstractDatabaseTest {
*
*/
public function testSanatizeException() {
$this->database->sql('some garbage');
$this->db->sql('some garbage');
}
public function testParameters() {
$this->database->prepareExecute('SELECT * FROM person WHERE id = :valueOfA', [':valueOfA' => 2]);
$this->db->prepareExecute('SELECT * FROM Person WHERE id = :valueOfA', [':valueOfA' => 2]);
$this->assertEquals(1, $this->database->rowCount());
$this->assertEquals(1, $this->db->rowCount());
}
public function testGetSetValueList() {
$valueList = $this->database->getEnumSetValueList('person', 'gender');
$valueList = $this->db->getEnumSetValueList('person', 'gender');
$expected = [0 => '', 1 => 'male', 2 => 'female'];
$this->assertEquals($expected, $valueList);
$expected = [0 => '', 1 => 'a', 2 => 'b', 3 => 'c'];
$valueList = $this->database->getEnumSetValueList('person', 'groups');
$valueList = $this->db->getEnumSetValueList('person', 'groups');
$this->assertEquals($expected, $valueList);
}
public function testGetLastInsertId() {
$sql = "INSERT INTO person (id, name, firstname, gender, groups) VALUES (NULL, 'Doe', 'Jonni', 'male','')";
$sql = "INSERT INTO Person (id, name, firstname, gender, groups) VALUES (NULL, 'Doe', 'Jonni', 'male','')";
$this->database->prepareExecute($sql);
$this->assertEquals(3, $this->database->getLastInsertId());
$this->db->prepareExecute($sql);
$this->assertEquals(3, $this->db->getLastInsertId());
}
protected function setUp() {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment