Codeception / module-laravel

Modern Laravel module for Codeception
MIT License
5 stars 13 forks source link

Can't use factory states with Codeception #21

Open wesol05 opened 7 years ago

wesol05 commented 7 years ago

What are you trying to achieve?

There is no possibility to use factory states: example with $i->have function. I requesting for such functionality

torkiljohnsen commented 7 years ago

👍

AdrianSkierniewski commented 6 years ago

Hi,

I'm using factories with Codeception quite some time. I'm just using them in my helpers (example here), but I encountered a problem with some memory leaks from Faker library.

If we want to support factories we'd need to re-bind Faker & EloquentFactory in _after hook, to remove all references to faker between tests, so garbage collector can do his job.

Something like that:

            $this->app->singleton(FakerGenerator::class, function ($app) {
                return FakerFactory::create($app['config']->get('app.faker_locale', 'en_US'));
            });

            $this->app->singleton(EloquentFactory::class, function ($app) {
                return EloquentFactory::construct(
                    $app->make(FakerGenerator::class), $this->app->databasePath('factories')
                );
            });

I know that this isn't perfect but Laravel doesn't have build in method to run it on application. They're doing this here