Skip to content

#[UsesVendor] attribute fails due to unbooted application, causing container BindingResolutionException #372

@jordyvanderhaegen

Description

@jordyvanderhaegen
  • Testbench Version: 10.8.0
  • Laravel Version: 12.x
  • PHP Version: 8.4
  • Database Driver & Version: MySQL

Description:

I recently attempted to use the #[UsesVendor] attribute in one of our packages, but encountered an issue related to container resolution. It appears that the application isn’t fully booted, and calling $this->refreshApplication() is necessary to make things work. Without it, the following exception is thrown:

Illuminate\Contracts\Container\BindingResolutionException: Target class [config] does not exist.

In our case, we need access to the framework’s default translations, which are stored in a path such as base_path('vendor/laravel/framework/src/Illuminate/Translation/lang'). This is why the vendor directory must be available. Hopefully I’m not misunderstanding how the attribute is intended to be used, as I couldn’t find any documentation on it.

Steps To Reproduce:

  1. Create a test case with a method that uses the #[UsesVendor] attribute.
  2. Execute functionality that interacts with the container.
  3. Observe the resulting BindingResolutionException.
use Orchestra\Testbench\Attributes\UsesVendor;
use Orchestra\Testbench\TestCase;
use PHPUnit\Framework\Attributes\Test;

class MyTestCase extends TestCase
{
    #[Test]
    #[UsesVendor]
    public function it_can_interact_with_the_vendor_folder(): void
    {
        app()->make('config');
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions