Beispiel #1
0
 /**
  * Get a factory instance.
  *
  * @param $factoryClass
  * @param $definedName
  *
  * @return ModelFactoryInstance
  */
 public function get($factoryClass = null, $definedName = 'default')
 {
     if (is_string($factoryClass)) {
         $this->factory = Container::getInstance()->make('Illuminate\\Database\\Eloquent\\Factory');
         $instance = $this->factory->of($factoryClass, $definedName);
     } else {
         $instance = null;
     }
     return new ModelFactoryInstance($instance, $this->transformerService);
 }
 /**
  * @before
  */
 public function relocateFactories()
 {
     // change factories path
     // https://laracasts.com/discuss/channels/laravel/l51-how-to-change-factories-path-when-using-model-factories
     $this->app->singleton(Factory::class, function () {
         return Factory::construct(env('FACTORIES_PATH', 'database/factories'));
     });
 }
 /**
  * Register the Eloquent factory instance in the container.
  *
  * @return void
  */
 protected function registerEloquentFactory()
 {
     $this->app->singleton(FakerGenerator::class, function () {
         return FakerFactory::create();
     });
     $this->app->singleton(EloquentFactory::class, function ($app) {
         $faker = $app->make(FakerGenerator::class);
         return EloquentFactory::construct($faker, database_path('factories'));
     });
 }
 /**
  * Register the Eloquent factory instance in the container.
  *
  * @return void
  */
 protected function registerEloquentFactory()
 {
     $this->app->singleton('Faker\\Generator', function () {
         return FakerFactory::create();
     });
     $this->app->singleton('Illuminate\\Database\\Eloquent\\Factory', function ($app) {
         $faker = $app->make('Faker\\Generator');
         return EloquentFactory::construct($faker, database_path('factories'));
     });
 }
Beispiel #5
0
 /**
  * Create a model factory builder for a given class, name, and amount.
  *
  * @param  dynamic  class|class,name|class,amount|class,name,amount
  * @return \Illuminate\Database\Eloquent\FactoryBuilder
  */
 function alpacaFactory()
 {
     $factory = \Illuminate\Database\Eloquent\Factory::construct(app('Faker\\Generator'), base_path('vendor/alcodo/alpaca/src/resources/factories/'));
     $arguments = func_get_args();
     if (isset($arguments[1]) && is_string($arguments[1])) {
         return $factory->of($arguments[0], $arguments[1])->times(isset($arguments[2]) ? $arguments[2] : 1);
     } elseif (isset($arguments[1])) {
         return $factory->of($arguments[0])->times($arguments[1]);
     } else {
         return $factory->of($arguments[0]);
     }
 }
Beispiel #6
0
 /**
  * Creates the application.
  *
  * Needs to be implemented by subclasses.
  *
  * @return \Symfony\Component\HttpKernel\HttpKernelInterface
  */
 public function createApplication()
 {
     $app = (require __DIR__ . '/../vendor/laravel/laravel/bootstrap/app.php');
     $app->make(Kernel::class)->bootstrap();
     // register factory for mocking
     $app->singleton(Factory::class, function () {
         return Factory::construct(new Generator(), __DIR__ . '/../database/factories');
     });
     $app->register(FrameworkServiceProvider::class);
     $db_preset = $app['config']->get('database.connections.mysql');
     $app['config']->set('database.connections.hyn', array_merge($db_preset, ['database' => 'hyn']));
     $app['config']->set('database.default', 'hyn');
     $this->artisan('multi-tenant:setup', ['--tenant' => 'example', '--hostname' => 'system.testing', '--email' => '*****@*****.**', '--webserver' => 'apache']);
     return $app;
 }
Beispiel #7
0
 /**
  * @return $this|\Illuminate\Database\Eloquent\FactoryBuilder
  */
 public function factory()
 {
     $faker = app(FakerGenerator::class);
     $factory = EloquentFactory::construct($faker);
     foreach (app('modules')->enabled() as $module) {
         $factory->load("modules/{$module}/Database/Factories");
     }
     $arguments = func_get_args();
     if (isset($arguments[1]) && is_string($arguments[1])) {
         return $factory->of($arguments[0], $arguments[1])->times(isset($arguments[2]) ? $arguments[2] : 1);
     } elseif (isset($arguments[1])) {
         return $factory->of($arguments[0])->times($arguments[1]);
     } else {
         return $factory->of($arguments[0]);
     }
 }
 /**
  * Register the Eloquent factory instance in the container.
  *
  * @return void
  */
 protected function registerEloquentFactory()
 {
     $this->app->singleton('Illuminate\\Database\\Eloquent\\Factory', function () {
         return EloquentFactory::construct(database_path('factories'));
     });
 }
Beispiel #9
0
 /**
  * Create a new factory instance.
  *
  * @param  \Faker\Generator  $faker
  * @param  \Analogue\ORM\System\Manager  $manager
  *
  * @return void
  */
 public function __construct(Faker $faker, Manager $manager)
 {
     $this->manager = $manager;
     return parent::__construct($faker);
 }