summaryrefslogtreecommitdiffstats
path: root/tests/modules/database
diff options
context:
space:
mode:
authorVolker Thiel <riker09@gmx.de>2013-03-12 13:57:37 +0100
committerVolker Thiel <riker09@gmx.de>2013-03-12 13:57:37 +0100
commit43cf002a0d5cb35737dab88eba976fdc44f0e772 (patch)
tree56a713a59ba5fa5b177714d9e355d9dea491da5d /tests/modules/database
parent3eafbc10c01224aaf839da92b4686042d4ae7959 (diff)
downloadPHPixie-43cf002a0d5cb35737dab88eba976fdc44f0e772.zip
PHPixie-43cf002a0d5cb35737dab88eba976fdc44f0e772.tar.gz
PHPixie-43cf002a0d5cb35737dab88eba976fdc44f0e772.tar.bz2
Further application of coding guidelines
Done with Netbeans 7.3 Now with Tabs instead of Spaces!
Diffstat (limited to 'tests/modules/database')
-rw-r--r--tests/modules/database/database/expressionTest.php61
-rw-r--r--tests/modules/database/driver/mysql/queryTest.php269
-rw-r--r--tests/modules/database/driver/mysql/resultTest.php150
-rw-r--r--tests/modules/database/driver/pdo/dbTest.php221
-rw-r--r--tests/modules/database/driver/pdo/queryTest.php293
-rw-r--r--tests/modules/database/driver/pdo/resultTest.php151
-rw-r--r--tests/modules/database/files/config.sqlite16
7 files changed, 599 insertions, 562 deletions
diff --git a/tests/modules/database/database/expressionTest.php b/tests/modules/database/database/expressionTest.php
index edb9d50..66164b2 100644
--- a/tests/modules/database/database/expressionTest.php
+++ b/tests/modules/database/database/expressionTest.php
@@ -1,37 +1,42 @@
<?php
+
require_once('/../../../../modules/database/classes/database/expression.php');
+
/**
* Generated by PHPUnit_SkeletonGenerator on 2013-02-07 at 10:14:10.
*/
class Expression_DatabaseTest extends PHPUnit_Framework_TestCase
{
- /**
- * @var Expression_Database
- */
- protected $object;
-
- /**
- * Sets up the fixture, for example, opens a network connection.
- * This method is called before a test is executed.
- */
- protected function setUp()
- {
- $this->object = new Expression_Database('test');
- }
-
+
/**
- * @covers Expression_Database::__construct
- */
- public function testConstruct()
- {
- $this->assertEquals('test',$this->object->value);
- }
-
- /**
- * Tears down the fixture, for example, closes a network connection.
- * This method is called after a test is executed.
- */
- protected function tearDown()
- {
- }
+ * @var Expression_Database
+ */
+ protected $object;
+
+ /**
+ * Sets up the fixture, for example, opens a network connection.
+ * This method is called before a test is executed.
+ */
+ protected function setUp()
+ {
+ $this->object = new Expression_Database('test');
+ }
+
+ /**
+ * @covers Expression_Database::__construct
+ */
+ public function testConstruct()
+ {
+ $this->assertEquals('test', $this->object->value);
+ }
+
+ /**
+ * Tears down the fixture, for example, closes a network connection.
+ * This method is called after a test is executed.
+ */
+ protected function tearDown()
+ {
+
+ }
+
}
diff --git a/tests/modules/database/driver/mysql/queryTest.php b/tests/modules/database/driver/mysql/queryTest.php
index a326434..3534048 100644
--- a/tests/modules/database/driver/mysql/queryTest.php
+++ b/tests/modules/database/driver/mysql/queryTest.php
@@ -1,69 +1,73 @@
<?php
+
require_once('/../../../../../modules/database/classes/database/query.php');
require_once('/../../../../../modules/database/classes/driver/pdo/query.php');
require_once('/../../../../../modules/database/classes/driver/mysql/query.php');
require_once('/../../../../../modules/database/classes/database/expression.php');
+
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.0 on 2013-02-01 at 06:23:13.
*/
class Query_Mysql_DriverTest extends PHPUnit_Framework_TestCase
{
- /**
- * @var Query_Mysql_Driver
- */
- protected $object;
-
- /**
- * Sets up the fixture, for example, opens a network connection.
- * This method is called before a test is executed.
- */
- protected function setUp()
- {
- $stub=(object)array('db_type'=>'mysql');
- $this->object = new Query_Mysql_Driver($stub,'select');
- }
-
- /**
- * Tears down the fixture, for example, closes a network connection.
- * This method is called after a test is executed.
- */
- protected function tearDown()
- {
- }
-
- /**
- * @covers Query_Mysql_Driver::escape_field
- * @todo Implement testEscape_field().
- */
- public function testEscape_field()
- {
+
+ /**
+ * @var Query_Mysql_Driver
+ */
+ protected $object;
+
+ /**
+ * Sets up the fixture, for example, opens a network connection.
+ * This method is called before a test is executed.
+ */
+ protected function setUp()
+ {
+ $stub = (object) array('db_type' => 'mysql');
+ $this->object = new Query_Mysql_Driver($stub, 'select');
+ }
+
+ /**
+ * Tears down the fixture, for example, closes a network connection.
+ * This method is called after a test is executed.
+ */
+ protected function tearDown()
+ {
+
+ }
+
+ /**
+ * @covers Query_Mysql_Driver::escape_field
+ * @todo Implement testEscape_field().
+ */
+ public function testEscape_field()
+ {
$this->object->add_alias();
- $this->assertEquals('test', $this->object->escape_field(new Expression_Database('test')));
+ $this->assertEquals('test', $this->object->escape_field(new Expression_Database('test')));
$this->assertEquals('`a0`.*', $this->object->escape_field('*'));
$this->assertEquals('`a0`.`test`', $this->object->escape_field('test'));
- $this->assertEquals('`test`.`test`',$this->object->escape_field('test.test'));
- }
-
- /**
- * @covers Query_Mysql_Driver::escape_value
- * @todo Implement testEscape_value().
- */
- public function testEscape_value()
- {
- $params=array();
- $this->assertEquals('test', $this->object->escape_value(new Expression_Database('test'),$params));
+ $this->assertEquals('`test`.`test`', $this->object->escape_field('test.test'));
+ }
+
+ /**
+ * @covers Query_Mysql_Driver::escape_value
+ * @todo Implement testEscape_value().
+ */
+ public function testEscape_value()
+ {
+ $params = array();
+ $this->assertEquals('test', $this->object->escape_value(new Expression_Database('test'), $params));
$this->assertEquals('?', $this->object->escape_value('korova', $params));
$this->assertArrayHasKey(0, $params);
$this->assertEquals('korova', $params[0]);
- }
-
- /**
- * @covers Query_Mysql_Driver::query
- * @todo Implement testQuery().
- */
- public function testQuerySelect1()
- {
- $query=$this->object
+ }
+
+ /**
+ * @covers Query_Mysql_Driver::query
+ * @todo Implement testQuery().
+ */
+ public function testQuerySelect1()
+ {
+ $query = $this->object
->table('fairies')
->where('a', 7)
->where('b', '<', 8)
@@ -72,13 +76,13 @@ class Query_Mysql_DriverTest extends PHPUnit_Framework_TestCase
->where(array(
array('e', 9),
array('or', array(
- array('f', 10),
- array('g', 11),
- )),
+ array('f', 10),
+ array('g', 11),
+ )),
array('or', array(
- array('h', 12),
- array('or',array('i', 13)),
- ))
+ array('h', 12),
+ array('or', array('i', 13)),
+ ))
))
->order_by('id', 'desc')
->group_by('id')
@@ -87,123 +91,122 @@ class Query_Mysql_DriverTest extends PHPUnit_Framework_TestCase
->having(array(
array('m', 9),
array('or', array(
- array('n', 10),
- array('o', 11),
- ))
+ array('n', 10),
+ array('o', 11),
+ ))
))
->limit(5)
->offset(6)
->query();
- $this->assertEquals("SELECT * FROM `fairies` WHERE `fairies`.`a` = ? AND `fairies`.`b` < ? AND `fairies`.`c` > ? OR `fairies`.`d` > ? AND ( `fairies`.`e` = ? OR ( `fairies`.`f` = ? AND `fairies`.`g` = ? ) OR ( `fairies`.`h` = ? OR `fairies`.`i` = ? ) ) GROUP BY `fairies`.`id` HAVING `fairies`.`j` < korova OR `fairies`.`l` > ? AND ( `fairies`.`m` = ? OR ( `fairies`.`n` = ? AND `fairies`.`o` = ? ) ) ORDER BY `fairies`.`id` DESC LIMIT 5 OFFSET 6 ",current($query));
-
- }
+ $this->assertEquals("SELECT * FROM `fairies` WHERE `fairies`.`a` = ? AND `fairies`.`b` < ? AND `fairies`.`c` > ? OR `fairies`.`d` > ? AND ( `fairies`.`e` = ? OR ( `fairies`.`f` = ? AND `fairies`.`g` = ? ) OR ( `fairies`.`h` = ? OR `fairies`.`i` = ? ) ) GROUP BY `fairies`.`id` HAVING `fairies`.`j` < korova OR `fairies`.`l` > ? AND ( `fairies`.`m` = ? OR ( `fairies`.`n` = ? AND `fairies`.`o` = ? ) ) ORDER BY `fairies`.`id` DESC LIMIT 5 OFFSET 6 ", current($query));
+ }
+
/**
- * @covers Query_Mysql_Driver::query
- * @todo Implement testQuery().
- */
- public function testQuerySelect2()
- {
- $query=$this->object
+ * @covers Query_Mysql_Driver::query
+ * @todo Implement testQuery().
+ */
+ public function testQuerySelect2()
+ {
+ $query = $this->object
->table('fairies')
->where('a', 7)
->join('test', array('fairies.test_id', 'test.id'))
->join('test2', array(
array('fairies.test2_id', 'test.test_id'),
array('fairies.test3_id', 'test.id')
- ),'inner')
- ->order_by('id','desc')
+ ), 'inner')
+ ->order_by('id', 'desc')
->query();
- $this->assertEquals("SELECT * FROM `fairies` LEFT JOIN `test` ON `fairies`.`test_id` = `test`.`id` INNER JOIN `test2` ON ( `fairies`.`test2_id` = `test`.`test_id` AND `fairies`.`test3_id` = `test`.`id` ) WHERE `fairies`.`a` = ? ORDER BY `fairies`.`id` DESC ",current($query));
-
- }
-
+ $this->assertEquals("SELECT * FROM `fairies` LEFT JOIN `test` ON `fairies`.`test_id` = `test`.`id` INNER JOIN `test2` ON ( `fairies`.`test2_id` = `test`.`test_id` AND `fairies`.`test3_id` = `test`.`id` ) WHERE `fairies`.`a` = ? ORDER BY `fairies`.`id` DESC ", current($query));
+ }
+
/**
- * @covers Query_Mysql_Driver::query
- * @todo Implement testQuery().
- */
- public function testQueryDelete()
- {
- $query=$this->object
+ * @covers Query_Mysql_Driver::query
+ * @todo Implement testQuery().
+ */
+ public function testQueryDelete()
+ {
+ $query = $this->object
->type('delete')
->table('fairies')
- ->where('id',1)
+ ->where('id', 1)
->query();
-
- $this->assertEquals("DELETE fairies.* FROM `fairies` WHERE `fairies`.`id` = ? ",current($query));
- }
-
+
+ $this->assertEquals("DELETE fairies.* FROM `fairies` WHERE `fairies`.`id` = ? ", current($query));
+ }
+
/**
- * @covers Query_Mysql_Driver::query
- * @todo Implement testQuery().
- */
- public function testQueryInsert()
- {
- $query=$this->object
+ * @covers Query_Mysql_Driver::query
+ * @todo Implement testQuery().
+ */
+ public function testQueryInsert()
+ {
+ $query = $this->object
->type('insert')
->table('fairies')
- ->data(array('id'=>1,'name'=>'Trixie'))
+ ->data(array('id' => 1, 'name' => 'Trixie'))
->query();
-
- $this->assertEquals("INSERT INTO `fairies` (`id`, `name`) VALUES(?, ?)",current($query));
- }
-
+
+ $this->assertEquals("INSERT INTO `fairies` (`id`, `name`) VALUES(?, ?)", current($query));
+ }
+
/**
- * @covers Query_Mysql_Driver::query
- * @todo Implement testQuery().
- */
- public function testQueryUpdate()
- {
- $query=$this->object
+ * @covers Query_Mysql_Driver::query
+ * @todo Implement testQuery().
+ */
+ public function testQueryUpdate()
+ {
+ $query = $this->object
->type('update')
->table('fairies')
- ->data(array('id'=>1,'name'=>'Trixie'))
+ ->data(array('id' => 1, 'name' => 'Trixie'))
->query();
-
- $this->assertEquals("UPDATE `fairies` SET `id` = ?, `name` = ? ",current($query));
- }
-
+
+ $this->assertEquals("UPDATE `fairies` SET `id` = ?, `name` = ? ", current($query));
+ }
+
/**
- * @covers Query_Mysql_Driver::query
- * @todo Implement testQuery().
- */
+ * @covers Query_Mysql_Driver::query
+ * @todo Implement testQuery().
+ */
public function testQueryCount()
- {
- $query=$this->object
+ {
+ $query = $this->object
->type('count')
->table('fairies')
- ->where('id',8)
+ ->where('id', 8)
->query();
-
- $this->assertEquals("SELECT COUNT(*) as `count` FROM `fairies` WHERE `fairies`.`id` = ? ",current($query));
- }
-
+
+ $this->assertEquals("SELECT COUNT(*) as `count` FROM `fairies` WHERE `fairies`.`id` = ? ", current($query));
+ }
+
/**
- * @covers Query_Mysql_Driver::add_alias
- * @todo Implement testQuery().
- */
+ * @covers Query_Mysql_Driver::add_alias
+ * @todo Implement testQuery().
+ */
public function testAlias()
- {
+ {
$this->object->table('fairies');
$this->assertEquals('fairies', $this->object->last_alias());
$this->object->add_alias();
- $this->assertEquals('a0',$this->object->last_alias());
- }
-
+ $this->assertEquals('a0', $this->object->last_alias());
+ }
+
/**
- * @covers Query_Mysql_Driver::__call
- * @todo Implement testQuery().
- */
+ * @covers Query_Mysql_Driver::__call
+ * @todo Implement testQuery().
+ */
public function testCall()
- {
+ {
$this->object->table('fairies');
$this->assertEquals('fairies', $this->object->table());
$except = false;
try {
$this->object->limit('fairies');
- }catch (Exception $e) {
- $except=true;
+ } catch (Exception $e) {
+ $except = true;
}
- $this->assertEquals(true,$except);
- }
-
+ $this->assertEquals(true, $except);
+ }
+
}
diff --git a/tests/modules/database/driver/mysql/resultTest.php b/tests/modules/database/driver/mysql/resultTest.php
index 5159e39..7142313 100644
--- a/tests/modules/database/driver/mysql/resultTest.php
+++ b/tests/modules/database/driver/mysql/resultTest.php
@@ -1,125 +1,135 @@
<?php
+
require_once('/../../../../../modules/database/classes/database/result.php');
require_once('/../../../../../modules/database/classes/driver/mysql/result.php');
+
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.0 on 2013-02-06 at 20:48:50.
*/
class Result_Mysql_DriverTest extends PHPUnit_Framework_TestCase
{
- /**
- * @var Result_Mysql_Driver
- */
- protected $object;
- /**
- * Sets up the fixture, for example, opens a network connection.
- * This method is called before a test is executed.
- */
- protected function setUp()
- {
+ /**
+ * @var Result_Mysql_Driver
+ */
+ protected $object;
+
+ /**
+ * Sets up the fixture, for example, opens a network connection.
+ * This method is called before a test is executed.
+ */
+ protected function setUp()
+ {
$stub = $this->getMockBuilder('mysqli_result')
- ->disableOriginalConstructor()
- ->getMock();
+ ->disableOriginalConstructor()
+ ->getMock();
$stub->expects($this->any())
->method('fetch_object')
->will($this->onConsecutiveCalls(
- (object) array('id' => 1, 'name' => 'Tinkerbell'),
- (object) array('id' => 2, 'name' => 'Trixie'),
- null
- ));
+ (object) array('id' => 1, 'name' => 'Tinkerbell'), (object) array('id' => 2, 'name' => 'Trixie'), null
+ ));
- $this->object = new Result_Mysql_Driver($stub);
- }
+ $this->object = new Result_Mysql_Driver($stub);
+ }
- /**
- * Tears down the fixture, for example, closes a network connection.
- * This method is called after a test is executed.
- */
- protected function tearDown()
- {
- }
+ /**
+ * Tears down the fixture, for example, closes a network connection.
+ * This method is called after a test is executed.
+ */
+ protected function tearDown()
+ {
- /**
- * @covers Result_Mysql_Driver::rewind
- * @todo Implement testRewind().
- */
- public function testRewind()
- {
- $except = false;
+ }
+
+ /**
+ * @covers Result_Mysql_Driver::rewind
+ * @todo Implement testRewind().
+ */
+ public function testRewind()
+ {
+ $except = false;
$this->object->valid();
$this->object->rewind();
$this->object->next();
try {
$this->object->rewind();
- }catch(Exception $e) {
- $except=true;
+ } catch (Exception $e) {
+ $except = true;
}
- $this->assertEquals(true,$except);
- }
+ $this->assertEquals(true, $except);
+ }
-
/**
- * @covers Result_Mysql_Driver::current
- */
- public function testCurrent() {
- $this->assertEquals($this->object->current()->name,'Tinkerbell');
+ * @covers Result_Mysql_Driver::current
+ */
+ public function testCurrent()
+ {
+ $this->assertEquals($this->object->current()->name, 'Tinkerbell');
}
-
+
/**
- * @covers Result_Mysql_Driver::valid
- */
- public function testVaid() {
- $this->assertEquals($this->object->valid(),true);
+ * @covers Result_Mysql_Driver::valid
+ */
+ public function testVaid()
+ {
+ $this->assertEquals($this->object->valid(), true);
}
-
+
/**
- * @covers Result_Mysql_Driver::key
- */
- public function testKey() {
- $this->assertEquals($this->object->key(),0);
+ * @covers Result_Mysql_Driver::key
+ */
+ public function testKey()
+ {
+ $this->assertEquals($this->object->key(), 0);
}
-
+
/**
- * @covers Result_Mysql_Driver::key
- */
- public function testGet() {
- $this->assertEquals($this->object->get('id'),1);
+ * @covers Result_Mysql_Driver::key
+ */
+ public function testGet()
+ {
+ $this->assertEquals($this->object->get('id'), 1);
}
-
+
/**
- * @covers Result_Mysql_Driver::as_array
- */
- public function testAs_Array() {
+ * @covers Result_Mysql_Driver::as_array
+ */
+ public function testAs_Array()
+ {
$arr = $this->object->as_array();
$this->assertArrayHasKey(0, $arr);
- $this->assertArrayHasKey('name', (array)$arr[0]);
+ $this->assertArrayHasKey('name', (array) $arr[0]);
$this->assertEquals($arr[0]->name, 'Tinkerbell');
$this->assertArrayHasKey(1, $arr);
- $this->assertArrayHasKey('id', (array)$arr[1]);
+ $this->assertArrayHasKey('id', (array) $arr[1]);
$this->assertEquals($arr[1]->id, 2);
}
-
- public function testIterator(){
+
+ public function testIterator()
+ {
$this->assertEquals($this->object->valid(), true);
$this->assertEquals($this->object->get('id'), 1);
- foreach($this->object as $key => $row) {
- if ($key == 0) {
+ foreach ($this->object as $key => $row)
+ {
+ if ($key == 0)
+ {
$this->assertEquals($row->name, 'Tinkerbell');
$this->assertEquals($row->id, 1);
}
- if ($key == 1) {
+ if ($key == 1)
+ {
$this->assertEquals($row->name, 'Trixie');
$this->assertEquals(2, $this->object->get('id'));
$this->assertEquals($row->id, 2);
}
}
- $this->assertEquals(false,$this->object->valid());
+ $this->assertEquals(false, $this->object->valid());
$this->assertEquals(null, $this->object->get('id'));
$this->assertEquals(null, $this->object->current());
$this->object->next();
$this->object->next();
$this->object->next();
- $this->assertEquals(1,$this->object->key());
-
+ $this->assertEquals(1, $this->object->key());
}
+
}
diff --git a/tests/modules/database/driver/pdo/dbTest.php b/tests/modules/database/driver/pdo/dbTest.php
index bf242ec..ccebedc 100644
--- a/tests/modules/database/driver/pdo/dbTest.php
+++ b/tests/modules/database/driver/pdo/dbTest.php
@@ -1,134 +1,137 @@
<?php
+
require_once('/../../../../../modules/database/classes/db.php');
require_once('/../../../../../modules/database/classes/driver/pdo/db.php');
require_once('/../../../../../modules/database/classes/database/query.php');
require_once('/../../../../../modules/database/classes/driver/pdo/query.php');
+
/**
* Generated by PHPUnit_SkeletonGenerator on 2013-02-07 at 12:41:50.
*/
class DB_PDO_DriverTest extends PHPUnit_Framework_TestCase
{
- /**
- * @var DB_PDO_Driver
- */
- protected $object;
-
- /**
- * Sets up the fixture, for example, opens a network connection.
- * This method is called before a test is executed.
- */
- protected function setUp()
- {
- file_put_contents(dirname(__FILE__).'/../../files/test.sqlite','');
+
+ /**
+ * @var DB_PDO_Driver
+ */
+ protected $object;
+
+ /**
+ * Sets up the fixture, for example, opens a network connection.
+ * This method is called before a test is executed.
+ */
+ protected function setUp()
+ {
+ file_put_contents(dirname(__FILE__).'/../../files/test.sqlite', '');
$db = new PDO('sqlite:'.dirname(__FILE__).'/../../files/test.sqlite');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->exec("CREATE TABLE fairies(id INT PRIMARY_KEY,name VARCHAR(255))");
-
+
Misc::$file = dirname(__FILE__).'/../../files/config.sqlite';
file_put_contents(Misc::$file, "<?php return ".var_export(array(
- 'default' => array(
- 'connection' => 'sqlite:'.dirname(__FILE__).'/../../files/test.sqlite',
- 'driver'=>'pdo'
- )
- ), true).';');
-
- $this->object = new DB_PDO_Driver('default');
- }
-
- /**
- * Tears down the fixture, for example, closes a network connection.
- * This method is called after a test is executed.
- */
- protected function tearDown()
- {
-
- }
-
- /**
- * @covers DB_PDO_Driver::build_query
- * @todo Implement testBuild_query().
- */
- public function testBuild_query()
- {
- $this->object->build_query('select');
- }
-
- /**
- * @covers DB_PDO_Driver::get_insert_id
- * @todo Implement testGet_insert_id().
- */
- public function testGet_insert_id()
- {
- $this->object->execute("INSERT INTO fairies(name)values('Trixie')");
- $this->assertEquals(1,$this->object->get_insert_id());
- }
-
- /**
- * @covers DB_PDO_Driver::list_columns
- * @todo Implement testList_columns().
- */
- public function testList_columns()
- {
- $cols = $this->object->list_columns('fairies');
- $this->assertContains('id',$cols);
- $this->assertContains('name',$cols);
- }
-
- /**
- * @covers DB_PDO_Driver::execute
- * @todo Implement testExecute().
- */
- public function testExecute()
- {
- $this->object->execute("SELECT * FROM fairies where id = ?",array(1));
- }
-
+ 'default' => array(
+ 'connection' => 'sqlite:'.dirname(__FILE__).'/../../files/test.sqlite',
+ 'driver' => 'pdo'
+ )
+ ), true).';');
+
+ $this->object = new DB_PDO_Driver('default');
+ }
+
+ /**
+ * Tears down the fixture, for example, closes a network connection.
+ * This method is called after a test is executed.
+ */
+ protected function tearDown()
+ {
+
+ }
+
/**
- * @covers DB_PDO_Driver::execute
- * @todo Implement testExecute().
- */
- public function testExecuteException()
- {
+ * @covers DB_PDO_Driver::build_query
+ * @todo Implement testBuild_query().
+ */
+ public function testBuild_query()
+ {
+ $this->object->build_query('select');
+ }
+
+ /**
+ * @covers DB_PDO_Driver::get_insert_id
+ * @todo Implement testGet_insert_id().
+ */
+ public function testGet_insert_id()
+ {
+ $this->object->execute("INSERT INTO fairies(name)values('Trixie')");
+ $this->assertEquals(1, $this->object->get_insert_id());
+ }
+
+ /**
+ * @covers DB_PDO_Driver::list_columns
+ * @todo Implement testList_columns().
+ */
+ public function testList_columns()
+ {
+ $cols = $this->object->list_columns('fairies');
+ $this->assertContains('id', $cols);
+ $this->assertContains('name', $cols);
+ }
+
+ /**
+ * @covers DB_PDO_Driver::execute
+ * @todo Implement testExecute().
+ */
+ public function testExecute()
+ {
+ $this->object->execute("SELECT * FROM fairies where id = ?", array(1));
+ }
+
+ /**
+ * @covers DB_PDO_Driver::execute
+ * @todo Implement testExecute().
+ */
+ public function testExecuteException()
+ {
$except = false;
- try{
+ try {
$this->object->execute("SELECUT * FROM fairies where id = ?", array(1));
- }catch (Exception $e) {
- $except=true;
+ } catch (Exception $e) {
+ $except = true;
}
- $this->assertEquals(true,$except);
- }
-
+ $this->assertEquals(true, $except);
+ }
+
/**
- * @covers DB_PDO_Driver::named_query
- * @todo Implement testExecute().
- */
- public function testNamed_query()
- {
- $this->object->named_query("SELECT * FROM fairies where id = :id",array(array('id'=>1)));
- }
-
+ * @covers DB_PDO_Driver::named_query
+ * @todo Implement testExecute().
+ */
+ public function testNamed_query()
+ {
+ $this->object->named_query("SELECT * FROM fairies where id = :id", array(array('id' => 1)));
+ }
+
/**
- * @covers DB_PDO_Driver::named_query
- * @todo Implement testExecute().
- */
- public function testNamed_queryException()
- {
+ * @covers DB_PDO_Driver::named_query
+ * @todo Implement testExecute().
+ */
+ public function testNamed_queryException()
+ {
$except = false;
- try{
- $this->object->named_query("SELsECT * FROM fairies where id = :id",array(array('id'=>1)));
- }catch (Exception $e) {
- $except=true;
+ try {
+ $this->object->named_query("SELsECT * FROM fairies where id = :id", array(array('id' => 1)));
+ } catch (Exception $e) {
+ $except = true;
}
- $this->assertEquals(true,$except);
- }
-
+ $this->assertEquals(true, $except);
+ }
+
/**
- * @covers DB_PDO_Driver::instance
- * @todo Implement testExecute().
- */
- public function testInstance()
- {
- $this->assertEquals('DB_PDO_Driver',get_class(DB::instance('default')));
- }
-
+ * @covers DB_PDO_Driver::instance
+ * @todo Implement testExecute().
+ */
+ public function testInstance()
+ {
+ $this->assertEquals('DB_PDO_Driver', get_class(DB::instance('default')));
+ }
+
}
diff --git a/tests/modules/database/driver/pdo/queryTest.php b/tests/modules/database/driver/pdo/queryTest.php
index 158a0f7..b216ec7 100644
--- a/tests/modules/database/driver/pdo/queryTest.php
+++ b/tests/modules/database/driver/pdo/queryTest.php
@@ -1,68 +1,72 @@
<?php
+
require_once('/../../../../../modules/database/classes/database/query.php');
require_once('/../../../../../modules/database/classes/driver/pdo/query.php');
require_once('/../../../../../modules/database/classes/database/expression.php');
+
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.0 on 2013-02-01 at 06:23:13.
*/
class Query_PDO_DriverTest extends PHPUnit_Framework_TestCase
{
- /**
- * @var Query_PDO_Driver
- */
- protected $object;
- /**
- * Sets up the fixture, for example, opens a network connection.
- * This method is called before a test is executed.
- */
- protected function setUp()
- {
- $stub=(object)array('db_type'=>'mysql');
- $this->object = new Query_PDO_Driver($stub,'select');
- }
+ /**
+ * @var Query_PDO_Driver
+ */
+ protected $object;
+
+ /**
+ * Sets up the fixture, for example, opens a network connection.
+ * This method is called before a test is executed.
+ */
+ protected function setUp()
+ {
+ $stub = (object) array('db_type' => 'mysql');
+ $this->object = new Query_PDO_Driver($stub, 'select');
+ }
+
+ /**
+ * Tears down the fixture, for example, closes a network connection.
+ * This method is called after a test is executed.
+ */
+ protected function tearDown()
+ {
- /**
- * Tears down the fixture, for example, closes a network connection.
- * This method is called after a test is executed.
- */
- protected function tearDown()
- {
- }
+ }
- /**
- * @covers Query_PDO_Driver::escape_field
- * @todo Implement testEscape_field().
- */
- public function testEscape_field()
- {
+ /**
+ * @covers Query_PDO_Driver::escape_field
+ * @todo Implement testEscape_field().
+ */
+ public function testEscape_field()
+ {
$this->object->add_alias();
- $this->assertEquals('test', $this->object->escape_field(new Expression_Database('test')));
+ $this->assertEquals('test', $this->object->escape_field(new Expression_Database('test')));
$this->assertEquals('`a0`.*', $this->object->escape_field('*'));
$this->assertEquals('`a0`.`test`', $this->object->escape_field('test'));
- $this->assertEquals('`test`.`test`',$this->object->escape_field('test.test'));
- }
+ $this->assertEquals('`test`.`test`', $this->object->escape_field('test.test'));
+ }
- /**
- * @covers Query_PDO_Driver::escape_value
- * @todo Implement testEscape_value().
- */
- public function testEscape_value()
- {
- $params=array();
- $this->assertEquals('test', $this->object->escape_value(new Expression_Database('test'),$params));
+ /**
+ * @covers Query_PDO_Driver::escape_value
+ * @todo Implement testEscape_value().
+ */
+ public function testEscape_value()
+ {
+ $params = array();
+ $this->assertEquals('test', $this->object->escape_value(new Expression_Database('test'), $params));
$this->assertEquals('?', $this->object->escape_value('korova', $params));
$this->assertArrayHasKey(0, $params);
$this->assertEquals('korova', $params[0]);
- }
+ }
- /**
- * @covers Query_PDO_Driver::query
- * @todo Implement testQuery().
- */
- public function testQuerySelect1()
- {
- $query=$this->object
+ /**
+ * @covers Query_PDO_Driver::query
+ * @todo Implement testQuery().
+ */
+ public function testQuerySelect1()
+ {
+ $query = $this->object
->table('fairies')
->where('a', 7)
->where('b', '<', 8)
@@ -71,13 +75,13 @@ class Query_PDO_DriverTest extends PHPUnit_Framework_TestCase
->where(array(
array('e', 9),
array('or', array(
- array('f', 10),
- array('g', 11),
- )),
+ array('f', 10),
+ array('g', 11),
+ )),
array('or', array(
- array('h', 12),
- array('or',array('i', 13)),
- ))
+ array('h', 12),
+ array('or', array('i', 13)),
+ ))
))
->order_by('id', 'desc')
->group_by('id')
@@ -86,173 +90,172 @@ class Query_PDO_DriverTest extends PHPUnit_Framework_TestCase
->having(array(
array('m', 9),
array('or', array(
- array('n', 10),
- array('o', 11),
- ))
+ array('n', 10),
+ array('o', 11),
+ ))
))
->limit(5)
->offset(6)
->query();
- $this->assertEquals("SELECT * FROM `fairies` WHERE `fairies`.`a` = ? AND `fairies`.`b` < ? AND `fairies`.`c` > ? OR `fairies`.`d` > ? AND ( `fairies`.`e` = ? OR ( `fairies`.`f` = ? AND `fairies`.`g` = ? ) OR ( `fairies`.`h` = ? OR `fairies`.`i` = ? ) ) GROUP BY `fairies`.`id` HAVING `fairies`.`j` < korova OR `fairies`.`l` > ? AND ( `fairies`.`m` = ? OR ( `fairies`.`n` = ? AND `fairies`.`o` = ? ) ) ORDER BY `fairies`.`id` DESC LIMIT 5 OFFSET 6 ",current($query));
-
- }
+ $this->assertEquals("SELECT * FROM `fairies` WHERE `fairies`.`a` = ? AND `fairies`.`b` < ? AND `fairies`.`c` > ? OR `fairies`.`d` > ? AND ( `fairies`.`e` = ? OR ( `fairies`.`f` = ? AND `fairies`.`g` = ? ) OR ( `fairies`.`h` = ? OR `fairies`.`i` = ? ) ) GROUP BY `fairies`.`id` HAVING `fairies`.`j` < korova OR `fairies`.`l` > ? AND ( `fairies`.`m` = ? OR ( `fairies`.`n` = ? AND `fairies`.`o` = ? ) ) ORDER BY `fairies`.`id` DESC LIMIT 5 OFFSET 6 ", current($query));
+ }
+
/**
- * @covers Query_PDO_Driver::query
- * @todo Implement testQuery().
- */
- public function testQuerySelect2()
- {
- $query=$this->object
+ * @covers Query_PDO_Driver::query
+ * @todo Implement testQuery().
+ */
+ public function testQuerySelect2()
+ {
+ $query = $this->object
->table('fairies')
->where('a', 7)
->join('test', array('fairies.test_id', 'test.id'))
->join('test2', array(
array('fairies.test2_id', 'test.test_id'),
array('fairies.test3_id', 'test.id')
- ),'inner')
- ->order_by('id','desc')
+ ), 'inner')
+ ->order_by('id', 'desc')
->query();
- $this->assertEquals("SELECT * FROM `fairies` LEFT JOIN `test` ON `fairies`.`test_id` = `test`.`id` INNER JOIN `test2` ON ( `fairies`.`test2_id` = `test`.`test_id` AND `fairies`.`test3_id` = `test`.`id` ) WHERE `fairies`.`a` = ? ORDER BY `fairies`.`id` DESC ",current($query));
-
- }
-
+ $this->assertEquals("SELECT * FROM `fairies` LEFT JOIN `test` ON `fairies`.`test_id` = `test`.`id` INNER JOIN `test2` ON ( `fairies`.`test2_id` = `test`.`test_id` AND `fairies`.`test3_id` = `test`.`id` ) WHERE `fairies`.`a` = ? ORDER BY `fairies`.`id` DESC ", current($query));
+ }
+
/**
- * @covers Query_PDO_Driver::query
- * @todo Implement testQuery().
- */
- public function testQueryDelete()
- {
- $query=$this->object
+ * @covers Query_PDO_Driver::query
+ * @todo Implement testQuery().
+ */
+ public function testQueryDelete()
+ {
+ $query = $this->object
->type('delete')
->table('fairies')
- ->where('id',1)
+ ->where('id', 1)
->query();
-
- $this->assertEquals("DELETE fairies.* FROM `fairies` WHERE `fairies`.`id` = ? ",current($query));
- }
-
+
+ $this->assertEquals("DELETE fairies.* FROM `fairies` WHERE `fairies`.`id` = ? ", current($query));
+ }
+
/**
- * @covers Query_PDO_Driver::query
- * @todo Implement testQuery().
- */
- public function testQueryInsert()
- {
- $query=$this->object
+ * @covers Query_PDO_Driver::query
+ * @todo Implement testQuery().
+ */
+ public function testQueryInsert()
+ {
+ $query = $this->object
->type('insert')
->table('fairies')
- ->data(array('id'=>1,'name'=>'Trixie'))
+ ->data(array('id' => 1, 'name' => 'Trixie'))
->query();
-
- $this->assertEquals("INSERT INTO `fairies` (`id`, `name`) VALUES(?, ?)",current($query));
- }
-
+
+ $this->assertEquals("INSERT INTO `fairies` (`id`, `name`) VALUES(?, ?)", current($query));
+ }
+
/**
- * @covers Query_PDO_Driver::query
- * @todo Implement testQuery().
- */
- public function testQueryUpdate()
- {
- $query=$this->object
+ * @covers Query_PDO_Driver::query
+ * @todo Implement testQuery().
+ */
+ public function testQueryUpdate()
+ {
+ $query = $this->object
->type('update')
->table('fairies')
- ->data(array('id'=>1,'name'=>'Trixie'))
+ ->data(array('id' => 1, 'name' => 'Trixie'))
->query();
-
- $this->assertEquals("UPDATE `fairies` SET `id` = ?, `name` = ? ",current($query));
- }
-
+
+ $this->assertEquals("UPDATE `fairies` SET `id` = ?, `name` = ? ", current($query));
+ }
+
/**
- * @covers Query_PDO_Driver::query
- * @todo Implement testQuery().
- */
+ * @covers Query_PDO_Driver::query
+ * @todo Implement testQuery().
+ */
public function testQueryCount()
- {
- $query=$this->object
+ {
+ $query = $this->object
->type('count')
->table('fairies')
- ->where('id',8)
+ ->where('id', 8)
->query();
-
- $this->assertEquals("SELECT COUNT(*) as `count` FROM `fairies` WHERE `fairies`.`id` = ? ",current($query));
- }
-
+
+ $this->assertEquals("SELECT COUNT(*) as `count` FROM `fairies` WHERE `fairies`.`id` = ? ", current($query));
+ }
+
/**
- * @covers Query_PDO_Driver::add_alias
- * @todo Implement testQuery().
- */
+ * @covers Query_PDO_Driver::add_alias
+ * @todo Implement testQuery().
+ */
public function testAlias()
- {
+ {
$this->object->table('fairies');
$this->assertEquals('fairies', $this->object->last_alias());
$this->object->add_alias();
- $this->assertEquals('a0',$this->object->last_alias());
- }
-
+ $this->assertEquals('a0', $this->object->last_alias());
+ }
+
/**
- * @covers Query_PDO_Driver::__call
- * @todo Implement testQuery().
- */
+ * @covers Query_PDO_Driver::__call
+ * @todo Implement testQuery().
+ */
public function testCall()
- {
+ {
$this->object->table('fairies');
$this->assertEquals('fairies', $this->object->table());
$except = false;
try {
$this->object->limit('fairies');
- }catch (Exception $e) {
- $except=true;
+ } catch (Exception $e) {
+ $except = true;
}
- $this->assertEquals(true,$except);
- }
-
+ $this->assertEquals(true, $except);
+ }
+
public function testUnion()
{
- $stub=(object)array('db_type'=>'mysql');
+ $stub = (object) array('db_type' => 'mysql');
$subquery = new Query_PDO_Driver($stub, 'select');
$subquery->table('fairies');
$this->object->table('fairies');
$this->object->where('id', '>', 7);
$this->object->union($subquery);
$this->object->union($subquery);
- $this->assertEquals('(SELECT * FROM `fairies` WHERE `fairies`.`id` > ? ) UNION ALL (SELECT * FROM `fairies` ) UNION ALL (SELECT * FROM `fairies` ) ',current($this->object->query()));
+ $this->assertEquals('(SELECT * FROM `fairies` WHERE `fairies`.`id` > ? ) UNION ALL (SELECT * FROM `fairies` ) UNION ALL (SELECT * FROM `fairies` ) ', current($this->object->query()));
}
-
+
public function testSubselect()
{
- $stub=(object)array('db_type'=>'mysql');
+ $stub = (object) array('db_type' => 'mysql');
$subquery = new Query_PDO_Driver($stub, 'select');
$subquery->fields('id')->table('fairies');
$this->object->table('fairies')->where('id', 7)->where('id', 'in', $subquery);
- $this->assertEquals('SELECT * FROM `fairies` WHERE `fairies`.`id` = ? AND `fairies`.`id` in (SELECT `fairies`.`id` FROM `fairies` ) ',current($this->object->query()));
+ $this->assertEquals('SELECT * FROM `fairies` WHERE `fairies`.`id` = ? AND `fairies`.`id` in (SELECT `fairies`.`id` FROM `fairies` ) ', current($this->object->query()));
}
-
+
public function testSubtable()
{
- $stub=(object)array('db_type'=>'mysql');
+ $stub = (object) array('db_type' => 'mysql');
$subquery = new Query_PDO_Driver($stub, 'select');
$subquery->fields('id')->table('fairies');
$this->object->table($subquery)->where('id', 7);
- $this->assertEquals('SELECT * FROM (SELECT `fairies`.`id` FROM `fairies` ) AS a0 WHERE `a0`.`id` = ? ',current($this->object->query()));
+ $this->assertEquals('SELECT * FROM (SELECT `fairies`.`id` FROM `fairies` ) AS a0 WHERE `a0`.`id` = ? ', current($this->object->query()));
}
-
+
public function testJoinSubtable()
{
- $stub=(object)array('db_type'=>'mysql');
+ $stub = (object) array('db_type' => 'mysql');
$subquery = new Query_PDO_Driver($stub, 'select');
$subquery->table('fairies');
$this->object->table($subquery);
$this->object->join('pixies', array('fairies.id', '=', 'pixie.id'));
$this->object->join(array('fairies', 'fae'), array('fairies.id', '=', 'fae.id'));
$this->object->join(array($subquery, 'fae2'), array('fairies.id', '=', 'fae2.id'));
-
-
- $this->assertEquals('SELECT * FROM (SELECT * FROM `fairies` ) AS a0 LEFT JOIN `pixies` ON `fairies`.`id` = `pixie`.`id` LEFT JOIN `fairies` AS fae ON `fairies`.`id` = `fae`.`id` LEFT JOIN (SELECT * FROM `fairies` ) AS fae2 ON `fairies`.`id` = `fae2`.`id` ',current($this->object->query()));
+
+
+ $this->assertEquals('SELECT * FROM (SELECT * FROM `fairies` ) AS a0 LEFT JOIN `pixies` ON `fairies`.`id` = `pixie`.`id` LEFT JOIN `fairies` AS fae ON `fairies`.`id` = `fae`.`id` LEFT JOIN (SELECT * FROM `fairies` ) AS fae2 ON `fairies`.`id` = `fae2`.`id` ', current($this->object->query()));
}
-
+
public function testExpressionSelect()
{
- $this->object->table('fairies')->where('id','in',DB::expr("(SELECT id from fairies)"));
- $this->assertEquals('SELECT * FROM `fairies` WHERE `fairies`.`id` in (SELECT id from fairies) ',current($this->object->query()));
+ $this->object->table('fairies')->where('id', 'in', DB::expr("(SELECT id from fairies)"));
+ $this->assertEquals('SELECT * FROM `fairies` WHERE `fairies`.`id` in (SELECT id from fairies) ', current($this->object->query()));
}
-
+
}
diff --git a/tests/modules/database/driver/pdo/resultTest.php b/tests/modules/database/driver/pdo/resultTest.php
index 3b341b4..0a48d3a 100644
--- a/tests/modules/database/driver/pdo/resultTest.php
+++ b/tests/modules/database/driver/pdo/resultTest.php
@@ -1,125 +1,136 @@
<?php
+
require_once('/../../../../../modules/database/classes/database/result.php');
require_once('/../../../../../modules/database/classes/driver/pdo/result.php');
+
/**
* Generated by PHPUnit_SkeletonGenerator 1.2.0 on 2013-02-06 at 20:48:50.
*/
class Result_PDO_DriverTest extends PHPUnit_Framework_TestCase
{
- /**
- * @var Result_PDO_Driver
- */
- protected $object;
-
- /**
- * Sets up the fixture, for example, opens a network connection.
- * This method is called before a test is executed.
- */
- protected function setUp()
- {
+
+ /**
+ * @var Result_PDO_Driver
+ */
+ protected $object;
+
+ /**
+ * Sets up the fixture, for example, opens a network connection.
+ * This method is called before a test is executed.
+ */
+ protected function setUp()
+ {
$db = new PDO('sqlite::memory:');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->exec("CREATE TABLE fairies(id INT,name VARCHAR(255))");
-
+
$db->exec("INSERT INTO fairies (id,name) VALUES (1,'Tinkerbell')");
$db->exec("INSERT INTO fairies (id,name) VALUES (2,'Trixie')");
-
+
$q = $db->prepare("SELECT * from fairies");
$q->execute();
- $this->object = new Result_PDO_Driver($q);
- }
-
- /**
- * Tears down the fixture, for example, closes a network connection.
- * This method is called after a test is executed.
- */
- protected function tearDown()
- {
-
- }
-
- /**
- * @covers Result_PDO_Driver::rewind
- * @todo Implement testRewind().
- */
- public function testRewind()
- {
- $except = false;
+ $this->object = new Result_PDO_Driver($q);
+ }
+
+ /**
+ * Tears down the fixture, for example, closes a network connection.
+ * This method is called after a test is executed.
+ */
+ protected function tearDown()
+ {
+
+ }
+
+ /**
+ * @covers Result_PDO_Driver::rewind
+ * @todo Implement testRewind().
+ */
+ public function testRewind()
+ {
+ $except = false;
$this->object->valid();
$this->object->rewind();
$this->object->next();
try {
$this->object->rewind();
- }catch(Exception $e) {
- $except=true;
+ } catch (Exception $e) {
+ $except = true;
}
- $this->assertEquals(true,$except);
- }
+ $this->assertEquals(true, $except);
+ }
-
/**
- * @covers Result_PDO_Driver::current
- */
- public function testCurrent() {
- $this->assertEquals($this->object->current()->name,'Tinkerbell');
+ * @covers Result_PDO_Driver::current
+ */
+ public function testCurrent()
+ {
+ $this->assertEquals($this->object->current()->name, 'Tinkerbell');
}
-
+
/**
- * @covers Result_PDO_Driver::valid
- */
- public function testVaid() {
- $this->assertEquals($this->object->valid(),true);
+ * @covers Result_PDO_Driver::valid
+ */
+ public function testVaid()
+ {
+ $this->assertEquals($this->object->valid(), true);
}
-
+
/**
- * @covers Result_PDO_Driver::key
- */
- public function testKey() {
- $this->assertEquals($this->object->key(),0);
+ * @covers Result_PDO_Driver::key
+ */
+ public function testKey()
+ {
+ $this->assertEquals($this->object->key(), 0);
}
-
+
/**
- * @covers Result_PDO_Driver::key
- */
- public function testGet() {
- $this->assertEquals($this->object->get('id'),1);
+ * @covers Result_PDO_Driver::key
+ */
+ public function testGet()
+ {
+ $this->assertEquals($this->object->get('id'), 1);
}
-
+
/**
- * @covers Result_PDO_Driver::as_array
- */
- public function testAs_Array() {
+ * @covers Result_PDO_Driver::as_array
+ */
+ public function testAs_Array()
+ {
$arr = $this->object->as_array();
$this->assertArrayHasKey(0, $arr);
- $this->assertArrayHasKey('name', (array)$arr[0]);
+ $this->assertArrayHasKey('name', (array) $arr[0]);
$this->assertEquals($arr[0]->name, 'Tinkerbell');
$this->assertArrayHasKey(1, $arr);
- $this->assertArrayHasKey('id', (array)$arr[1]);
+ $this->assertArrayHasKey('id', (array) $arr[1]);
$this->assertEquals($arr[1]->id, 2);
}
-
- public function testIterator(){
+
+ public function testIterator()
+ {
$this->assertEquals($this->object->valid(), true);
$this->assertEquals($this->object->get('id'), 1);
- foreach($this->object as $key => $row) {
- if ($key == 0) {
+ foreach ($this->object as $key => $row)
+ {
+ if ($key == 0)
+ {
$this->assertEquals($row->name, 'Tinkerbell');
$this->assertEquals($row->id, 1);
}
- if ($key == 1) {
+ if ($key == 1)
+ {
$this->assertEquals($row->name, 'Trixie');
$this->assertEquals(2, $this->object->get('id'));
$this->assertEquals($row->id, 2);
}
}
- $this->assertEquals(false,$this->object->valid());
+ $this->assertEquals(false, $this->object->valid());
$this->assertEquals(null, $this->object->get('id'));
$this->assertEquals(null, $this->object->current());
$this->object->next();
$this->object->next();
$this->object->next();
- $this->assertEquals(1,$this->object->key());
-
+ $this->assertEquals(1, $this->object->key());
}
+
}
diff --git a/tests/modules/database/files/config.sqlite b/tests/modules/database/files/config.sqlite
index 34eea03..401e0ff 100644
--- a/tests/modules/database/files/config.sqlite
+++ b/tests/modules/database/files/config.sqlite
@@ -1,7 +1,9 @@
-<?php return array (
- 'default' =>
- array (
- 'connection' => 'sqlite:C:\\Users\\Dracony\\Documents\\GitHub\\PHPixie\\tests\\modules\\database\\driver\\pdo/../../files/test.sqlite',
- 'driver' => 'pdo',
- ),
-); \ No newline at end of file
+<?php
+
+return array(
+ 'default' =>
+ array(
+ 'connection' => 'sqlite:C:\\Users\\Dracony\\Documents\\GitHub\\PHPixie\\tests\\modules\\database\\driver\\pdo/../../files/test.sqlite',
+ 'driver' => 'pdo',
+ ),
+);