/** * Runs main seeders for all active modules * * @param Seeder $seeder */ public function seed(Seeder $seeder) { $this->withSeeders()->each(function ($module) use($seeder) { /* @var Module $module */ $seeder->call($module->seederClass()); }); }
/** * Execute the console command. * * @return void */ public function fire() { $name = $this->input->getOption('database'); $total = $this->seeder->seed($this->resolver->connection($name), $this->path); if ($total == 0) { $this->info('Nothing to seed.'); } }
/** * Run seeders. * * @return void * * @SuppressWarnings(PHPMD.StaticAccess) */ public function run() { Model::unguard(); try { foreach ($this->seederClasses as $seederClass) { $this->parentSeeder->call($seederClass); } } finally { Model::reguard(); } }
public function testTablesAreSeededFromSeedFiles() { $seeder = new Seeder($files = m::mock('Illuminate\\Filesystem'), $events = m::mock('Illuminate\\Events\\Dispatcher')); $files->shouldReceive('glob')->once()->with('path/*.php')->andReturn(array('path/b.php', 'path/a.php')); $files->shouldReceive('getRequire')->once()->with('path/a.php')->andReturn(array('table' => 'a_table', array('name' => 'Taylor'))); $files->shouldReceive('getRequire')->once()->with('path/b.php')->andReturn(array(array('name' => 'Dayle'))); $connection = m::mock('Illuminate\\Database\\Connection'); $table = m::mock('Illuminate\\Database\\Query\\Builder'); $connection->shouldReceive('table')->with('a_table')->andReturn($table); $table->shouldReceive('delete')->twice(); $table->shouldReceive('insert')->once()->with(array(array('name' => 'Taylor'))); $connection->shouldReceive('table')->with('b')->andReturn($table); $table->shouldReceive('insert')->once()->with(array(array('name' => 'Dayle'))); $events->shouldReceive('fire')->once()->with('illuminate.seeding', array('a_table', 1)); $events->shouldReceive('fire')->once()->with('illuminate.seeding', array('b', 1)); $this->assertEquals(2, $seeder->seed($connection, 'path')); }
protected function runSeed($class) { // Boot Laravel Framework $app = (require_once \Sledgehammer\PATH . 'bootstrap/app.php'); $request = \Illuminate\Http\Request::capture(); $app['request'] = $request; $app->bootstrapWith(['Illuminate\\Foundation\\Bootstrap\\DetectEnvironment', 'Illuminate\\Foundation\\Bootstrap\\LoadConfiguration', 'Illuminate\\Foundation\\Bootstrap\\ConfigureLogging', 'Illuminate\\Foundation\\Bootstrap\\RegisterFacades', 'Illuminate\\Foundation\\Bootstrap\\RegisterProviders', 'Illuminate\\Foundation\\Bootstrap\\BootProviders']); // Run the seeder $command = new DevutilsCommand(); // @todo implement formatter $command->setOutput(new BufferedOutput()); $seeder = new Seeder(); $seeder->setCommand($command); $seeder->setContainer($app); $seeder->call($class); // Return the result return new Alert(nl2br(Html::escape($command->getOutput()->fetch())), ['class' => 'alert alert-info']); }