Giter Site home page Giter Site logo

Comments (4)

sebastiandedeyne avatar sebastiandedeyne commented on June 9, 2024

Maybe we should register event handlers after the app is booted @freekmurze?

from laravel-event-projector.

freekmurze avatar freekmurze commented on June 9, 2024

I'd accept a PR that moved the registration to the boot method.

from laravel-event-projector.

talvbansal avatar talvbansal commented on June 9, 2024

@sebastiandedeyne I've just tried moving this code

$this->app->singleton(Projectionist::class, function () {
            $config = config('event-projector');

            $projectionist = new Projectionist($config);

            $projectionist
                ->addProjectors($config['projectors'] ?? [])
                ->addReactors($config['reactors'] ?? []);

            return $projectionist;
        });

from the register to the boot method, but theres no change in the functionality. I assume by the time we're at the first line of a test method the app has finished registered and booted even if the test is blank.

I can't think of an obvious way to hook into the app lifecycle to swap Fakes in during tests unless I'm missing something obvious. If there is something please point me in the right direction and ill take another look.

As a work around for now I'm doing the following in my tests:

  • Swapping the implementation for a fake
  • Fetching the Projectionist from the app container
  • Re-adding the reactor and overwriting its key held within the EventHandlerCollection.
        $this->app->singleton(ClaimsManagementNotifier::class, function () use ($fakeRequests) {
            $mock = new MockHandler($fakeRequests);

            $handler = HandlerStack::create($mock);
            $client = new \GuzzleHttp\Client(['handler' => $handler]);

            return new ClaimsManagementNotifier($client);
        });

        /** @var Projectionist $projectionist */
        $projectionist = $this->app->make(Projectionist::class);
        $projectionist->addReactor(AppClaimReactor::class);

from laravel-event-projector.

spatie-bot avatar spatie-bot commented on June 9, 2024

Dear contributor,

because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.

from laravel-event-projector.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.