tenancy / multi-tenant

Run multiple websites using the same Laravel installation while keeping tenant specific data separated for fully independent multi-domain setups, previously github.com/hyn/multi-tenant
https://tenancy.dev
MIT License
2.56k stars 394 forks source link

Integration with spatie/laravel-event-sourcing and PHPUnit #878

Open fhusquinet opened 4 years ago

fhusquinet commented 4 years ago

Hi!

I have a weird issue when using this package with spatie/laravel-event-sourcing. When I am running tests with PHPUnit everything fails after the first test.

Illuminate\Contracts\Container\BindingResolutionException: Unresolvable dependency resolving [Parameter #0 [ string $storedEventRepository ]] in class Spatie\EventSourcing\EventSubscriber Looks like the singleton binding for the EventSubscriber isn't used/ran after the first test is run. The class doesn't receive the required $storedEventRepository parameter when created, which should contain the value in the config file (config('event-sourcing.stored_event_repository')).

If I hardcode a fallback inside the class the tests run, but this isn't a viable option obviously...

namespace Spatie\EventSourcing;

final class EventSubscriber
{
    /** @var \Spatie\EventSourcing\StoredEventRepository */
    private $repository;

    public function __construct(string $storedEventRepository = '')
    {
        if ( ! $storedEventRepository ) {
            $storedEventRepository = config('event-sourcing.stored_event_repository');
        }
        $this->repository = app($storedEventRepository);
    }

    // Other methods
}

My test isn't related to any functionnality provided by either of the two packages.

I know this is most likely not an issue with this package in particular, nor with spatie/laravel-event-sourcing but maybe a functionality that is used by both packages and therefore creates a conflict?

Hoping you have an idea of where this could come from, because I'm shooting dd() in the dark right now 😅

Happy holidays!

bkintanar commented 4 years ago

@fhusquinet can you share a repo that I can test with?

fhusquinet commented 4 years ago

For sure, here is a basic Laravel installation with all the packages integrated into my project (which isn't too many as of now): https://github.com/fhusquinet/test-multi-tenant-event-sourcing-integration

Running the unit test file should work because it is using PHPUnit's base TestCase file and not the one provided by Laravel. The feature test file will throw that error on the second test and the ones after.