diff options
author | Tom Gregory <[email protected]> | 2013-01-22 00:23:04 -0500 |
---|---|---|
committer | Tom Gregory <[email protected]> | 2013-01-22 00:23:04 -0500 |
commit | 98b806652bab694797c0d09b41f198b7bf6f2c4c (patch) | |
tree | 077eefaaea3098418fa9eea317b87a854abd6f51 /test/ORMTest.php | |
parent | 349532a2c5b8d968f8fa7743b33b8d50d3525630 (diff) | |
parent | 6391acb3371e07742cf94c7c4bc4cc3888a6cae5 (diff) |
Merge remote-tracking branch 'upstream/develop' into dev-multi. Updated documentation to rat format, and tests to use phpunit.
(Resolved)Conflicts:
README.markdown
idiorm.php
test/test_queries.php
Diffstat (limited to 'test/ORMTest.php')
-rw-r--r-- | test/ORMTest.php | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/test/ORMTest.php b/test/ORMTest.php new file mode 100644 index 0000000..ced3cbd --- /dev/null +++ b/test/ORMTest.php @@ -0,0 +1,87 @@ +<?php + +class ORMTest extends PHPUnit_Framework_TestCase { + + public function setUp() { + // Enable logging + ORM::configure('logging', true); + + // Set up the dummy database connection + $db = new MockPDO('sqlite::memory:'); + ORM::set_db($db); + } + + public function tearDown() { + ORM::configure('logging', false); + ORM::set_db(null); + } + + public function testStaticAtrributes() { + $this->assertEquals('0', ORM::CONDITION_FRAGMENT); + $this->assertEquals('1', ORM::CONDITION_VALUES); + } + + public function testForTable() { + $result = ORM::for_table('test'); + $this->assertInstanceOf('ORM', $result); + } + + public function testCreate() { + $model = ORM::for_table('test')->create(); + $this->assertInstanceOf('ORM', $model); + $this->assertTrue($model->is_new()); + } + + public function testIsNew() { + $model = ORM::for_table('test')->create(); + $this->assertTrue($model->is_new()); + + $model = ORM::for_table('test')->create(array('test' => 'test')); + $this->assertTrue($model->is_new()); + } + + public function testIsDirty() { + $model = ORM::for_table('test')->create(); + $this->assertFalse($model->is_dirty('test')); + + $model = ORM::for_table('test')->create(array('test' => 'test')); + $this->assertTrue($model->is_dirty('test')); + } + + public function testArrayAccess() { + $value = 'test'; + $model = ORM::for_table('test')->create(); + $model['test'] = $value; + $this->assertTrue(isset($model['test'])); + $this->assertEquals($model['test'], $value); + unset($model['test']); + $this->assertFalse(isset($model['test'])); + } + + public function testFindResultSet() { + $result_set = ORM::for_table('test')->find_result_set(); + $this->assertInstanceOf('IdiormResultSet', $result_set); + $this->assertSame(count($result_set), 5); + } + + public function testFindResultSetByDefault() { + ORM::configure('return_result_sets', true); + + $result_set = ORM::for_table('test')->find_many(); + $this->assertInstanceOf('IdiormResultSet', $result_set); + $this->assertSame(count($result_set), 5); + + ORM::configure('return_result_sets', false); + + $result_set = ORM::for_table('test')->find_many(); + $this->assertInternalType('array', $result_set); + $this->assertSame(count($result_set), 5); + } + + public function testGetLastPdoStatement() { + ORM::for_table('widget')->where('name', 'Fred')->find_one(); + $statement = ORM::get_last_statement(); + $this->assertInstanceOf('MockPDOStatement', $statement); + } + +}
\ No newline at end of file |