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

[4.x] Add use to closure to pass in environment condition #1434

Merged
merged 2 commits into from
Feb 8, 2024

Conversation

LaurenceRawlings
Copy link
Contributor

@LaurenceRawlings LaurenceRawlings commented Feb 3, 2024

I came across this bug when running the Dusk test suite in a new project with Telescope installed. (Local dev environment running on macOS using sail)

Accessing $this inside the closure results in the following error: Target class [env] does not exist.

This can be fixed by calculating whether the environment is local before the filter colsure and passing the value in.

Full error log:

   FAIL  Tests\Browser\RegistrationTest
  ✓ register valid user                                                                                  2.58s
  ⨯ register password mismatch
  ────────────────────────────────────────────────────────────────────────────────────────────────────────────
   FAILED  Tests\Browser\RegistrationTest > register password mismatch             BindingResolutionException
  Target class [env] does not exist.

  at vendor/laravel/framework/src/Illuminate/Container/Container.php:914
    910▕
    911▕         try {
    912▕             $reflector = new ReflectionClass($concrete);
    913▕         } catch (ReflectionException $e) {
  ➜ 914▕             throw new BindingResolutionException("Target class [$concrete] does not exist.", 0, $e);
    915▕         }
    916▕
    917▕         // If the type is not instantiable, the developer is attempting to resolve
    918▕         // an abstract type such as an Interface or Abstract Class and there is

      +9 vendor frames
  10  app/Providers/TelescopeServiceProvider.php:24
      +20 vendor frames
  31  tests/Browser/RegistrationTest.php:23


  Tests:    1 failed, 1 passed (3 assertions)
  Duration: 2.84s

RegistrationTest.php:

...
    public function setUp(): void
    {
        parent::setUp(); // line 23
        $this->faker = Factory::create();
    }
...

accessing `$this` inside the closure results in the foloowing error: `Target class [env] does not exist.`
@driesvints driesvints changed the title [4.x] Fix: add use to closure to pass in environment condition [4.x] Add use to closure to pass in environment condition Feb 6, 2024
@taylorotwell taylorotwell merged commit 2d453dc into laravel:4.x Feb 8, 2024
10 checks passed
@LaurenceRawlings LaurenceRawlings deleted the patch-1 branch February 9, 2024 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants