Copyright (c) 2013, Erik Wiesenthal All rights reserved http://github.com/Surt/Granada/ Idiorm with some small changes ( http://github.com/Surt/Granada/ ). Idiorm http://github.com/j4mie/idiorm/ A single-class super-simple database abstraction layer for PHP. Provides (nearly) zero-configuration object-relational mapping and a fluent interface for building basic, commonly-used queries. BSD Licensed. Copyright (c) 2010, Jamie Matthews All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Inheritance: implements ArrayAcces\ArrayAccess
Example #1
0
 public function testQueryGenerationOnlyOccursOnceWithMultipleConnections()
 {
     // Test caching with multiple connections (also a bit of a hack)
     ORM::for_table('widget', self::ALTERNATE)->where('name', 'Steve')->where('age', 80)->find_one();
     ORM::for_table('widget', self::ALTERNATE)->where('name', 'Tom')->where('age', 120)->find_one();
     $expected = ORM::get_last_query();
     ORM::for_table('widget', self::ALTERNATE)->where('name', 'Steve')->where('age', 80)->find_one();
     // this shouldn't run a query!
     $this->assertEquals($expected, ORM::get_last_query(self::ALTERNATE));
 }
Example #2
0
 public function testLoggerCallback()
 {
     ORM::configure('logger', function ($log_string) {
         return $log_string;
     });
     $function = ORM::get_config('logger');
     $this->assertTrue(is_callable($function));
     $log_string = "UPDATE `widget` SET `added` = NOW() WHERE `id` = '1'";
     $this->assertEquals($log_string, $function($log_string));
     ORM::configure('logger', null);
 }
 public function testCallingMethods()
 {
     $result_set = array('item' => ORM::for_table('test'), 'item2' => ORM::for_table('test'));
     $ResultSet = new ResultSet($result_set);
     $ResultSet->set('field', 'value')->set('field2', 'value');
     foreach ($ResultSet as $record) {
         $this->assertTrue(isset($record->field));
         $this->assertSame($record->field, 'value');
         $this->assertTrue(isset($record->field2));
         $this->assertSame($record->field2, 'value');
     }
 }
 public function testFindOneOverDifferentConnections()
 {
     ORM::for_table('widget')->find_one();
     $statementOne = ORM::get_last_statement();
     $this->assertInstanceOf('MockPDOStatement', $statementOne);
     ORM::for_table('person', self::ALTERNATE)->find_one();
     $statementOne = ORM::get_last_statement();
     // get_statement is *not* per connection
     $this->assertInstanceOf('MockDifferentPDOStatement', $statementOne);
     $expected = "SELECT * FROM `widget` LIMIT 1";
     $this->assertNotEquals($expected, ORM::get_last_query());
     // Because get_last_query() is across *all* connections
     $this->assertEquals($expected, ORM::get_last_query(ORM::DEFAULT_CONNECTION));
     $expectedToo = "SELECT * FROM `person` LIMIT 1";
     $this->assertEquals($expectedToo, ORM::get_last_query(self::ALTERNATE));
 }
Example #5
0
 /**
  * Wrap Idiorm's create method to return an
  * empty instance of the class associated with
  * this wrapper instead of the raw ORM class.
  */
 public function create($data = null)
 {
     $model = $this->_create_model_instance(parent::create(null));
     if ($data !== null) {
         $model->set($data);
     }
     return $model;
 }
Example #6
0
 public function testGetLastPdoStatement()
 {
     ORM::for_table('widget')->where('name', 'Fred')->find_one();
     $statement = ORM::get_last_statement();
     $this->assertInstanceOf('MockPDOStatement', $statement);
 }
Example #7
0
 public function testIssue90UsingSetExprAloneDoesTriggerQueryGeneration()
 {
     $widget = ORM::for_table('widget')->find_one(1);
     $widget->set_expr('added', 'NOW()');
     $widget->save();
     $expected = "UPDATE `widget` SET `added` = NOW() WHERE `id` = '1'";
     $this->assertEquals($expected, ORM::get_last_query());
 }
 public function testLimit()
 {
     ORM::for_table('widget')->limit(5)->find_many();
     $expected = 'SELECT TOP 5 * FROM "widget"';
     $this->assertEquals($expected, ORM::get_last_query());
 }
Example #9
0
 public function testGetConfigArray()
 {
     $expected = array('connection_string' => 'sqlite::memory:', 'id_column' => 'primary_key', 'id_column_overrides' => array(), 'error_mode' => PDO::ERRMODE_EXCEPTION, 'username' => null, 'password' => null, 'driver_options' => null, 'identifier_quote_character' => '`', 'logging' => true, 'logger' => null, 'caching' => false, 'return_result_sets' => true, 'limit_clause_style' => 'limit', 'find_many_primary_id_as_key' => true);
     $this->assertEquals($expected, ORM::get_config());
 }