Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WithFaker references $this->app which might be missing #31071

Closed
czesieq opened this issue Jan 8, 2020 · 3 comments · Fixed by #31083
Closed

WithFaker references $this->app which might be missing #31071

czesieq opened this issue Jan 8, 2020 · 3 comments · Fixed by #31083
Labels

Comments

@czesieq
Copy link

czesieq commented Jan 8, 2020

  • Laravel Version: 6.10.0
  • PHP Version: 7.4.0
  • Database Driver & Version:

Description:

Recent change to src/Illuminate/Foundation/Testing/WithFaker.php added resolving of Faker instance from the container.

    protected function makeFaker($locale = null)
    {
        $locale = $locale ?? config('app.faker_locale', Factory::DEFAULT_LOCALE);

        if ($this->app->bound(Generator::class)) {
            return $this->app->make(Generator::class, [$locale]);
        }

        return Factory::create($locale);
    }

Up to this change, this trait was not depending on any properties of the class that it's used in. This allowed for easy injection of Faker into other elements of code.

Steps To Reproduce:

Add the Illuminate\Foundation\Testing\WithFaker trait to any class that's not a Illuminate\Foundation\Testing\TestCase or object with $app property, it results with an error that the property is undefined.

@driesvints
Copy link
Member

Thanks for reporting. I've sent in a fix for this here: #31083

@crynobone
Copy link
Member

@czesieq may I know how are you actually using WithFaker? Is it still within a Laravel project or outside of Laravel.

@vomitHatSteve
Copy link

My team is having this issue too.
Our use case is that some of our TestCases include a non TestCase object that has the WithFaker trait and generates our test data.
#31083 resolves the issue. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants