diff options
Diffstat (limited to 'tests/modules/orm/ormTest.php')
-rw-r--r-- | tests/modules/orm/ormTest.php | 534 |
1 files changed, 267 insertions, 267 deletions
diff --git a/tests/modules/orm/ormTest.php b/tests/modules/orm/ormTest.php index f6b4b6a..ca85182 100644 --- a/tests/modules/orm/ormTest.php +++ b/tests/modules/orm/ormTest.php @@ -1,158 +1,160 @@ <?php + require_once('/../../../modules/orm/classes/orm.php'); require_once('/files/tree_orm.php'); require_once('/files/fairy_orm.php'); + /** * Generated by PHPUnit_SkeletonGenerator on 2013-02-08 at 21:28:15. */ class ORMTest extends PHPUnit_Framework_TestCase { - /** - * @var ORM - */ - 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 ORM + */ + 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),tree_id INT)"); $db->exec("CREATE TABLE trees(id INT PRIMARY_KEY,name VARCHAR(255),protector_id INT)"); $db->exec("CREATE TABLE friends(fairy_id INT,friend_id INT)"); - + $db->exec("INSERT INTO fairies(id,name,tree_id) VALUES (1,'Tinkerbell',1)"); $db->exec("INSERT INTO fairies(id,name,tree_id) VALUES (2,'Trixie',2)"); - + $db->exec("INSERT INTO trees(id,name,protector_id) VALUES (1,'Oak',2)"); $db->exec("INSERT INTO trees(id,name,protector_id) VALUES (2,'Willow',2)"); - + $db->exec("INSERT INTO friends(fairy_id,friend_id) VALUES (1,2)"); - - + + Misc::$file = dirname(__FILE__).'./files/config.php'; file_put_contents(Misc::$file, "<?php return ".var_export(array( - 'orm' => array( - 'connection' => 'sqlite:'.dirname(__FILE__).'./files/test.sqlite', - 'driver'=>'pdo' - ) - ), true).';'); + 'orm' => array( + 'connection' => 'sqlite:'.dirname(__FILE__).'./files/test.sqlite', + 'driver' => 'pdo' + ) + ), true).';'); Config::set('database.orm.connection', 'sqlite:'.dirname(__FILE__).'./files/test.sqlite'); - Config::set('database.orm.driver','pdo'); - - $this->fairies = new Fairy_Model; + Config::set('database.orm.driver', 'pdo'); + + $this->fairies = new Fairy_Model; $this->trees = new Tree_Model; - } - - /** - * Tears down the fixture, for example, closes a network connection. - * This method is called after a test is executed. - */ - protected function tearDown() - { - - } - - /** - * @covers ORM::__call - * @todo Implement test__call(). - */ - public function test__call() - { - $this->fairies->limit(6); - $this->fairies->offset(5); - $this->assertEquals(6, $this->fairies->limit()); - $this->assertEquals(5, $this->fairies->offset()); - $this->fairies->where('id', 8); - $this->fairies->order_by('id', 'desc'); - - } - - /** - * @covers ORM::find_all - * @todo Implement testFind_all(). - */ - public function testFind_all() - { - - $this->assertEquals('Trixie',ORM::factory('fairy')->where('id',2)->find_all()->current()->name); - } - - /** - * @covers ORM::find - * @todo Implement testFind(). - */ - public function testFind() - { - $this->assertEquals('Trixie',$this->fairies->where('id',2)->find()->name); - } - - /** - * @covers ORM::count_all - * @todo Implement testCount_all(). - */ - public function testCount_all() - { - $this->assertEquals(2, $this->fairies->count_all()); + } + + /** + * Tears down the fixture, for example, closes a network connection. + * This method is called after a test is executed. + */ + protected function tearDown() + { + + } + + /** + * @covers ORM::__call + * @todo Implement test__call(). + */ + public function test__call() + { + $this->fairies->limit(6); + $this->fairies->offset(5); + $this->assertEquals(6, $this->fairies->limit()); + $this->assertEquals(5, $this->fairies->offset()); + $this->fairies->where('id', 8); + $this->fairies->order_by('id', 'desc'); + } + + /** + * @covers ORM::find_all + * @todo Implement testFind_all(). + */ + public function testFind_all() + { + + $this->assertEquals('Trixie', ORM::factory('fairy')->where('id', 2)->find_all()->current()->name); + } + + /** + * @covers ORM::find + * @todo Implement testFind(). + */ + public function testFind() + { + $this->assertEquals('Trixie', $this->fairies->where('id', 2)->find()->name); + } + + /** + * @covers ORM::count_all + * @todo Implement testCount_all(). + */ + public function testCount_all() + { + $this->assertEquals(2, $this->fairies->count_all()); $this->assertEquals(0, $this->fairies->find()->protects->count_all()); $this->assertEquals(1, $this->fairies->where('id', 2)->count_all()); $this->assertEquals(2, ORM::factory('fairy')->where('id', 2)->protects->count_all()); - } - - /** - * @covers ORM::loaded - * @todo Implement testLoaded(). - */ - public function testLoaded() - { - $this->assertEquals(false,$this->fairies->loaded()); - $this->assertEquals(true,$this->fairies->find()->loaded()); - } - - /** - * @covers ORM::as_array - * @todo Implement testAs_array(). - */ - public function testAs_array() - { - $arr = $this->fairies->find()->as_array(); - $this->assertEquals('Tinkerbell',$arr['name']); - } - - /** - * @covers ORM::query - * @todo Implement testQuery(). - */ - public function testQuery() - { - $this->fairies->limit(5); - $this->assertEquals(5,$this->fairies->query()->limit()); - } - - /** - * @covers ORM::get - * @todo Implement testGet(). - */ - public function testGet() - { + } + + /** + * @covers ORM::loaded + * @todo Implement testLoaded(). + */ + public function testLoaded() + { + $this->assertEquals(false, $this->fairies->loaded()); + $this->assertEquals(true, $this->fairies->find()->loaded()); + } + + /** + * @covers ORM::as_array + * @todo Implement testAs_array(). + */ + public function testAs_array() + { + $arr = $this->fairies->find()->as_array(); + $this->assertEquals('Tinkerbell', $arr['name']); + } + + /** + * @covers ORM::query + * @todo Implement testQuery(). + */ + public function testQuery() + { + $this->fairies->limit(5); + $this->assertEquals(5, $this->fairies->query()->limit()); + } + + /** + * @covers ORM::get + * @todo Implement testGet(). + */ + public function testGet() + { $dd = array('fff' => 44); - $fairy = $this->fairies->find(); + $fairy = $this->fairies->find(); $fairy->test; - $this->assertEquals(5,$fairy->cached['test']); - } - - /** - * @covers ORM::__get - * @todo Implement test__get(). - */ - public function test__get() - { - $this->assertEquals('Oak', $this->fairies->tree-> find_all()->current()->name); + $this->assertEquals(5, $fairy->cached['test']); + } + + /** + * @covers ORM::__get + * @todo Implement test__get(). + */ + public function test__get() + { + $this->assertEquals('Oak', $this->fairies->tree->find_all()->current()->name); $this->assertEquals('Oak', $this->fairies->find()->tree->name); $this->assertEquals('Tinkerbell', $this->trees->find()->fairy->name); $this->assertEquals('Tinkerbell', $this->trees->find()->fairy->name); @@ -163,174 +165,172 @@ class ORMTest extends PHPUnit_Framework_TestCase $this->assertEquals('Trixie', $this->trees->protector->find()->name); $this->assertEquals('Trixie', ORM::factory('fairy')->find()->friends->find()->name); - - } + } /** - * @covers ORM::add - * @todo Implement testAdd(). - */ - public function testAdd() - { - $fairy = ORM::factory('fairy')->find(); + * @covers ORM::add + * @todo Implement testAdd(). + */ + public function testAdd() + { + $fairy = ORM::factory('fairy')->find(); $fairy->add('tree', ORM::factory('tree')->where('id', 2)->find()); $fairy->save(); - $this->assertEquals('Willow', ORM::factory('fairy')->find()->tree-> name); - + $this->assertEquals('Willow', ORM::factory('fairy')->find()->tree->name); + $fairy = ORM::factory('fairy'); $fairy->add('tree', ORM::factory('tree')->where('id', 2)->find()); - $fairy->id=3; + $fairy->id = 3; $fairy->save(); $fairy = ORM::factory('fairy', 3); $this->assertEquals('Willow', $fairy->tree->name); - - $tree=ORM::factory('tree')->find(); - $fairy=ORM::factory('fairy'); - $tree-> fairy = $fairy; + + $tree = ORM::factory('tree')->find(); + $fairy = ORM::factory('fairy'); + $tree->fairy = $fairy; $fairy->id = 4; $fairy->save(); - $this->assertEquals('Oak', ORM::factory('fairy',4)->tree->name); - - - $fairy = ORM::factory('fairy')->where('id',2)->find(); - $fairy->add('friends',ORM::factory('fairy')->where('id', 1)->find()); - $this->assertEquals('Tinkerbell',ORM::factory('fairy')->where('id',2)->find()->friends->find()->name); - } - - /** - * @covers ORM::__set - * @todo Implement test__set(). - */ - public function test__set() - { - $fairy = $this->fairies->find(); + $this->assertEquals('Oak', ORM::factory('fairy', 4)->tree->name); + + + $fairy = ORM::factory('fairy')->where('id', 2)->find(); + $fairy->add('friends', ORM::factory('fairy')->where('id', 1)->find()); + $this->assertEquals('Tinkerbell', ORM::factory('fairy')->where('id', 2)->find()->friends->find()->name); + } + + /** + * @covers ORM::__set + * @todo Implement test__set(). + */ + public function test__set() + { + $fairy = $this->fairies->find(); $fairy->name = 'test'; $this->assertEquals('test', $fairy->name); - - $fairy = ORM::factory('fairy')->where('id',2)->find(); + + $fairy = ORM::factory('fairy')->where('id', 2)->find(); $fairy->friends = ORM::factory('fairy')->where('id', 1)->find(); - $this->assertEquals('Tinkerbell', ORM::factory('fairy')->where('id',2)->find()->friends->find()->name); - - ORM::factory('tree')->where('id',2)->find()->fairy = ORM::factory('fairy')->find(); + $this->assertEquals('Tinkerbell', ORM::factory('fairy')->where('id', 2)->find()->friends->find()->name); + + ORM::factory('tree')->where('id', 2)->find()->fairy = ORM::factory('fairy')->find(); ORM::factory('tree')->find()->fairy = ORM::factory('fairy')->where('id', 2)->find(); - + $this->assertEquals('Trixie', ORM::factory('tree')->find()->fairy->name); - } - - - /** - * @covers ORM::remove - * @todo Implement testRemove(). - */ - public function testRemove() - { - $fairy = ORM::factory('fairy')->find(); - $fairy->remove('tree'); - - $this->assertEquals(false, $fairy->tree->loaded()); - - $fairy->remove('friends', ORM::factory('fairy')->where('id', 2)->find()); - $this->assertEquals(false, $fairy->friends->find()->loaded()); - - $fairy = ORM::factory('fairy')->where('id',2)->find(); - $fairy->remove('protects',ORM::factory('tree')->where('id',1)->find()); - $this->assertEquals('Willow', $fairy->protects->find()->name); - - } - - /** - * @covers ORM::columns - * @todo Implement testColumns(). - */ - public function testColumns() - { - $cols=$this->fairies->columns(); - $this->assertEquals('id', $cols[0]); + } + + /** + * @covers ORM::remove + * @todo Implement testRemove(). + */ + public function testRemove() + { + $fairy = ORM::factory('fairy')->find(); + $fairy->remove('tree'); + + $this->assertEquals(false, $fairy->tree->loaded()); + + $fairy->remove('friends', ORM::factory('fairy')->where('id', 2)->find()); + $this->assertEquals(false, $fairy->friends->find()->loaded()); + + $fairy = ORM::factory('fairy')->where('id', 2)->find(); + $fairy->remove('protects', ORM::factory('tree')->where('id', 1)->find()); + $this->assertEquals('Willow', $fairy->protects->find()->name); + } + + /** + * @covers ORM::columns + * @todo Implement testColumns(). + */ + public function testColumns() + { + $cols = $this->fairies->columns(); + $this->assertEquals('id', $cols[0]); $this->assertEquals('name', $cols[1]); - $this->assertEquals('tree_id',$cols[2]); - } - - /** - * @covers ORM::with - * @todo Implement testWith(). - */ - public function testWith() - { - $res = $this->fairies->with('tree', 'tree.protector')->find(); + $this->assertEquals('tree_id', $cols[2]); + } + + /** + * @covers ORM::with + * @todo Implement testWith(). + */ + public function testWith() + { + $res = $this->fairies->with('tree', 'tree.protector')->find(); $this->assertEquals('Oak', $res->cached['tree']->name); - $this->assertEquals('Trixie',$res->cached['tree']->cached['protector']->name); - } - - /** - * @covers ORM::delete - * @todo Implement testDelete(). - */ - public function testDelete() - { - $this->fairies->find()->delete(); - $this->assertEquals('Trixie',$this->fairies->find()->name); - } - + $this->assertEquals('Trixie', $res->cached['tree']->cached['protector']->name); + } + /** - * @covers ORM::delete - * @todo Implement testDelete(). - */ - public function testDeleteException() - { + * @covers ORM::delete + * @todo Implement testDelete(). + */ + public function testDelete() + { + $this->fairies->find()->delete(); + $this->assertEquals('Trixie', $this->fairies->find()->name); + } + + /** + * @covers ORM::delete + * @todo Implement testDelete(). + */ + public function testDeleteException() + { $except = false; - try{ + try { $this->fairies->delete(); - }catch (Exception $e) { - $except=true; + } catch (Exception $e) { + $except = true; } - $this->assertEquals(true,$except); - } - - /** - * @covers ORM::delete_all - * @todo Implement testDelete_all(). - */ - public function testDelete_all() - { - $this->fairies->delete_all(); - $this->assertEquals(false,$this->fairies->find()->loaded()); - } - - /** - * @covers ORM::save - * @todo Implement testSave(). - */ - public function testSave() - { - $fairy = $this->fairies->find(); + $this->assertEquals(true, $except); + } + + /** + * @covers ORM::delete_all + * @todo Implement testDelete_all(). + */ + public function testDelete_all() + { + $this->fairies->delete_all(); + $this->assertEquals(false, $this->fairies->find()->loaded()); + } + + /** + * @covers ORM::save + * @todo Implement testSave(). + */ + public function testSave() + { + $fairy = $this->fairies->find(); $fairy->name = 'test'; $fairy->save(); $this->assertEquals('test', $this->fairies->find()->name); - + $fairy = ORM::factory('fairy'); $fairy->name = 'test2'; $fairy->id = 3; $fairy->save(); - $this->assertEquals('test2', $this->fairies->order_by('id','desc')->find()->name); - } - - /** - * @covers ORM::values - * @todo Implement testValues(). - */ - public function testValues() - { - $fairy = $this->fairies->find(); - $fairy->values(array('id' => 1, 'name' => 'Trixie')); - $this->assertEquals('Trixie',$fairy->name); - } - - /** - * @covers ORM::factory - * @todo Implement testFactory(). - */ - public function testFactory() - { - $this->assertEquals('fairy',ORM::factory('fairy')->model_name); - } + $this->assertEquals('test2', $this->fairies->order_by('id', 'desc')->find()->name); + } + + /** + * @covers ORM::values + * @todo Implement testValues(). + */ + public function testValues() + { + $fairy = $this->fairies->find(); + $fairy->values(array('id' => 1, 'name' => 'Trixie')); + $this->assertEquals('Trixie', $fairy->name); + } + + /** + * @covers ORM::factory + * @todo Implement testFactory(). + */ + public function testFactory() + { + $this->assertEquals('fairy', ORM::factory('fairy')->model_name); + } + } |