public function setUp() { parent::setUp(); Cache::flush(); // books / authors / contacts Schema\Builder::getInstance()->migrate(App::collection('contacts')->getModel(), array('relationships' => array('belongs_to' => 'author'))); Schema\Builder::getInstance()->migrate(App::collection('authors')->getModel(), array('relationships' => array('has_many' => array('books', 'contacts')))); Schema\Builder::getInstance()->migrate(App::collection('books')->getModel(), array('relationships' => array('belongs_to' => array('author')))); // clear tables before running tests App::collection('authors')->truncate(); App::collection('books')->truncate(); App::collection('contacts')->truncate(); // populate simple data $author = App::collection('authors')->create(array('name' => "Rasmus Lerdorf")); $author->contacts()->create(array('name' => "Kevin Tatroe")); $author->contacts()->create(array('name' => "Peter MacIntyre")); // default create $book = App::collection('books')->create(array('name' => "Programming PHP", 'author_id' => $author->_id)); $this->assertFalse(isset($book['author']), "shouldn't eager load related data by default"); $eager_loaded_book = CollectionDelegator::queryEagerLoadRelations($book, array('author')); $this->assertTrue($eager_loaded_book['author']['name'] == "Rasmus Lerdorf", "should eager load related data"); $book_with_author = App::collection('books')->join("author")->create(array('name' => "Programming PHP", 'author_id' => $author->_id)); $this->assertTrue($book_with_author['author']['name'] == "Rasmus Lerdorf", "should eager load related data"); // teams / matches Schema\Builder::getInstance()->migrate(App::collection('matches')->getModel(), array('relationships' => array('belongs_to' => array(array('house' => array('collection' => 'teams')), array('guest' => array('collection' => 'teams')))))); Schema\Builder::getInstance()->migrate(App::collection('teams')->getModel(), array('relationships' => array('has_many' => 'matches'))); App::collection('teams')->truncate(); App::collection('matches')->truncate(); $brazil = App::collection('teams')->create(array('name' => "Brazil")); $germany = App::collection('teams')->create(array('name' => "Germany")); $argentina = App::collection('teams')->create(array('name' => "Argentina")); $netherlands = App::collection('teams')->create(array('name' => "Netherlands")); App::collection('matches')->create(array('name' => "Brazil vs Germany", 'house_id' => $brazil->_id, 'guest_id' => $germany->_id)); App::collection('matches')->create(array('name' => "Argentina vs Netherlands", 'house_id' => $argentina->_id, 'guest_id' => $netherlands->_id)); }
public function testBelongsToIndex() { Cache::flush(); Schema\Builder::getInstance()->migrate(App::collection('auths')->getModel(), array('attributes' => array(array('name' => 'lucky_number_id', 'type' => 'integer', 'unique' => true)), 'relationships' => array('belongs_to' => 'lucky_numbers'))); $auths_cache = SchemaCache::get('auths'); $this->assertTrue($auths_cache['attributes'][0]['name'] == 'lucky_number_id'); }
public function testMigrateFields() { Cache::flush(); $attributes = array(array('name' => "default_is_string"), array('name' => "string", 'type' => "string"), array('name' => "int", 'type' => "integer"), array('name' => "float", 'type' => "float"), array('name' => "boolean", 'type' => "boolean")); // books / authors / contacts Schema\Builder::getInstance()->migrate(App::collection('schema')->getModel(), array('attributes' => $attributes)); $dump = Schema\Builder::getInstance()->dump(); $this->assertTrue(count($dump['schemas']['attributes']) == 5); $this->assertTrue($dump['schemas']['attributes'] == $attributes); }
public function deploy() { set_time_limit(0); $statuses = array(); // application configs $configs = Input::get('config', array()); $configs['security'] = Input::get('security', array()); // Flush cache on deployment Cache\Cache::flush(); // Migrate and keep schema cache $collections_migrated = 0; foreach (Input::get('schema', array()) as $collection => $config) { if (Schema\Builder::getInstance()->migrate(Model\App::collection($collection)->getModel(), $config)) { $collections_migrated += 1; } } $statuses['schema'] = $collections_migrated; // do we have write permission on this server? if (is_writable(storage_dir())) { $statuses['config'] = Config::deploy($configs); $statuses['schedule'] = Model\ScheduledTask::deploy(Input::get('schedule', array())); // install composer packages $statuses['packages'] = Package\Manager::install(Input::get('packages', array())); } else { $error_message = array('error' => 'without write permissions'); $statuses['error'] = "Without write permissions. Ignoring 'config', 'schedule' and 'packages'."; } // modules $statuses['modules'] = Model\Module::deploy(Input::get('modules', array())); return $statuses; }
public function setUp() { parent::setUp(); Cache::flush(); }
public function delete_cache() { Cache\Cache::flush(); return array('success' => true); }