public function set_up($connection_name = null)
 {
     ActiveRecord\Table::clear_cache();
     $config = ActiveRecord\Config::instance();
     $this->original_default_connection = $config->get_default_connection();
     $this->original_date_class = $config->get_date_class();
     if ($connection_name) {
         $config->set_default_connection($connection_name);
     }
     if ($connection_name == 'sqlite' || $config->get_default_connection() == 'sqlite') {
         // need to create the db. the adapter specifically does not create it for us.
         static::$db = substr(ActiveRecord\Config::instance()->get_connection('sqlite'), 9);
         new SQLite3(static::$db);
     }
     $this->connection_name = $connection_name;
     try {
         $this->conn = ActiveRecord\ConnectionManager::get_connection($connection_name);
     } catch (ActiveRecord\DatabaseException $e) {
         $this->mark_test_skipped($connection_name . ' failed to connect. ' . $e->getMessage());
     }
     $GLOBALS['ACTIVERECORD_LOG'] = false;
     $loader = new DatabaseLoader($this->conn);
     $loader->reset_table_data();
     if (self::$log) {
         $GLOBALS['ACTIVERECORD_LOG'] = true;
     }
 }
 public function set_up($connection_name = null)
 {
     ActiveRecord\Table::clear_cache();
     $config = ActiveRecord\Config::instance();
     $this->original_default_connection = $config->get_default_connection();
     if ($connection_name) {
         $config->set_default_connection($connection_name);
     }
     if ($connection_name == 'sqlite' || $config->get_default_connection() == 'sqlite') {
         // need to create the db. the adapter specifically does not create it for us.
         $this->db = substr(ActiveRecord\Config::instance()->get_connection('sqlite'), 9);
         new SQLite3($this->db);
     }
     $this->conn = ActiveRecord\ConnectionManager::get_connection($connection_name);
     $GLOBALS['ACTIVERECORD_LOG'] = false;
     $loader = new DatabaseLoader($this->conn);
     $loader->reset_table_data();
     if (self::$log) {
         $GLOBALS['ACTIVERECORD_LOG'] = true;
     }
 }
 public function test_clear_cache_for_specific_class()
 {
     $book_table1 = ActiveRecord\Table::load('Book');
     $book_table2 = ActiveRecord\Table::load('Book');
     ActiveRecord\Table::clear_cache('Book');
     $book_table3 = ActiveRecord\Table::load('Book');
     $this->assert_true($book_table1 === $book_table2);
     $this->assert_true($book_table1 !== $book_table3);
 }
Beispiel #4
0
 public function test_before_validation_returned_false_halts_execution()
 {
     VenueCB::$before_validation = array('before_validation_halt_execution');
     ActiveRecord\Table::clear_cache('VenueCB');
     $table = ActiveRecord\Table::load('VenueCB');
     $v = VenueCB::find(1);
     $v->name .= 'test';
     $ret = $v->save();
     $this->assert_false($ret);
     $this->assert_true(strpos(ActiveRecord\Table::load('VenueCB')->last_sql, 'UPDATE') === false);
 }
 public function test_gh_28_after_create_should_be_invoked_after_auto_incrementing_pk_is_set()
 {
     $that = $this;
     VenueCB::$after_create = function ($model) use($that) {
         $that->assert_not_null($model->id);
     };
     ActiveRecord\Table::clear_cache('VenueCB');
     $venue = VenueCB::find(1);
     $venue = new VenueCB($venue->attributes());
     $venue->id = null;
     $venue->name = 'alksdjfs';
     $venue->save();
 }