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 { ...@@ -24,7 +24,7 @@ abstract class AbstractDatabaseTest extends PHPUnit_Framework_TestCase {
/** /**
* @var qfq\Database * @var qfq\Database
*/ */
protected $database = null; protected $db = null;
/* /*
* @var qfq\store\Store * @var qfq\store\Store
*/ */
...@@ -57,7 +57,7 @@ abstract class AbstractDatabaseTest extends PHPUnit_Framework_TestCase { ...@@ -57,7 +57,7 @@ abstract class AbstractDatabaseTest extends PHPUnit_Framework_TestCase {
protected function setUp() { protected function setUp() {
// Init the store also reads db credential configuration // Init the store also reads db credential configuration
$this->store = \qfq\store\Store::getInstance(''); $this->store = \qfq\store\Store::getInstance();
// SWITCH to TestDB // SWITCH to TestDB
$this->store->setVar(SYSTEM_DB, $this->store->getVar(SYSTEM_TESTDB, STORE_SYSTEM), STORE_SYSTEM); $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 { ...@@ -77,9 +77,9 @@ abstract class AbstractDatabaseTest extends PHPUnit_Framework_TestCase {
} }
} }
if ($this->database === null) { if ($this->db === null) {
$this->database = new \qfq\Database(); $this->db = new \qfq\Database();
$this->pdo = $this->database->pdo; $this->pdo = $this->db->pdo;
} }
} }
} }
...@@ -10,21 +10,21 @@ class DatabaseTest extends AbstractDatabaseTest { ...@@ -10,21 +10,21 @@ class DatabaseTest extends AbstractDatabaseTest {
public function testExecute() { 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() { 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() { 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('name', $oneRow);
$this->assertArrayHasKey('firstname', $oneRow); $this->assertArrayHasKey('firstname', $oneRow);
...@@ -35,9 +35,9 @@ class DatabaseTest extends AbstractDatabaseTest { ...@@ -35,9 +35,9 @@ class DatabaseTest extends AbstractDatabaseTest {
} }
public function testFetchAll() { 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->assertCount(2, $allRows);
$this->assertEquals(1, $allRows[0]['id']); $this->assertEquals(1, $allRows[0]['id']);
...@@ -45,9 +45,9 @@ class DatabaseTest extends AbstractDatabaseTest { ...@@ -45,9 +45,9 @@ class DatabaseTest extends AbstractDatabaseTest {
} }
public function testFetchAllEmpty() { 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() { public function testQuerySimple() {
...@@ -70,62 +70,62 @@ class DatabaseTest extends AbstractDatabaseTest { ...@@ -70,62 +70,62 @@ class DatabaseTest extends AbstractDatabaseTest {
]; ];
// Check read rows // 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 // 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)); $this->assertEquals(2, $this->store->getVar(SYSTEM_SQL_COUNT, STORE_SYSTEM));
// Compare rows // Compare rows
$this->assertSame($expected, $dataArray); $this->assertSame($expected, $dataArray);
// Check rows // Check rows
// Same as above, but specify 'ROW_REGULAR' // Same as above, but specify 'ROW_REGULAR'
$dataArray = $this->database->sql('SELECT * FROM person ORDER BY id LIMIT 2', ROW_REGULAR); $dataArray = $this->db->sql('SELECT * FROM Person ORDER BY id LIMIT 2', ROW_REGULAR);
$this->assertEquals(2, $this->database->rowCount()); $this->assertEquals(2, $this->db->rowCount());
// Check rows // Check rows
$this->assertSame($expected, $dataArray); $this->assertSame($expected, $dataArray);
// ROW_EXACT_1 // ROW_EXACT_1
$dataArray = $this->database->sql('SELECT * FROM person WHERE id=1', ROW_EXACT_1); $dataArray = $this->db->sql('SELECT * FROM Person WHERE id=1', ROW_EXACT_1);
$this->assertEquals(1, $this->database->rowCount()); $this->assertEquals(1, $this->db->rowCount());
// Check rows // Check rows
$this->assertSame($expected[0], $dataArray); $this->assertSame($expected[0], $dataArray);
// ROW_EMPTY_IS_OK - one record // ROW_EMPTY_IS_OK - one record
$dataArray = $this->database->sql('SELECT * FROM person WHERE id=1', ROW_EMPTY_IS_OK); $dataArray = $this->db->sql('SELECT * FROM Person WHERE id=1', ROW_EMPTY_IS_OK);
$this->assertEquals(1, $this->database->rowCount()); $this->assertEquals(1, $this->db->rowCount());
// Check rows // Check rows
$this->assertSame($expected[0], $dataArray); $this->assertSame($expected[0], $dataArray);
// ROW_EMPTY_IS_OK - no record // ROW_EMPTY_IS_OK - no record
$dataArray = $this->database->sql('SELECT * FROM person WHERE id=0', ROW_EMPTY_IS_OK); $dataArray = $this->db->sql('SELECT * FROM Person WHERE id=0', ROW_EMPTY_IS_OK);
$this->assertEquals(0, $this->database->rowCount()); $this->assertEquals(0, $this->db->rowCount());
// Check rows // Check rows
$this->assertSame(array(), $dataArray); $this->assertSame(array(), $dataArray);
// Check Implode: 2 records // 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); $this->assertEquals(implode($expected[0]) . implode($expected[1]), $data);
// Check Implode: 1 record // 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); $this->assertEquals(implode($expected[0]), $data);
// Check Implode 0 record // 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); $this->assertEquals('', $data);
} }
public function testQuerySimpleParameter() { public function testQuerySimpleParameter() {
// Parameter Susbstitution by '?' // 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 // Check count
$this->assertEquals(1, $this->database->rowCount()); $this->assertEquals(1, $this->db->rowCount());
// Parameter Susbstitution by name // 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 // Check count
$this->assertEquals(1, $this->database->rowCount()); $this->assertEquals(1, $this->db->rowCount());
} }
...@@ -134,31 +134,31 @@ class DatabaseTest extends AbstractDatabaseTest { ...@@ -134,31 +134,31 @@ class DatabaseTest extends AbstractDatabaseTest {
* *
*/ */
public function testSanatizeException() { public function testSanatizeException() {
$this->database->sql('some garbage'); $this->db->sql('some garbage');
} }
public function testParameters() { 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() { public function testGetSetValueList() {
$valueList = $this->database->getEnumSetValueList('person', 'gender'); $valueList = $this->db->getEnumSetValueList('person', 'gender');
$expected = [0 => '', 1 => 'male', 2 => 'female']; $expected = [0 => '', 1 => 'male', 2 => 'female'];
$this->assertEquals($expected, $valueList); $this->assertEquals($expected, $valueList);
$expected = [0 => '', 1 => 'a', 2 => 'b', 3 => 'c']; $expected = [0 => '', 1 => 'a', 2 => 'b', 3 => 'c'];
$valueList = $this->database->getEnumSetValueList('person', 'groups'); $valueList = $this->db->getEnumSetValueList('person', 'groups');
$this->assertEquals($expected, $valueList); $this->assertEquals($expected, $valueList);
} }
public function testGetLastInsertId() { 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->db->prepareExecute($sql);
$this->assertEquals(3, $this->database->getLastInsertId()); $this->assertEquals(3, $this->db->getLastInsertId());
} }
protected function setUp() { 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